Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3663288pxb; Mon, 24 Jan 2022 14:47:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxpyz50oUhr9OOyhSuzFw+24MZtI1cF9UwrXInsGrtDrIFbOfYGuN7fWUc5BO+BYYUXEYT X-Received: by 2002:a17:902:7047:b0:14b:650c:4cef with SMTP id h7-20020a170902704700b0014b650c4cefmr3153849plt.16.1643064446566; Mon, 24 Jan 2022 14:47:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643064446; cv=none; d=google.com; s=arc-20160816; b=dO6LyNsmCjLQRsFVJZJj4z73u1NB7Y3SO7/YhlcJAdq9CgfIY4ePmcioCn2xLmz5oh H7SpnoIwSuiFUqeZsxydgvmtzHgF69/aY8mTAV/b4NlmUN/SHzXezuBn5SaBwcpysDdo RizlSpFAjc9OLoNEDOTOi+jfx7oWSzYnb9U21MfmEny+FKLTUSw1YeejCP9/EVGgwu75 imEHlzqek9hfgHUBKw03c9MReHTQjh7pZjdAhv1jftSgm6keo7y/T0b3UpVbHhm2Ru93 ymDE2/f2a8UX3iKLEEpJPy4oW7ZGox2hChQUqY/vYXqGpqdno2sdozHweCZ6bN1+nX/I PHtA== 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=kpPNnxZj2KzHuu26xDodRUzGt/sCD2drAwqmgMhEBss=; b=uHjG4N2s1uvzxePi7LGZyFrM1wenwF4r03lMyzGXj4SLVxCm7xQw8l3uc6rtm3LQbR aGHvKLFUFq8n1Nh0JvCrVCOPlX/LScAhi6GxyZetVkJWcDHfOsP8nMOFknSIoJD0iqt1 AvhecRqNDibpERAtyQaaWGXJurs3RwUixYbLHHpYOSpw9aSligO7MZKsrqJG4tUekk1N 58nrYrcqg3w+nkKTY64+OehNP0iSu9K/NYvzXS+o0Um0XF3cAA9NsdKhdm2zWw/3k19w 7ny/0dGP1P22nF+fZzkw/9Q8bzzvIsos3AgbfGyxeVs6ENWT1RBzPU19s5ho8W9lP1IW UvPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MaSIAOrx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d14si13419889pls.470.2022.01.24.14.47.14; Mon, 24 Jan 2022 14:47:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MaSIAOrx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1837533AbiAXWop (ORCPT + 99 others); Mon, 24 Jan 2022 17:44:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1456645AbiAXVjm (ORCPT ); Mon, 24 Jan 2022 16:39:42 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CAC3C0613BC; Mon, 24 Jan 2022 12:25:33 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id DC9CBB8122F; Mon, 24 Jan 2022 20:25:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC951C340E5; Mon, 24 Jan 2022 20:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055930; bh=vWuaQh9+1cpl/nhG0brUXLPOIwq3Abe+uCQXC24ox1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MaSIAOrxYBQM/oveIFjWJP12YZUtTOwp+uROujzDF3nBQQQzWVZm8wy5Ejf2PmlAM 4w3malcczLWWrpCtjxJKlGK2eNynEG8oqGsf3dbmGqpFSJWDqDQM8mT43lwVSBekC6 fdVN7INMUPuXjZxDzcIZ661lXQCmHxDzmtzSlNaU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.15 313/846] bpf: Fix SO_RCVBUF/SO_SNDBUF handling in _bpf_setsockopt(). Date: Mon, 24 Jan 2022 19:37:10 +0100 Message-Id: <20220124184111.712108953@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima [ Upstream commit 04c350b1ae6bdb12b84009a4d0bf5ab4e621c47b ] The commit 4057765f2dee ("sock: consistent handling of extreme SO_SNDBUF/SO_RCVBUF values") added a change to prevent underflow in setsockopt() around SO_SNDBUF/SO_RCVBUF. This patch adds the same change to _bpf_setsockopt(). Fixes: 4057765f2dee ("sock: consistent handling of extreme SO_SNDBUF/SO_RCVBUF values") Signed-off-by: Kuniyuki Iwashima Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20220104013153.97906-2-kuniyu@amazon.co.jp Signed-off-by: Sasha Levin --- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index 1e6831880d1fd..1e43ab413b62e 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4742,12 +4742,14 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname, switch (optname) { case SO_RCVBUF: val = min_t(u32, val, sysctl_rmem_max); + val = min_t(int, val, INT_MAX / 2); sk->sk_userlocks |= SOCK_RCVBUF_LOCK; WRITE_ONCE(sk->sk_rcvbuf, max_t(int, val * 2, SOCK_MIN_RCVBUF)); break; case SO_SNDBUF: val = min_t(u32, val, sysctl_wmem_max); + val = min_t(int, val, INT_MAX / 2); sk->sk_userlocks |= SOCK_SNDBUF_LOCK; WRITE_ONCE(sk->sk_sndbuf, max_t(int, val * 2, SOCK_MIN_SNDBUF)); -- 2.34.1