Skip to content
/ linux Public

Commit e23da16

Browse files
edumazetSasha Levin
authored andcommitted
ipv6: fix a race in ip6_sock_set_v6only()
[ Upstream commit 452a3ee ] It is unlikely that this function will be ever called with isk->inet_num being not zero. Perform the check on isk->inet_num inside the locked section for complete safety. Fixes: 9b11574 ("ipv6: add ip6_sock_set_v6only") Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Fernando Fernandez Mancera <fmancera@suse.de> Link: https://patch.msgid.link/20260216102202.3343588-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2a6586e commit e23da16

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

include/net/ipv6.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,12 +1255,15 @@ int ipv6_sock_mc_drop(struct sock *sk, int ifindex,
12551255

12561256
static inline int ip6_sock_set_v6only(struct sock *sk)
12571257
{
1258-
if (inet_sk(sk)->inet_num)
1259-
return -EINVAL;
1258+
int ret = 0;
1259+
12601260
lock_sock(sk);
1261-
sk->sk_ipv6only = true;
1261+
if (inet_sk(sk)->inet_num)
1262+
ret = -EINVAL;
1263+
else
1264+
sk->sk_ipv6only = true;
12621265
release_sock(sk);
1263-
return 0;
1266+
return ret;
12641267
}
12651268

12661269
static inline void ip6_sock_set_recverr(struct sock *sk)

0 commit comments

Comments
 (0)