Skip to content

Commit 80e679b

Browse files
V4bel-theorikuba-moo
authored andcommitted
tcp: Fix Use-After-Free in tcp_ao_connect_init
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: 7c2ffaf ("net/tcp: Calculate TCP-AO traffic keys") Signed-off-by: Hyunwoo Kim <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Acked-by: Dmitry Safonov <[email protected]> Link: https://lore.kernel.org/r/ZiYu9NJ/ClR8uSkH@v4bel-B760M-AORUS-ELITE-AX Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4ce62d5 commit 80e679b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/ipv4/tcp_ao.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,7 @@ void tcp_ao_connect_init(struct sock *sk)
10681068
{
10691069
struct tcp_sock *tp = tcp_sk(sk);
10701070
struct tcp_ao_info *ao_info;
1071+
struct hlist_node *next;
10711072
union tcp_ao_addr *addr;
10721073
struct tcp_ao_key *key;
10731074
int family, l3index;
@@ -1090,7 +1091,7 @@ void tcp_ao_connect_init(struct sock *sk)
10901091
l3index = l3mdev_master_ifindex_by_index(sock_net(sk),
10911092
sk->sk_bound_dev_if);
10921093

1093-
hlist_for_each_entry_rcu(key, &ao_info->head, node) {
1094+
hlist_for_each_entry_safe(key, next, &ao_info->head, node) {
10941095
if (!tcp_ao_key_cmp(key, l3index, addr, key->prefixlen, family, -1, -1))
10951096
continue;
10961097

0 commit comments

Comments
 (0)