Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3017834rwb; Mon, 15 Aug 2022 16:14:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR5nyVX+XNnZorvUvMRn7Sf0pitbNt4FS8nyCIWockfbq5YH3Rb3uO/pWW/vrHoYWgdFoPFK X-Received: by 2002:a17:907:7d8c:b0:731:65f6:1f28 with SMTP id oz12-20020a1709077d8c00b0073165f61f28mr11182144ejc.91.1660605271257; Mon, 15 Aug 2022 16:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605271; cv=none; d=google.com; s=arc-20160816; b=RljfsBo4fjkQXL5rnYnwKRtt+jrH7lhuPr3ebgmkbU9hDnZkPYmhE23DtLeKqn0A5k kO/64ALJRAQnAZlYglSEqtdCS2phOqTD9jCUM2czpddTbKvX1gWyvFmM9BBVz2RzZbag vMGiIILVfYy0Y5gb23102Z5anjuUE8Z43lRRtMai+PfmmWwdbdR6DDRWx4Q/fZygoAVe JLGgWdF+V/14YDcWvl8j60qN/6fcAMmuiHBoSS+CTVPo23YV7WnxGZSGRoCJce8odf2R VHojfZpTaQqdQSyrPAeWjNsw5ObcquvLrrJn/XWupqj1S079szRFMtpCL3btDy+9aGK8 gDDg== 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=fdp87niroHby9j2KpX2IYvwCwlydp8hdM5WUvEpBpek=; b=Wmx5eZmlwGm3rkHr0/YH2sQ9KX2fvlleichKM8nwT5blREx+FAHRH6gqRAsi9MoBNr 8rjh9Zxo3dbVWKzfibXO8TvO8U6WcitC5Z2ADzv+NJ55RtPqMYkGlYXKmsXmmn2GrcHq dYRhAy81zXjJUzk6ItyFx5NlKXw9Hm6Cy2eFlPUu78DAoORmwk9EmAtNKkswzIpCHein lg0JiQR14fUYGgtE0nBxDOw1rln73MsTLCZWpAas6ar7vTm6/dV1C2AKCgmy428WufN5 fzxxUOx06eyi5x2nCTj7rLM5abyWKvarQmzEuRzlqOza6TL+VTQJVTlRZUbQ/M0MIMdS 13WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jivtlsj+; 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 p37-20020a056402502500b0043c1908e995si8695341eda.113.2022.08.15.16.14.06; Mon, 15 Aug 2022 16:14:31 -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=Jivtlsj+; 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 S242521AbiHOVCZ (ORCPT + 99 others); Mon, 15 Aug 2022 17:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243401AbiHOU7t (ORCPT ); Mon, 15 Aug 2022 16:59:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCDCEC3F42; Mon, 15 Aug 2022 12:12:52 -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 B61796009B; Mon, 15 Aug 2022 19:12:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B304DC433D6; Mon, 15 Aug 2022 19:12:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590771; bh=PbMFbN05pqb5amj2QXqI2mgSacN5B6a8jKrPwhiOtOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jivtlsj+SrmdfvnUh4BXC/8fs5sD0dpTsviPdV+C4ARkt6QiPLq6fnMpqGd61xZ/Z eTdeQUT485B+eXmm4Mlw4jLzrBbU7ORiLc1DH1/2jBFIYOwdTGSTpR6tzdq06oqPgj 3WLTqVWGF63OhlzC4D08aJOaPx+1Jzf8TVPSCYIA= 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.18 0335/1095] net: fix sk_wmem_schedule() and sk_rmem_schedule() errors Date: Mon, 15 Aug 2022 19:55:34 +0200 Message-Id: <20220815180443.661703788@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 9563a093fdfc..aab25d1806a9 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1557,19 +1557,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