Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d22e1537 authored by Josh Hunt's avatar Josh Hunt Committed by David S. Miller
Browse files

tcp: fix tcp fin memory accounting



tcp_send_fin() does not account for the memory it allocates properly, so
sk_forward_alloc can be negative in cases where we've sent a FIN:

ss example output (ss -amn | grep -B1 f4294):
tcp    FIN-WAIT-1 0      1            192.168.0.1:45520         192.0.2.1:8080
	skmem:(r0,rb87380,t0,tb87380,f4294966016,w1280,o0,bl0)
Acked-by: default avatarEric Dumazet <edumazet@google.com>

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 73ba57bf
Loading
Loading
Loading
Loading
+1 −5
Original line number Original line Diff line number Diff line
@@ -2773,15 +2773,11 @@ void tcp_send_fin(struct sock *sk)
	} else {
	} else {
		/* Socket is locked, keep trying until memory is available. */
		/* Socket is locked, keep trying until memory is available. */
		for (;;) {
		for (;;) {
			skb = alloc_skb_fclone(MAX_TCP_HEADER,
			skb = sk_stream_alloc_skb(sk, 0, sk->sk_allocation);
					       sk->sk_allocation);
			if (skb)
			if (skb)
				break;
				break;
			yield();
			yield();
		}
		}

		/* Reserve space for headers and prepare control bits. */
		skb_reserve(skb, MAX_TCP_HEADER);
		/* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */
		/* FIN eats a sequence byte, write_seq advanced by tcp_queue_skb(). */
		tcp_init_nondata_skb(skb, tp->write_seq,
		tcp_init_nondata_skb(skb, tp->write_seq,
				     TCPHDR_ACK | TCPHDR_FIN);
				     TCPHDR_ACK | TCPHDR_FIN);