Skip to content

Commit 3ba9cf6

Browse files
mowenrootgregkh
authored andcommitted
netlabel: Fix NULL pointer exception caused by CALIPSO on IPv4 sockets
[ Upstream commit 078aabd ] When calling netlbl_conn_setattr(), addr->sa_family is used to determine the function behavior. If sk is an IPv4 socket, but the connect function is called with an IPv6 address, the function calipso_sock_setattr() is triggered. Inside this function, the following code is executed: sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL; Since sk is an IPv4 socket, pinet6 is NULL, leading to a null pointer dereference. This patch fixes the issue by checking if inet6_sk(sk) returns a NULL pointer before accessing pinet6. Signed-off-by: Debin Zhu <mowenroot@163.com> Signed-off-by: Bitao Ouyang <1985755126@qq.com> Acked-by: Paul Moore <paul@paul-moore.com> Fixes: ceba183 ("calipso: Set the calipso socket label to match the secattr.") Link: https://patch.msgid.link/20250401124018.4763-1-mowenroot@163.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent feb1fa2 commit 3ba9cf6

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

net/ipv6/calipso.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,13 @@ static int calipso_sock_getattr(struct sock *sk,
10721072
struct ipv6_opt_hdr *hop;
10731073
int opt_len, len, ret_val = -ENOMSG, offset;
10741074
unsigned char *opt;
1075-
struct ipv6_txoptions *txopts = txopt_get(inet6_sk(sk));
1075+
struct ipv6_pinfo *pinfo = inet6_sk(sk);
1076+
struct ipv6_txoptions *txopts;
1077+
1078+
if (!pinfo)
1079+
return -EAFNOSUPPORT;
10761080

1081+
txopts = txopt_get(pinfo);
10771082
if (!txopts || !txopts->hopopt)
10781083
goto done;
10791084

@@ -1125,8 +1130,13 @@ static int calipso_sock_setattr(struct sock *sk,
11251130
{
11261131
int ret_val;
11271132
struct ipv6_opt_hdr *old, *new;
1128-
struct ipv6_txoptions *txopts = txopt_get(inet6_sk(sk));
1133+
struct ipv6_pinfo *pinfo = inet6_sk(sk);
1134+
struct ipv6_txoptions *txopts;
1135+
1136+
if (!pinfo)
1137+
return -EAFNOSUPPORT;
11291138

1139+
txopts = txopt_get(pinfo);
11301140
old = NULL;
11311141
if (txopts)
11321142
old = txopts->hopopt;
@@ -1153,8 +1163,13 @@ static int calipso_sock_setattr(struct sock *sk,
11531163
static void calipso_sock_delattr(struct sock *sk)
11541164
{
11551165
struct ipv6_opt_hdr *new_hop;
1156-
struct ipv6_txoptions *txopts = txopt_get(inet6_sk(sk));
1166+
struct ipv6_pinfo *pinfo = inet6_sk(sk);
1167+
struct ipv6_txoptions *txopts;
1168+
1169+
if (!pinfo)
1170+
return;
11571171

1172+
txopts = txopt_get(pinfo);
11581173
if (!txopts || !txopts->hopopt)
11591174
goto done;
11601175

0 commit comments

Comments
 (0)