tcp: fix race in tcp_v6_syn_recv_sock()
Subsystems (3)
PATCH 1/1 tcp: fix race in tcp_v6_syn_recv_sock()
tcp_v6_syn_recv_sock() calls ip6_dst_store() before inet_sk(newsk)->pinet6 has been set up.
This means ip6_dst_store() writes over the parent (listener) np->dst_cookie.
This is racy because multiple threads could share the same parent and their final np->dst_cookie could be wrong.
Move ip6_dst_store() call after inet_sk(newsk)->pinet6 has been changed and after the copy of parent ipv6_pinfo.
--- net/ipv6/tcp_ipv6.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/tcp_ipv6.c +2 -1
@@ -1439,7 +1439,6 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff **/ newsk->sk_gso_type =SKB_GSO_TCPV6 ; -ip6_dst_store (newsk, dst,NULL ,NULL );inet6_sk_rx_dst_set (newsk, skb);inet_sk (newsk)->pinet6 =tcp_inet6_sk (newsk);
@@ -1450,6 +1449,8 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *memcpy (newnp, np,sizeof (struct ipv6_pinfo )); +ip6_dst_store (newsk, dst,NULL ,NULL ); + newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr; newnp->saddr = ireq->ir_v6_loc_addr; newsk->sk_v6_rcv_saddr = ireq->ir_v6_loc_addr;
Signature · 1 line
2.45.1.467.gbab1589fc0-goog
+ David Ahern
Quoted 6 lines · Eric Dumazet
tcp_v6_syn_recv_sock()callsip6_dst_store()before inet_sk(newsk)->pinet6 has been set up.This means
ip6_dst_store()writes over the parent (listener)np->dst_cookie.
Quoted 8 lines
This is racy because multiple threads could share the same parent and their final
np->dst_cookiecould be wrong.Move
ip6_dst_store()call after inet_sk(newsk)->pinet6 has been changed and after the copy of parentipv6_pinfo.Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")Signed-off-by Eric Dumazet <[email protected]>
Quoted 29 lines
--- net/ipv6/tcp_ipv6.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/ipv6/tcp_ipv6.c +2
-1@@ -1439,7 +1439,6 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff **/ newsk->sk_gso_type =SKB_GSO_TCPV6 ; -ip6_dst_store (newsk, dst,NULL ,NULL );inet6_sk_rx_dst_set (newsk, skb);inet_sk (newsk)->pinet6 =tcp_inet6_sk (newsk);@@ -1450,6 +1449,8 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *memcpy (newnp, np,sizeof (struct ipv6_pinfo )); +ip6_dst_store (newsk, dst,NULL ,NULL ); + newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr; newnp->saddr = ireq->ir_v6_loc_addr; newsk->sk_v6_rcv_saddr = ireq->ir_v6_loc_addr;Signature · 1 line
2.45.1.467.gbab1589fc0-goog
David Ahern
Reviewed-byQuoted 12 lines · Simon Horman
+ David Ahern
Quoted 9 lines · Eric Dumazet
tcp_v6_syn_recv_sock()callsip6_dst_store()before inet_sk(newsk)->pinet6 has been set up.This means
ip6_dst_store()writes over the parent (listener)np->dst_cookie.This is racy because multiple threads could share the same parent and their final
np->dst_cookiecould be wrong.
Quoted 12 lines
Quoted 5 lines
Move
ip6_dst_store()call after inet_sk(newsk)->pinet6 has been changed and after the copy of parentipv6_pinfo.Fixes e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")Signed-off-by Eric Dumazet <[email protected]>Reviewed-by Simon Horman <[email protected]>Quoted 4 lines
--- net/ipv6/tcp_ipv6.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 10 lines · On Thu, 6 Jun 2024 15:46:51 +0000 you wrote:
tcp_v6_syn_recv_sock()callsip6_dst_store()before inet_sk(newsk)->pinet6 has been set up.This means
ip6_dst_store()writes over the parent (listener)np->dst_cookie.This is racy because multiple threads could share the same parent and their final
np->dst_cookiecould be wrong.[...]
Here is the summary with links:
- [net] tcp: fix race in tcp_v6_syn_recv_sock()
https://git.kernel.org/netdev/net/c/d37fe4255abe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html