All of lore.kernel.org
 help / color / mirror / Atom feed
* [net-next v1] tcp: don't free a FIN sk_buff in tcp_remove_empty_skb()
@ 2021-10-24 23:59 Jon Maxwell
  2021-10-25 16:13 ` Eric Dumazet
  2021-10-26 12:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Jon Maxwell @ 2021-10-24 23:59 UTC (permalink / raw)
  To: edumazet; +Cc: davem, yoshfuji, dsahern, kuba, netdev, linux-kernel, jmaxwell37

v1: Implement a more general statement as recommended by Eric Dumazet. The 
sequence number will be advanced, so this check will fix the FIN case and 
other cases. 

A customer reported sockets stuck in the CLOSING state. A Vmcore revealed that 
the write_queue was not empty as determined by tcp_write_queue_empty() but the 
sk_buff containing the FIN flag had been freed and the socket was zombied in 
that state. Corresponding pcaps show no FIN from the Linux kernel on the wire.

Some instrumentation was added to the kernel and it was found that there is a 
timing window where tcp_sendmsg() can run after tcp_send_fin().

tcp_sendmsg() will hit an error, for example:

1269 ▹       if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))↩
1270 ▹       ▹       goto do_error;↩

tcp_remove_empty_skb() will then free the FIN sk_buff as "skb->len == 0". The
TCP socket is now wedged in the FIN-WAIT-1 state because the FIN is never sent.

If the other side sends a FIN packet the socket will transition to CLOSING and
remain that way until the system is rebooted.

Fix this by checking for the FIN flag in the sk_buff and don't free it if that 
is the case. Testing confirmed that fixed the issue.

Fixes: fdfc5c8594c2 ("tcp: remove empty skb from write queue in error cases")
Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
Reported-by: Monir Zouaoui <Monir.Zouaoui@mail.schwarz>
Reported-by: Simon Stier <simon.stier@mail.schwarz>
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index c2d9830136d2..56ff7c746f88 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -938,7 +938,7 @@ int tcp_send_mss(struct sock *sk, int *size_goal, int flags)
  */
 void tcp_remove_empty_skb(struct sock *sk, struct sk_buff *skb)
 {
-	if (skb && !skb->len) {
+	if (skb && TCP_SKB_CB(skb)->seq == TCP_SKB_CB(skb)->end_seq) {
 		tcp_unlink_write_queue(skb, sk);
 		if (tcp_write_queue_empty(sk))
 			tcp_chrono_stop(sk, TCP_CHRONO_BUSY);
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [net-next v1] tcp: don't free a FIN sk_buff in tcp_remove_empty_skb()
  2021-10-24 23:59 [net-next v1] tcp: don't free a FIN sk_buff in tcp_remove_empty_skb() Jon Maxwell
@ 2021-10-25 16:13 ` Eric Dumazet
  2021-10-26 12:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2021-10-25 16:13 UTC (permalink / raw)
  To: Jon Maxwell
  Cc: David Miller, Hideaki YOSHIFUJI, David Ahern, Jakub Kicinski,
	netdev, LKML

On Sun, Oct 24, 2021 at 4:59 PM Jon Maxwell <jmaxwell37@gmail.com> wrote:
>
> v1: Implement a more general statement as recommended by Eric Dumazet. The
> sequence number will be advanced, so this check will fix the FIN case and
> other cases.
>
> A customer reported sockets stuck in the CLOSING state. A Vmcore revealed that
> the write_queue was not empty as determined by tcp_write_queue_empty() but the
> sk_buff containing the FIN flag had been freed and the socket was zombied in
> that state. Corresponding pcaps show no FIN from the Linux kernel on the wire.
>
> Some instrumentation was added to the kernel and it was found that there is a
> timing window where tcp_sendmsg() can run after tcp_send_fin().
>
> tcp_sendmsg() will hit an error, for example:
>
> 1269 ▹       if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))↩
> 1270 ▹       ▹       goto do_error;↩
>
> tcp_remove_empty_skb() will then free the FIN sk_buff as "skb->len == 0". The
> TCP socket is now wedged in the FIN-WAIT-1 state because the FIN is never sent.
>
> If the other side sends a FIN packet the socket will transition to CLOSING and
> remain that way until the system is rebooted.
>
> Fix this by checking for the FIN flag in the sk_buff and don't free it if that
> is the case. Testing confirmed that fixed the issue.
>
> Fixes: fdfc5c8594c2 ("tcp: remove empty skb from write queue in error cases")
> Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
> Reported-by: Monir Zouaoui <Monir.Zouaoui@mail.schwarz>
> Reported-by: Simon Stier <simon.stier@mail.schwarz>

Thanks for this fix !
Reviewed-by: Eric Dumazet <edumazet@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [net-next v1] tcp: don't free a FIN sk_buff in tcp_remove_empty_skb()
  2021-10-24 23:59 [net-next v1] tcp: don't free a FIN sk_buff in tcp_remove_empty_skb() Jon Maxwell
  2021-10-25 16:13 ` Eric Dumazet
@ 2021-10-26 12:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-10-26 12:20 UTC (permalink / raw)
  To: Jon Maxwell
  Cc: edumazet, davem, yoshfuji, dsahern, kuba, netdev, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Mon, 25 Oct 2021 10:59:03 +1100 you wrote:
> v1: Implement a more general statement as recommended by Eric Dumazet. The
> sequence number will be advanced, so this check will fix the FIN case and
> other cases.
> 
> A customer reported sockets stuck in the CLOSING state. A Vmcore revealed that
> the write_queue was not empty as determined by tcp_write_queue_empty() but the
> sk_buff containing the FIN flag had been freed and the socket was zombied in
> that state. Corresponding pcaps show no FIN from the Linux kernel on the wire.
> 
> [...]

Here is the summary with links:
  - [net-next,v1] tcp: don't free a FIN sk_buff in tcp_remove_empty_skb()
    https://git.kernel.org/netdev/net-next/c/cf12e6f91246

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-26 12:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-24 23:59 [net-next v1] tcp: don't free a FIN sk_buff in tcp_remove_empty_skb() Jon Maxwell
2021-10-25 16:13 ` Eric Dumazet
2021-10-26 12:20 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.