* [PATCH] net/tcp_sigpool: Use kref_get_unless_zero()
@ 2023-12-22 1:13 Dmitry Safonov
2023-12-22 4:25 ` Bagas Sanjaya
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Dmitry Safonov @ 2023-12-22 1:13 UTC (permalink / raw)
To: Eric Dumazet, David S. Miller, David Ahern, Jakub Kicinski,
Paolo Abeni
Cc: Dmitry Safonov, Dmitry Safonov, netdev, linux-kernel
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: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
net/ipv4/tcp_sigpool.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/tcp_sigpool.c b/net/ipv4/tcp_sigpool.c
index 55b310a722c7..8512cb09ebc0 100644
--- a/net/ipv4/tcp_sigpool.c
+++ b/net/ipv4/tcp_sigpool.c
@@ -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;
---
base-commit: 1a44b0073b9235521280e19d963b6dfef7888f18
change-id: 20231222-tcp-ao-kref_get_unless_zero-fe7105781ba4
Best regards,
--
Dmitry Safonov <dima@arista.com>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] net/tcp_sigpool: Use kref_get_unless_zero()
2023-12-22 1:13 [PATCH] net/tcp_sigpool: Use kref_get_unless_zero() Dmitry Safonov
@ 2023-12-22 4:25 ` Bagas Sanjaya
2023-12-22 17:08 ` Eric Dumazet
2024-01-01 14:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Bagas Sanjaya @ 2023-12-22 4:25 UTC (permalink / raw)
To: Dmitry Safonov, Eric Dumazet, David S. Miller, David Ahern,
Jakub Kicinski, Paolo Abeni
Cc: Dmitry Safonov, Linux Networking, Linux Kernel Mailing List,
YouHong Li
[-- Attachment #1: Type: text/plain, Size: 1459 bytes --]
On Fri, Dec 22, 2023 at 01:13:59AM +0000, Dmitry Safonov wrote:
> 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: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Dmitry Safonov <dima@arista.com>
> ---
> net/ipv4/tcp_sigpool.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/tcp_sigpool.c b/net/ipv4/tcp_sigpool.c
> index 55b310a722c7..8512cb09ebc0 100644
> --- a/net/ipv4/tcp_sigpool.c
> +++ b/net/ipv4/tcp_sigpool.c
> @@ -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;
>
> ---
> base-commit: 1a44b0073b9235521280e19d963b6dfef7888f18
> change-id: 20231222-tcp-ao-kref_get_unless_zero-fe7105781ba4
>
No observable regressions when booting the kernel with this patch applied.
Tested-by: Bagas Sanjaya <bagasdotme@gmail.com>
--
An old man doll... just what I always wanted! - Clara
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net/tcp_sigpool: Use kref_get_unless_zero()
2023-12-22 1:13 [PATCH] net/tcp_sigpool: Use kref_get_unless_zero() Dmitry Safonov
2023-12-22 4:25 ` Bagas Sanjaya
@ 2023-12-22 17:08 ` Eric Dumazet
2024-01-01 14:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2023-12-22 17:08 UTC (permalink / raw)
To: Dmitry Safonov
Cc: David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
Dmitry Safonov, netdev, linux-kernel
On Fri, Dec 22, 2023 at 2:14 AM Dmitry Safonov <dima@arista.com> wrote:
>
> 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: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Dmitry Safonov <dima@arista.com>
Reported-by: syzbot <syzkaller@googlegroups.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] net/tcp_sigpool: Use kref_get_unless_zero()
2023-12-22 1:13 [PATCH] net/tcp_sigpool: Use kref_get_unless_zero() Dmitry Safonov
2023-12-22 4:25 ` Bagas Sanjaya
2023-12-22 17:08 ` Eric Dumazet
@ 2024-01-01 14:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-01-01 14:50 UTC (permalink / raw)
To: Dmitry Safonov
Cc: edumazet, davem, dsahern, kuba, pabeni, 0x7f454c46, netdev,
linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Fri, 22 Dec 2023 01:13:59 +0000 you wrote:
> 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: 8c73b26315aa ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO")
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Dmitry Safonov <dima@arista.com>
>
> [...]
Here is the summary with links:
- net/tcp_sigpool: Use kref_get_unless_zero()
https://git.kernel.org/netdev/net/c/b901a4e27694
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-01 14:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-22 1:13 [PATCH] net/tcp_sigpool: Use kref_get_unless_zero() Dmitry Safonov
2023-12-22 4:25 ` Bagas Sanjaya
2023-12-22 17:08 ` Eric Dumazet
2024-01-01 14:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).