Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3634844pxb; Mon, 24 Jan 2022 14:03:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJwnqkgANoWpP9I6s25wPCRkTb1y9l/TexmFOMwemLori8f4kUS2vHlY6mAvAOdf6PovHaLG X-Received: by 2002:a17:902:b218:b0:149:936b:8306 with SMTP id t24-20020a170902b21800b00149936b8306mr16628887plr.134.1643061816846; Mon, 24 Jan 2022 14:03:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061816; cv=none; d=google.com; s=arc-20160816; b=P0Rg7S6gbF2NteVUjEM8QgbnxrhKvTFV116bz42gNodnEDy2g+JiY5/9ZvI2hFgpVS v+md4EU2FylNIvfW4Blrwj8jO3y5D6z9BouqrKJZNSDMoZZuntIAtpJjxiegtdzepNKX /gz2IwEH3JYbHQhXOgNbgTtfZ1siERu+sR7jhUzyTHms7iKXY/wCeZGomaCRWzfeEFsk ZEi2/A8zr/PH9UKVu2DpQSKBFvsumgnof6CdsSGMPdUSCr22l0Ru/rS9+vkcQHjVr4l2 /O+HlgjP669r6OVCVNKNj2eD2rrz4jYKFyXgE0BPB5jt2UIQE59bmN2yYMcZGtOTUJvQ UtBw== 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=BqYOefg4yipA+AmuFTErjcN5TD7CxomItMHmiiC/J5I=; b=lttqh/98P+J9A72sX05Di7wqmm2A9QkZ26OBQaMPK9r/QfhI4c6ChukTXiHcZIzsHx 3mMB9xYhV+30DA65fLj4nIhWxwhO0OaItKWjNkc/4/dIFlfMQi3T+OruPYtcijMqc3Jq OYzpJ42W+4915NT9/mglI2mUCbRwFL6sSRAFb8tr1drCOzHi7Ctpvy+3azIM92XgRHGW P0XSKmS/9aEnXP0WGP6UwIzk30/VTv8njPCVlyuLEQfeAZ7hldv5bdwz33ndMjp6KEsh MyJATrUJMbAgqENRtyYQ7zQ6OZ+EmA6vtt+YTQ5pKTdWgK+7nptJ7fpUGXRGYIxSIaZU Bc/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NSwfMPPM; 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 mz7si447761pjb.168.2022.01.24.14.03.24; Mon, 24 Jan 2022 14:03:36 -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=NSwfMPPM; 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 S1574716AbiAXVuJ (ORCPT + 99 others); Mon, 24 Jan 2022 16:50:09 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:34466 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1448674AbiAXVNf (ORCPT ); Mon, 24 Jan 2022 16:13:35 -0500 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 6B4BEB8122A; Mon, 24 Jan 2022 21:13:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9090DC340E5; Mon, 24 Jan 2022 21:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058813; bh=F2oYiKHVZmI6LKK4R/SUjdr8SVXHmnrD7tlG1U1IfVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NSwfMPPMwYnSOxt0Qv6WsF8bFEgg3SkayQla1lVFSSg33DvoBtLANXmh9Di8iK4xQ KvOIBg9BC1DPVJt4AYx//8ueu/hDN4su7kiVNsObBoWGP3CIaVNmpyTCpHBgl/4XQn 6lIExVLWflMGiGrBghxb1rkV1tADuyjYEjdaOdnI= 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.16 0377/1039] bpf: Fix SO_RCVBUF/SO_SNDBUF handling in _bpf_setsockopt(). Date: Mon, 24 Jan 2022 19:36:06 +0100 Message-Id: <20220124184137.979604025@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 6102f093d59a5..31147a4cfab30 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