mirror of
https://github.com/torvalds/linux.git
synced 2024-11-15 00:21:59 +00:00
bpf: Fix SO_RCVBUF/SO_SNDBUF handling in _bpf_setsockopt().
The commit4057765f2d
("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:4057765f2d
("sock: consistent handling of extreme SO_SNDBUF/SO_RCVBUF values") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20220104013153.97906-2-kuniyu@amazon.co.jp
This commit is contained in:
parent
a5bebc4f00
commit
04c350b1ae
@ -4741,12 +4741,14 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
|
|||||||
switch (optname) {
|
switch (optname) {
|
||||||
case SO_RCVBUF:
|
case SO_RCVBUF:
|
||||||
val = min_t(u32, val, sysctl_rmem_max);
|
val = min_t(u32, val, sysctl_rmem_max);
|
||||||
|
val = min_t(int, val, INT_MAX / 2);
|
||||||
sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
|
sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
|
||||||
WRITE_ONCE(sk->sk_rcvbuf,
|
WRITE_ONCE(sk->sk_rcvbuf,
|
||||||
max_t(int, val * 2, SOCK_MIN_RCVBUF));
|
max_t(int, val * 2, SOCK_MIN_RCVBUF));
|
||||||
break;
|
break;
|
||||||
case SO_SNDBUF:
|
case SO_SNDBUF:
|
||||||
val = min_t(u32, val, sysctl_wmem_max);
|
val = min_t(u32, val, sysctl_wmem_max);
|
||||||
|
val = min_t(int, val, INT_MAX / 2);
|
||||||
sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
|
sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
|
||||||
WRITE_ONCE(sk->sk_sndbuf,
|
WRITE_ONCE(sk->sk_sndbuf,
|
||||||
max_t(int, val * 2, SOCK_MIN_SNDBUF));
|
max_t(int, val * 2, SOCK_MIN_SNDBUF));
|
||||||
|
Loading…
Reference in New Issue
Block a user