Skip to content

Commit d37fe42

Browse files
edumazetdavem330
authored andcommitted
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. Fixes: e994b2f ("tcp: do not lock listener to process SYN packets") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5add2f7 commit d37fe42

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/ipv6/tcp_ipv6.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,6 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *
14391439
*/
14401440

14411441
newsk->sk_gso_type = SKB_GSO_TCPV6;
1442-
ip6_dst_store(newsk, dst, NULL, NULL);
14431442
inet6_sk_rx_dst_set(newsk, skb);
14441443

14451444
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 *
14501449

14511450
memcpy(newnp, np, sizeof(struct ipv6_pinfo));
14521451

1452+
ip6_dst_store(newsk, dst, NULL, NULL);
1453+
14531454
newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr;
14541455
newnp->saddr = ireq->ir_v6_loc_addr;
14551456
newsk->sk_v6_rcv_saddr = ireq->ir_v6_loc_addr;

0 commit comments

Comments
 (0)