Skip to content

Commit 8ba6092

Browse files
edumazetdavem330
authored andcommitted
tcp: fastopen: tcp_connect() must refresh the route
With new TCP_FASTOPEN_CONNECT socket option, there is a possibility to call tcp_connect() while socket sk_dst_cache is either NULL or invalid. +0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 4 +0 fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK) = 0 +0 setsockopt(4, SOL_TCP, TCP_FASTOPEN_CONNECT, [1], 4) = 0 +0 connect(4, ..., ...) = 0 << sk->sk_dst_cache becomes obsolete, or even set to NULL >> +1 sendto(4, ..., 1000, MSG_FASTOPEN, ..., ...) = 1000 We need to refresh the route otherwise bad things can happen, especially when syzkaller is running on the host :/ Fixes: 19f6d3f ("net/tcp-fastopen: Add new API support") Reported-by: Dmitry Vyukov <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Cc: Wei Wang <[email protected]> Cc: Yuchung Cheng <[email protected]> Acked-by: Wei Wang <[email protected]> Acked-by: Yuchung Cheng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ec0acb0 commit 8ba6092

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/ipv4/tcp_output.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,6 +3436,10 @@ int tcp_connect(struct sock *sk)
34363436
int err;
34373437

34383438
tcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB);
3439+
3440+
if (inet_csk(sk)->icsk_af_ops->rebuild_header(sk))
3441+
return -EHOSTUNREACH; /* Routing failure or similar. */
3442+
34393443
tcp_connect_init(sk);
34403444

34413445
if (unlikely(tp->repair)) {

0 commit comments

Comments
 (0)