]> git.baikalelectronics.ru Git - kernel.git/commitdiff
tcp: fix over estimation in sk_forced_mem_schedule()
authorEric Dumazet <edumazet@google.com>
Tue, 14 Jun 2022 17:17:33 +0000 (10:17 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:18:17 +0000 (11:18 +0200)
commit 3f29cbbc63de31c180110cd0e5ae15f5c28c1f95 upstream.

sk_forced_mem_schedule() has a bug similar to ones fixed
in commit 25f6b78d3bb7 ("net: fix sk_wmem_schedule() and
sk_rmem_schedule() errors")

While this bug has little chance to trigger in old kernels,
we need to fix it before the following patch.

Fixes: e0454b507e43 ("tcp: fix possible deadlock in tcp_send_fin()")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Reviewed-by: Shakeel Butt <shakeelb@google.com>
Reviewed-by: Wei Wang <weiwan@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/tcp_output.c

index fa7fb30e4b5991c2193cd4106ad95ab5524d3685..c37028af0db04876f747f6ad1b9bf8f74d0cb400 100644 (file)
@@ -3143,11 +3143,12 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
  */
 void sk_forced_mem_schedule(struct sock *sk, int size)
 {
-       int amt;
+       int delta, amt;
 
-       if (size <= sk->sk_forward_alloc)
+       delta = size - sk->sk_forward_alloc;
+       if (delta <= 0)
                return;
-       amt = sk_mem_pages(size);
+       amt = sk_mem_pages(delta);
        sk->sk_forward_alloc += amt * SK_MEM_QUANTUM;
        sk_memory_allocated_add(sk, amt);