Skip to content

Commit 3263481

Browse files
edumazetkuba-moo
authored andcommitted
net: fix __sock_gen_cookie()
I was mistaken how atomic64_try_cmpxchg(&sk_cookie, &res, new) is working. I was assuming @res would contain the final sk_cookie value, regardless of the success of our cmpxchg() We could do something like: if (atomic64_try_cmpxchg(&sk_cookie, &res, new) res = new; But we can avoid a conditional and read sk_cookie again. atomic64_cmpxchg(&sk_cookie, res, new); res = atomic64_read(&sk_cookie); Reported-by: coverity-bot <[email protected]> Addresses-Coverity-ID: 1527347 ("Error handling issues") Fixes: 4ebf802 ("net: __sock_gen_cookie() cleanup") Signed-off-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2c45455 commit 3263481

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/core/sock_diag.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ u64 __sock_gen_cookie(struct sock *sk)
3030
if (!res) {
3131
u64 new = gen_cookie_next(&sock_cookie);
3232

33-
atomic64_try_cmpxchg(&sk->sk_cookie, &res, new);
33+
atomic64_cmpxchg(&sk->sk_cookie, res, new);
34+
35+
/* Another thread might have changed sk_cookie before us. */
36+
res = atomic64_read(&sk->sk_cookie);
3437
}
3538
return res;
3639
}

0 commit comments

Comments
 (0)