Skip to content

Commit 452a3ee

Browse files
edumazetkuba-moo
authored andcommitted
ipv6: fix a race in ip6_sock_set_v6only()
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 <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Fernando Fernandez Mancera <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 77c5e3f commit 452a3ee

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

include/net/ipv6.h

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

12141214
static inline int ip6_sock_set_v6only(struct sock *sk)
12151215
{
1216-
if (inet_sk(sk)->inet_num)
1217-
return -EINVAL;
1216+
int ret = 0;
1217+
12181218
lock_sock(sk);
1219-
sk->sk_ipv6only = true;
1219+
if (inet_sk(sk)->inet_num)
1220+
ret = -EINVAL;
1221+
else
1222+
sk->sk_ipv6only = true;
12201223
release_sock(sk);
1221-
return 0;
1224+
return ret;
12221225
}
12231226

12241227
static inline void ip6_sock_set_recverr(struct sock *sk)

0 commit comments

Comments
 (0)