bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <kafai@fb.com>,
	Benjamin Herrenschmidt <benh@amazon.com>,
	Kuniyuki Iwashima <kuniyu@amazon.co.jp>,
	Kuniyuki Iwashima <kuni1840@gmail.com>, <bpf@vger.kernel.org>,
	<netdev@vger.kernel.org>, Guillaume Nault <gnault@redhat.com>
Subject: [PATCH bpf-next 1/6] bpf: Fix SO_RCVBUF/SO_SNDBUF handling in _bpf_setsockopt().
Date: Tue, 4 Jan 2022 10:31:48 +0900	[thread overview]
Message-ID: <20220104013153.97906-2-kuniyu@amazon.co.jp> (raw)
In-Reply-To: <20220104013153.97906-1-kuniyu@amazon.co.jp>

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 <kuniyu@amazon.co.jp>
CC: Guillaume Nault <gnault@redhat.com>
---
 net/core/filter.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index 606ab5a98a1a..368fe28c8dc6 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4741,12 +4741,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.30.2


  reply	other threads:[~2022-01-04  1:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-04  1:31 [PATCH bpf-next 0/6] bpf: Batching iter for AF_UNIX sockets Kuniyuki Iwashima
2022-01-04  1:31 ` Kuniyuki Iwashima [this message]
2022-01-04  1:31 ` [PATCH bpf-next 2/6] bpf: Add SO_RCVBUF/SO_SNDBUF in _bpf_getsockopt() Kuniyuki Iwashima
2022-01-04  1:31 ` [PATCH bpf-next 3/6] bpf: af_unix: Use batching algorithm in bpf unix iter Kuniyuki Iwashima
2022-01-05 22:22   ` Alexei Starovoitov
2022-01-05 23:06     ` Kuniyuki Iwashima
2022-01-04  1:31 ` [PATCH bpf-next 4/6] bpf: Support bpf_(get|set)sockopt() " Kuniyuki Iwashima
2022-01-04  1:31 ` [PATCH bpf-next 5/6] selftest/bpf: Test batching and bpf_(get|set)sockopt " Kuniyuki Iwashima
2022-01-04  1:31 ` [PATCH bpf-next 6/6] selftest/bpf: Fix a stale comment Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220104013153.97906-2-kuniyu@amazon.co.jp \
    --to=kuniyu@amazon.co.jp \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=benh@amazon.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=gnault@redhat.com \
    --cc=kafai@fb.com \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).