From patchwork Tue Jun 14 17:17:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12881314 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC06CC43334 for ; Tue, 14 Jun 2022 17:17:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244756AbiFNRRx (ORCPT ); Tue, 14 Jun 2022 13:17:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245239AbiFNRRm (ORCPT ); Tue, 14 Jun 2022 13:17:42 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BD582A43C for ; Tue, 14 Jun 2022 10:17:41 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id n18so8289113plg.5 for ; Tue, 14 Jun 2022 10:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PX4xpZVSDZWWYzf0Mgpk64vZeG3iQ4tbiusifSgBIMg=; b=NNOSUsZOXzsJ78Ul0a43M4kgxpNn9bZ7hY7dLpe9lFiWYg31ROa0EsgDNvO646xv83 qGOrUX6xljcSLCvvlBPvpCDDcIHjuzfpqwSS85K8ORYDdq40HCcw48P/SrkY7GI3gJZK lbgnKgeJcZMXRVHmYZclOBhest7/44n0eNiwwAcwjC4PRFL1NvofOnz20UJUWY82hwWk KYYa4k6PBy4TUXVxcXBH1S4yJEYmpqxiPsggxrhybMOkVAHejLafK1FOgvb9ZFUz7D1P Ib+vTa/B3ffnQSZEawZfVFt7cwDAByoUM5EEAirkcPLtyzPWtSonaoLY3+oIeKO4zEWB BMhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PX4xpZVSDZWWYzf0Mgpk64vZeG3iQ4tbiusifSgBIMg=; b=CdltVWq5Y4HZUJgruHlUMQ8Kd00Do+5PdcZiFCrXJnN5/UHOsKR4v/SioDbl0/2S4v bl1mAN+/c2/FMhEUoetzGaIkT3LyOAvekXb366ujJ9YS7E3WFkRTRy2twipvtl+tSksM qFcUlocUA1KmnYWkuWx/xSPGhsLIs9AtVa15WAIKz+7GTB+S0GaE7xemwQHKQwRDgLIq kDUnhjOUybI4bSNwtZIS5TfGK2OS0TCCiqcLr57hCMhfZz0NfKQCBPnGtH4z/brlsRqj kB5/IXJ1ggpg186dDFc01QECN1oecEfHUrKTahTMH/1blxz7HRyichqjmLdSLXQz/x/W Q6yQ== X-Gm-Message-State: AJIora+XTATghPffgW7WZ5/GwaJpklISTnlubTFUZrCSkvU1m1vdsHjb iUQXJq7eRAXTmLio5WRs0xdPLeenTJY= X-Google-Smtp-Source: AGRyM1t29oZfGJi5u+mz1Et2hPVNO+q5ai+RFNDq4HPzUILjKbjLO2kMcHLjtYSUAJBgDgthNMd+QQ== X-Received: by 2002:a17:902:ca0b:b0:167:4c4d:7320 with SMTP id w11-20020a170902ca0b00b001674c4d7320mr5235569pld.113.1655227060666; Tue, 14 Jun 2022 10:17:40 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:2dbb:8c54:2434:5ada]) by smtp.gmail.com with ESMTPSA id d20-20020a170902e15400b00168c523032fsm7435883pla.269.2022.06.14.10.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jun 2022 10:17:40 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev , Soheil Hassas Yeganeh , Wei Wang , Shakeel Butt , Neal Cardwell , Eric Dumazet , Eric Dumazet Subject: [PATCH v2 net-next 1/2] tcp: fix over estimation in sk_forced_mem_schedule() Date: Tue, 14 Jun 2022 10:17:33 -0700 Message-Id: <20220614171734.1103875-2-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220614171734.1103875-1-eric.dumazet@gmail.com> References: <20220614171734.1103875-1-eric.dumazet@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet sk_forced_mem_schedule() has a bug similar to ones fixed in commit 7c80b038d23e ("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: d83769a580f1 ("tcp: fix possible deadlock in tcp_send_fin()") Signed-off-by: Eric Dumazet Acked-by: Soheil Hassas Yeganeh Reviewed-by: Shakeel Butt Reviewed-by: Wei Wang --- net/ipv4/tcp_output.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 8ab98e1aca6797a51eaaf8886680d2001a616948..18c913a2347a984ae8cf2793bb8991e59e5e94ab 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -3362,11 +3362,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 << PAGE_SHIFT; sk_memory_allocated_add(sk, amt);