diff mbox series

tcp: Reset tcp connections in SYN-SENT state

Message ID 20210405170242.830-1-manojbm@codeaurora.org (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series tcp: Reset tcp connections in SYN-SENT state | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 13 maintainers not CCed: dsahern@kernel.org yhs@fb.com kpsingh@kernel.org yoshfuji@linux-ipv6.org daniel@iogearbox.net andrii@kernel.org bpf@vger.kernel.org kafai@fb.com ast@kernel.org john.fastabend@gmail.com songliubraving@fb.com davem@davemloft.net edumazet@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link

Commit Message

Manoj Basapathi April 5, 2021, 5:02 p.m. UTC
Userspace sends tcp connection (sock) destroy on network switch
i.e switching the default network of the device between multiple
networks(Cellular/Wifi/Ethernet).

Kernel though doesn't send reset for the connections in SYN-SENT state
and these connections continue to remain.
Even as per RFC 793, there is no hard rule to not send RST on ABORT in
this state.

Modify tcp_abort and tcp_disconnect behavior to send RST for connections
in syn-sent state to avoid lingering connections on network switch.

Signed-off-by: Manoj Basapathi <manojbm@codeaurora.org>
Signed-off-by: Sauvik Saha <ssaha@codeaurora.org>
---
 net/ipv4/tcp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Eric Dumazet April 9, 2021, 4:52 p.m. UTC | #1
On 4/5/21 7:02 PM, Manoj Basapathi wrote:
> Userspace sends tcp connection (sock) destroy on network switch
> i.e switching the default network of the device between multiple
> networks(Cellular/Wifi/Ethernet).
> 
> Kernel though doesn't send reset for the connections in SYN-SENT state
> and these connections continue to remain.
> Even as per RFC 793, there is no hard rule to not send RST on ABORT in
> this state.
> 
> Modify tcp_abort and tcp_disconnect behavior to send RST for connections
> in syn-sent state to avoid lingering connections on network switch.
> 
> Signed-off-by: Manoj Basapathi <manojbm@codeaurora.org>
> Signed-off-by: Sauvik Saha <ssaha@codeaurora.org>
> ---
>  net/ipv4/tcp.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index e14fd0c50c10..627a472161fb 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -2888,7 +2888,7 @@ static inline bool tcp_need_reset(int state)
>  {
>  	return (1 << state) &
>  	       (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT | TCPF_FIN_WAIT1 |
> -		TCPF_FIN_WAIT2 | TCPF_SYN_RECV);
> +		TCPF_FIN_WAIT2 | TCPF_SYN_RECV | TCPF_SYN_SENT);
>  }
>  
>  static void tcp_rtx_queue_purge(struct sock *sk)
> @@ -2954,8 +2954,7 @@ int tcp_disconnect(struct sock *sk, int flags)
>  		 */
>  		tcp_send_active_reset(sk, gfp_any());
>  		sk->sk_err = ECONNRESET;
> -	} else if (old_state == TCP_SYN_SENT)
> -		sk->sk_err = ECONNRESET;
> +	}
>  
>  	tcp_clear_xmit_timers(sk);
>  	__skb_queue_purge(&sk->sk_receive_queue);
> 

This is a completely buggy patch.

This has been sent to many people but _not_ to TCP maintainers ????

I will send a revert.
diff mbox series

Patch

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index e14fd0c50c10..627a472161fb 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2888,7 +2888,7 @@  static inline bool tcp_need_reset(int state)
 {
 	return (1 << state) &
 	       (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT | TCPF_FIN_WAIT1 |
-		TCPF_FIN_WAIT2 | TCPF_SYN_RECV);
+		TCPF_FIN_WAIT2 | TCPF_SYN_RECV | TCPF_SYN_SENT);
 }
 
 static void tcp_rtx_queue_purge(struct sock *sk)
@@ -2954,8 +2954,7 @@  int tcp_disconnect(struct sock *sk, int flags)
 		 */
 		tcp_send_active_reset(sk, gfp_any());
 		sk->sk_err = ECONNRESET;
-	} else if (old_state == TCP_SYN_SENT)
-		sk->sk_err = ECONNRESET;
+	}
 
 	tcp_clear_xmit_timers(sk);
 	__skb_queue_purge(&sk->sk_receive_queue);