Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3590072pxb; Mon, 24 Jan 2022 12:59:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJy24qTHRMG1qhrSru1prQRf5S8s4BjVViyV9ymuLwHDCtPzWoyy1iJC+drHg6uKIygo/0Ie X-Received: by 2002:a05:6a00:1687:b0:4c7:5fbb:bb13 with SMTP id k7-20020a056a00168700b004c75fbbbb13mr13432851pfc.36.1643057972448; Mon, 24 Jan 2022 12:59:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057972; cv=none; d=google.com; s=arc-20160816; b=YI6zZ7SPT43uiM9+Bd4XTmH9hjI2SuH5opAQZSMy6mKwsgPNtuNjYqlFV3TNJGVgkT W5QRGCAkUKq4aMQEYBET90a4glqn3dgHZoIRM5uXVTpNCvwxs+C7O1WafaUxPXhKC8DU RfRVG6oWuHsC6uh95gHkn1Xb+VJ5n2YV5tvRDMgNG2MxLtUVfZ0VHbuKq3YmOXGMxwrk JuBeh4EEt1ibvP71Z+6V2OJDoIBMUJ5aEuVKPTVGgQxyXH4pn+5Zkef1x9Ur6sGgl/YW HRKwdUBLTwRdn4pVdywDU2CcgKPlRj0ezbcYGHP2VDPDXz7AyOSeCkc3JTy88aKLxwTk Dapw== 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=5QjA9XQQ8XKgbJ5kfAzncw2AgVQp5NEXOgB2ML3Iy2o=; b=b7Nbmt3RFZrXyf21BvG+fVWak3edatZrFlsC+Z6nDoPgNP2fcrXxMFTiMLHCWITuFr 76NguIFvLGTy7i6bV4JMAQ09xdcOLUgB3krQzfe28gvNhSmkZDIN6nujw+7eSkiHCING XdDA5r3b9V8B2ewVLW9oZO27CkT9VKk2ZVUlNLmYltU+/TXbK8sy6u8OPznkWDIW4sMR 7pYi97UQgHuU7XGS1p4N8IHt+M+rGefFCjba/n/ViOyrIK5cnZbw2FnQtM6oFbUzcii7 NXhfPAGAamTg12+7QQ3dp1ZaCCL0fscWhT6HSrHMT2c4umpJePvekRchPikcpA/FJj7Y c/Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yhSC8EDP; 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 w12si14546868pga.617.2022.01.24.12.59.18; Mon, 24 Jan 2022 12:59:32 -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=yhSC8EDP; 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 S1381850AbiAXUYs (ORCPT + 99 others); Mon, 24 Jan 2022 15:24:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377243AbiAXUFL (ORCPT ); Mon, 24 Jan 2022 15:05:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 692F6C06135F; Mon, 24 Jan 2022 11:31:08 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 08EE660917; Mon, 24 Jan 2022 19:31:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B63CAC340E5; Mon, 24 Jan 2022 19:31:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052667; bh=ZziZE/q/QGnmo1EOHF/uyk7XIzDk+wvPA8vIawa5iH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yhSC8EDPeNaVbSrzCOAErNUIbDpIDkdKKvgefV9Npm3FaM6TtPY3StyCAFQxSmeGN DJMBjhaqa0nmgZg/yfw0dfrTlh4CgolWc9vpPmvuUVnivCqcXwS+OkcThFhZAr/9hw QwE6sjLaFv0G9Fg3y9qpRx71Mpz1871TcqhOR0D8= 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.4 102/320] bpf: Fix SO_RCVBUF/SO_SNDBUF handling in _bpf_setsockopt(). Date: Mon, 24 Jan 2022 19:41:26 +0100 Message-Id: <20220124183957.191563339@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@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 5ebc973ed4c50..b90c0b5a10112 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4248,12 +4248,14 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock, 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