From: Debin Zhu <mowenroot@163.com>
To: paul@paul-moore.com
Cc: linux-kernel@vger.kernel.org, Debin Zhu <mowenroot@163.com>,
Bitao Ouyang <1985755126@qq.com>
Subject: [PATCH] netlabel: Fix NULL pointer exception caused by CALIPSO on IPv4 sockets
Date: Wed, 26 Mar 2025 15:43:55 +0800 [thread overview]
Message-ID: <20250326074355.24016-1-mowenroot@163.com> (raw)
Added IPv6 socket checks in `calipso_sock_getattr`, `calipso_sock_setattr`,
and `calipso_sock_delattr` functions.
Return `-EAFNOSUPPORT` error code if the socket is not of the IPv6 type.
This fix prevents the IPv6 datagram code from
incorrectly calling the IPv4 datagram code,
thereby avoiding a NULL pointer exception.
Signed-off-by: Debin Zhu <mowenroot@163.com>
Signed-off-by: Bitao Ouyang <1985755126@qq.com>
---
net/ipv6/calipso.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c
index dbcea9fee..ef55e4176 100644
--- a/net/ipv6/calipso.c
+++ b/net/ipv6/calipso.c
@@ -1072,8 +1072,13 @@ static int calipso_sock_getattr(struct sock *sk,
struct ipv6_opt_hdr *hop;
int opt_len, len, ret_val = -ENOMSG, offset;
unsigned char *opt;
- struct ipv6_txoptions *txopts = txopt_get(inet6_sk(sk));
-
+ struct ipv6_pinfo *pinfo = inet6_sk(sk);
+ struct ipv6_txoptions *txopts;
+ /* Prevent IPv6 datagram code from calling IPv4 datagram code, causing pinet6 to be NULL */
+ if (!pinfo)
+ return -EAFNOSUPPORT;
+
+ txopts = txopt_get(pinfo);
if (!txopts || !txopts->hopopt)
goto done;
@@ -1125,8 +1130,13 @@ static int calipso_sock_setattr(struct sock *sk,
{
int ret_val;
struct ipv6_opt_hdr *old, *new;
- struct ipv6_txoptions *txopts = txopt_get(inet6_sk(sk));
-
+ struct ipv6_pinfo *pinfo = inet6_sk(sk);
+ struct ipv6_txoptions *txopts;
+ /* Prevent IPv6 datagram code from calling IPv4 datagram code, causing pinet6 to be NULL */
+ if (!pinfo)
+ return -EAFNOSUPPORT;
+
+ txopts = txopt_get(pinfo);
old = NULL;
if (txopts)
old = txopts->hopopt;
@@ -1153,8 +1163,13 @@ static int calipso_sock_setattr(struct sock *sk,
static void calipso_sock_delattr(struct sock *sk)
{
struct ipv6_opt_hdr *new_hop;
- struct ipv6_txoptions *txopts = txopt_get(inet6_sk(sk));
-
+ struct ipv6_pinfo *pinfo = inet6_sk(sk);
+ struct ipv6_txoptions *txopts;
+ /* Prevent IPv6 datagram code from calling IPv4 datagram code, causing pinet6 to be NULL */
+ if (!pinfo)
+ return -EAFNOSUPPORT;
+
+ txopts = txopt_get(pinfo);
if (!txopts || !txopts->hopopt)
goto done;
--
2.34.1
next reply other threads:[~2025-03-26 7:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 7:43 Debin Zhu [this message]
2025-03-26 19:38 ` Paul Moore
2025-03-28 12:02 ` Jakub Kicinski
2025-03-28 16:02 ` Paul Moore
2025-03-30 10:40 ` [PATCH v2] " Debin Zhu
2025-04-01 10:17 ` Paolo Abeni
2025-04-01 12:40 ` [PATCH v3] " Debin Zhu
2025-04-01 20:22 ` Paul Moore
2025-04-02 9:36 ` Simon Horman
2025-04-02 18:28 ` Paul Moore
2025-04-02 23:02 ` Jakub Kicinski
2025-03-30 11:09 ` Re: [PATCH] " mowenroot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250326074355.24016-1-mowenroot@163.com \
--to=mowenroot@163.com \
--cc=1985755126@qq.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®