Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2872524rwb; Mon, 15 Aug 2022 13:03:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR6g/IWSx2puPYfjvxT5oFCCZRQ9ItjkAYbB9rP+58S6lfUrAymG8u1d1++jUcm5Y0dqnkt2 X-Received: by 2002:a17:907:8a1a:b0:731:6475:68f7 with SMTP id sc26-20020a1709078a1a00b00731647568f7mr11186784ejc.359.1660593790735; Mon, 15 Aug 2022 13:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660593790; cv=none; d=google.com; s=arc-20160816; b=Yp2b3KcKiM5G7iWiVrPQOukwc83gOPLwnJtrRxJbnvZJ0y0H6tXE4BMEm7ss0VdD7I xoTXe1TsKgKXvrYvTui1hNpD/PrBqduBeXPAJa1Kzky4qAYqzb7+DfrjfftFC9CaReCu xxtA0P/cJfrFgSaQ1RRb2dE+xJxrWHRFTQF0c2LZwp00Lvw2oGFcObpAmay2Cnb4wdrB xhBUS+g2qa+t9Xux8X6OhhtmzUXCVCJE7aJgmfoN9zcRoVNUgAyXEjU3pMjTxjG3Uas+ yf9Eiyg+V1zM2gDbQzT2IhhLUGK3CXs5KrTzFtqMEiw72HKEp3kku2pRmJaJ+SsrcbF+ z0QQ== 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=4iS/h6cp+pd5zFpI2h3rk11aRpCI+vTj0OaA0lgc4+w=; b=cLJIoVB/g32D+6bqNE8vWf+ddOjZuxskwL9kqOwA+3NYHpswHAnrjBtBJOn+dcJEBW 1kQUDYaByuIgC8YVL971w6kIgRyZkXVS+CZzGFLTaDbwth7rGAYr4jvq7kk7svMHZXyc RqdP41K/3iTiDQZlhDMQQ62GYA20GXMR7ZCyjIHWlIy+8mjmkJw98hoya19QZqiPwmVi dC0P20znEtUocB4W0LbMgM1tG5piOW4zb6rQURzvEKQk71Ovxsk/DflMl/wCNiseXAv0 ebrC6WV2mPbiyUWzDl4pGfiodhsKHnuIESJ+vclc4+2TxeHDKMNlC/WYUacGl2lLfyt9 4Hwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gNki2vpb; 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 n12-20020a05640205cc00b00442edebe687si10000723edx.633.2022.08.15.13.02.44; Mon, 15 Aug 2022 13:03:10 -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=gNki2vpb; 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 S244189AbiHOSy5 (ORCPT + 99 others); Mon, 15 Aug 2022 14:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244160AbiHOSql (ORCPT ); Mon, 15 Aug 2022 14:46:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84D9B40BE7; Mon, 15 Aug 2022 11:28:14 -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 89CCC6102C; Mon, 15 Aug 2022 18:28:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8557BC433D7; Mon, 15 Aug 2022 18:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588093; bh=lRviNUT/rYmASAJMOBhWRjeohlYDqq+Z0AqjhvA7WX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gNki2vpb3eJ+aR2D47HYOASttkC8/eaUd4oMCLGQq7eJGsLdxIjhG9Jyias3cbn3D viVg9OG23w6nS/9PupUaALJ2yuuSNb5OZiOT5q7mz3uAaBJdS/akiZD3+VfXyJ+Tbe vkNj7JxZMWm1J8qLDkVhhPdR3lofQ93h5vURECSU= 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.15 261/779] net: fix sk_wmem_schedule() and sk_rmem_schedule() errors Date: Mon, 15 Aug 2022 19:58:25 +0200 Message-Id: <20220815180348.501598319@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 819c53965ef3..e0a88bb0a58c 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1507,19 +1507,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