Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3081646rwb; Mon, 15 Aug 2022 17:40:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ysJrDVVWu8QFq2fdbrMhYT/XCkjgpdgAHdyWS1XBs/IHmdbPP/11RufHBs5yoBDq0PZuw X-Received: by 2002:a17:902:778b:b0:170:a671:a090 with SMTP id o11-20020a170902778b00b00170a671a090mr19449096pll.56.1660610419427; Mon, 15 Aug 2022 17:40:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610419; cv=none; d=google.com; s=arc-20160816; b=ZT/PSm0lGxbfg5YffRqqq4+uS5B6c34w36qW44p7wx14S7BkB66LKcXIhnyxBjiW8x JCdYNlwhN6Mpo/GijBUt0m7IpxVBdadJVGrESg9A92YvzmPiG+rz+y4ecuYa7K6ONZN3 BB4sjO2cbQ2YITZloxyWHVEnKKwOm5NsmkvCrtI7XfBJ7ZdD3zbdAl7G23rPLPE3xd7z ERlDPI/0oqlHfWQ3pB0Z8BhheSIQuKkiLkb2ka44OaZrPgFadbhm3fDXP37uJPFiNMzz KtOFezsz/027LNyqEi342TGTAbRVLRtvt3BDL+bpsuvX0nXOoStKbJQ4eawEWGuIzjXu 0PTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yjAheDpQRR01CxRaMIi8no5KddSJiO4IU2GdG6uwbBA=; b=Q03hmXH2q7IDBKfV1yg1e8HAu92bEiTMAollm256tmRuNv3W4ypKwHkAx9Zte7O4Cp LOJIu9vD1pCqO0ziHFlrOhqXOT29eguabQJIuhxji/icTRZt5X0vxH01xRHNXJFPNAAt QOOuADAF5MMKD6EsnaB/jGFSX1FufDCFq0sQAJcwJYQPPrcdAcqsSJkl1NOP/eFfMk77 KnprKgmUNQwmMXkOtq989Im8034hx+kL8UgOCBpohnBRzycN03E+S/SHy2ZfCRKteizS RB++7OdZLmR6jT/FXpbfpIiBw9oYHGBo6Jo2ORHar5wIzhljBdy6bEOdRHY7Nzxq41xI IBxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GfRmi+71; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd33-20020a056a0027a100b00534b6674cb4si7064315pfb.301.2022.08.15.17.40.08; Mon, 15 Aug 2022 17:40:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GfRmi+71; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348020AbiHOXbW (ORCPT + 99 others); Mon, 15 Aug 2022 19:31:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245553AbiHOXZt (ORCPT ); Mon, 15 Aug 2022 19:25:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 948D4804A0; Mon, 15 Aug 2022 13:06:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 312B86068D; Mon, 15 Aug 2022 20:06:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3980CC433D6; Mon, 15 Aug 2022 20:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593967; bh=1INTIgiR9Q84Laxhh1/gssi/tKckhPOIoCaK9zQByIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GfRmi+71AzB2ThggYx9IJ+9PNfVVdeNK+gLWP3Z0v6V9nSwsLlt3c/BOEk9MfntVV +S4fP88CH76DS2DEe49xa+RlHAEzb/UtUAjUCwUlI3rD3EhjQWXcflLq+U9wQOOFbF f5zwRoPz/duA9wJtiqluKF7/S2aD842q9YsmR5IY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Shakeel Butt , Soheil Hassas Yeganeh , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.19 0355/1157] net: fix sk_wmem_schedule() and sk_rmem_schedule() errors Date: Mon, 15 Aug 2022 19:55:11 +0200 Message-Id: <20220815180453.914237573@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 7c80b038d23e1f4c7fcc311f43f83b8c60e7fb80 ] If sk->sk_forward_alloc is 150000, and we need to schedule 150001 bytes, we want to allocate 1 byte more (rounded up to one page), instead of 150001 :/ Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Eric Dumazet Reviewed-by: Shakeel Butt Acked-by: Soheil Hassas Yeganeh Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- include/net/sock.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 7a48991cdb19..13944ceea7ed 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1552,19 +1552,23 @@ static inline bool sk_has_account(struct sock *sk) static inline bool sk_wmem_schedule(struct sock *sk, int size) { + int delta; + if (!sk_has_account(sk)) return true; - return size <= sk->sk_forward_alloc || - __sk_mem_schedule(sk, size, SK_MEM_SEND); + delta = size - sk->sk_forward_alloc; + return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_SEND); } static inline bool sk_rmem_schedule(struct sock *sk, struct sk_buff *skb, int size) { + int delta; + if (!sk_has_account(sk)) return true; - return size <= sk->sk_forward_alloc || - __sk_mem_schedule(sk, size, SK_MEM_RECV) || + delta = size - sk->sk_forward_alloc; + return delta <= 0 || __sk_mem_schedule(sk, delta, SK_MEM_RECV) || skb_pfmemalloc(skb); } -- 2.35.1