summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorYafang Shao <laoar.shao@gmail.com>2019-01-23 05:37:19 +0100
committerDaniel Borkmann <daniel@iogearbox.net>2019-01-23 12:22:22 +0100
commitc9e4576743eeda8d24dedc164d65b78877f9a98c (patch)
tree0a9240f86f043b2e67ff4cb0641f33ffd9989afc /net
parentbpftool: fix percpu maps updating (diff)
downloadlinux-c9e4576743eeda8d24dedc164d65b78877f9a98c.tar.xz
linux-c9e4576743eeda8d24dedc164d65b78877f9a98c.zip
bpf: sock recvbuff must be limited by rmem_max in bpf_setsockopt()
When sock recvbuff is set by bpf_setsockopt(), the value must by limited by rmem_max. It is the same with sendbuff. Fixes: 8c4b4c7e9ff0 ("bpf: Add setsockopt helper function to bpf") Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Lawrence Brakmo <brakmo@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/filter.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index 7559d6835ecb..7a54dc11ac2d 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4112,10 +4112,12 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,
/* Only some socketops are supported */
switch (optname) {
case SO_RCVBUF:
+ val = min_t(u32, val, sysctl_rmem_max);
sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
sk->sk_rcvbuf = max_t(int, val * 2, SOCK_MIN_RCVBUF);
break;
case SO_SNDBUF:
+ val = min_t(u32, val, sysctl_wmem_max);
sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
sk->sk_sndbuf = max_t(int, val * 2, SOCK_MIN_SNDBUF);
break;