All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init
@ 2024-04-22  9:33 Hyunwoo Kim
  2024-04-22 10:39 ` Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hyunwoo Kim @ 2024-04-22  9:33 UTC (permalink / raw
  To: edumazet, 0x7f454c46; +Cc: v4bel, imv4bel, davem, dsahern, kuba, pabeni, netdev

Since call_rcu, which is called in the hlist_for_each_entry_rcu traversal
of tcp_ao_connect_init, is not part of the RCU read critical section, it
is possible that the RCU grace period will pass during the traversal and
the key will be free.

To prevent this, it should be changed to hlist_for_each_entry_safe.

Fixes: 7c2ffaf21bd6 ("net/tcp: Calculate TCP-AO traffic keys")
Signed-off-by: Hyunwoo Kim <v4bel@theori.io>
---
 net/ipv4/tcp_ao.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c
index 3afeeb68e8a7..781b67a52571 100644
--- a/net/ipv4/tcp_ao.c
+++ b/net/ipv4/tcp_ao.c
@@ -1068,6 +1068,7 @@ void tcp_ao_connect_init(struct sock *sk)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct tcp_ao_info *ao_info;
+	struct hlist_node *next;
 	union tcp_ao_addr *addr;
 	struct tcp_ao_key *key;
 	int family, l3index;
@@ -1090,7 +1091,7 @@ void tcp_ao_connect_init(struct sock *sk)
 	l3index = l3mdev_master_ifindex_by_index(sock_net(sk),
 						 sk->sk_bound_dev_if);
 
-	hlist_for_each_entry_rcu(key, &ao_info->head, node) {
+	hlist_for_each_entry_safe(key, next, &ao_info->head, node) {
 		if (!tcp_ao_key_cmp(key, l3index, addr, key->prefixlen, family, -1, -1))
 			continue;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init
  2024-04-22  9:33 [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init Hyunwoo Kim
@ 2024-04-22 10:39 ` Eric Dumazet
  2024-04-22 17:17 ` Dmitry Safonov
  2024-04-24  2:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2024-04-22 10:39 UTC (permalink / raw
  To: Hyunwoo Kim; +Cc: 0x7f454c46, imv4bel, davem, dsahern, kuba, pabeni, netdev

On Mon, Apr 22, 2024 at 11:33 AM Hyunwoo Kim <v4bel@theori.io> wrote:
>
> Since call_rcu, which is called in the hlist_for_each_entry_rcu traversal
> of tcp_ao_connect_init, is not part of the RCU read critical section, it
> is possible that the RCU grace period will pass during the traversal and
> the key will be free.
>
> To prevent this, it should be changed to hlist_for_each_entry_safe.
>
> Fixes: 7c2ffaf21bd6 ("net/tcp: Calculate TCP-AO traffic keys")
> Signed-off-by: Hyunwoo Kim <v4bel@theori.io>
> ---

Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks !

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init
  2024-04-22  9:33 [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init Hyunwoo Kim
  2024-04-22 10:39 ` Eric Dumazet
@ 2024-04-22 17:17 ` Dmitry Safonov
  2024-04-24  2:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Safonov @ 2024-04-22 17:17 UTC (permalink / raw
  To: Hyunwoo Kim; +Cc: edumazet, imv4bel, davem, dsahern, kuba, pabeni, netdev

On Mon, 22 Apr 2024 at 10:33, Hyunwoo Kim <v4bel@theori.io> wrote:
>
> Since call_rcu, which is called in the hlist_for_each_entry_rcu traversal
> of tcp_ao_connect_init, is not part of the RCU read critical section, it
> is possible that the RCU grace period will pass during the traversal and
> the key will be free.
>
> To prevent this, it should be changed to hlist_for_each_entry_safe.
>
> Fixes: 7c2ffaf21bd6 ("net/tcp: Calculate TCP-AO traffic keys")
> Signed-off-by: Hyunwoo Kim <v4bel@theori.io>

Thank you,

Acked-by: Dmitry Safonov <0x7f454c46@gmail.com>


> ---
>  net/ipv4/tcp_ao.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/ipv4/tcp_ao.c b/net/ipv4/tcp_ao.c
> index 3afeeb68e8a7..781b67a52571 100644
> --- a/net/ipv4/tcp_ao.c
> +++ b/net/ipv4/tcp_ao.c
> @@ -1068,6 +1068,7 @@ void tcp_ao_connect_init(struct sock *sk)
>  {
>         struct tcp_sock *tp = tcp_sk(sk);
>         struct tcp_ao_info *ao_info;
> +       struct hlist_node *next;
>         union tcp_ao_addr *addr;
>         struct tcp_ao_key *key;
>         int family, l3index;
> @@ -1090,7 +1091,7 @@ void tcp_ao_connect_init(struct sock *sk)
>         l3index = l3mdev_master_ifindex_by_index(sock_net(sk),
>                                                  sk->sk_bound_dev_if);
>
> -       hlist_for_each_entry_rcu(key, &ao_info->head, node) {
> +       hlist_for_each_entry_safe(key, next, &ao_info->head, node) {
>                 if (!tcp_ao_key_cmp(key, l3index, addr, key->prefixlen, family, -1, -1))
>                         continue;
>
> --
> 2.34.1
>


--
             Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init
  2024-04-22  9:33 [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init Hyunwoo Kim
  2024-04-22 10:39 ` Eric Dumazet
  2024-04-22 17:17 ` Dmitry Safonov
@ 2024-04-24  2:20 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-24  2:20 UTC (permalink / raw
  To: Hyunwoo Kim
  Cc: edumazet, 0x7f454c46, imv4bel, davem, dsahern, kuba, pabeni,
	netdev

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 22 Apr 2024 05:33:40 -0400 you wrote:
> Since call_rcu, which is called in the hlist_for_each_entry_rcu traversal
> of tcp_ao_connect_init, is not part of the RCU read critical section, it
> is possible that the RCU grace period will pass during the traversal and
> the key will be free.
> 
> To prevent this, it should be changed to hlist_for_each_entry_safe.
> 
> [...]

Here is the summary with links:
  - tcp: Fix Use-After-Free in tcp_ao_connect_init
    https://git.kernel.org/netdev/net/c/80e679b352c3

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-04-24  2:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-22  9:33 [PATCH] tcp: Fix Use-After-Free in tcp_ao_connect_init Hyunwoo Kim
2024-04-22 10:39 ` Eric Dumazet
2024-04-22 17:17 ` Dmitry Safonov
2024-04-24  2:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.