Skip to content

Commit

Permalink
net/tcp_sigpool: Use kref_get_unless_zero()
Browse files Browse the repository at this point in the history
The freeing and re-allocation of algorithm are protected by cpool_mutex,
so it doesn't fix an actual use-after-free, but avoids a deserved
refcount_warn_saturate() warning.

A trivial fix for the racy behavior.

Fixes: 8c73b26 ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Dmitry Safonov <dima@arista.com>
Tested-by: Bagas Sanjaya <bagasdotme@gmail.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Dmitry Safonov authored and David S. Miller committed Jan 1, 2024
1 parent 8fcb038 commit b901a4e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions net/ipv4/tcp_sigpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ int tcp_sigpool_alloc_ahash(const char *alg, size_t scratch_size)
if (strcmp(cpool[i].alg, alg))
continue;

if (kref_read(&cpool[i].kref) > 0)
kref_get(&cpool[i].kref);
else
/* pairs with tcp_sigpool_release() */
if (!kref_get_unless_zero(&cpool[i].kref))
kref_init(&cpool[i].kref);
ret = i;
goto out;
Expand Down

0 comments on commit b901a4e

Please sign in to comment.