Skip to content

Commit c9e4576

Browse files
laoarborkmann
authored andcommitted
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: 8c4b4c7 ("bpf: Add setsockopt helper function to bpf") Signed-off-by: Yafang Shao <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Acked-by: Lawrence Brakmo <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent b0ca5ec commit c9e4576

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/core/filter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,10 +4112,12 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,
41124112
/* Only some socketops are supported */
41134113
switch (optname) {
41144114
case SO_RCVBUF:
4115+
val = min_t(u32, val, sysctl_rmem_max);
41154116
sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
41164117
sk->sk_rcvbuf = max_t(int, val * 2, SOCK_MIN_RCVBUF);
41174118
break;
41184119
case SO_SNDBUF:
4120+
val = min_t(u32, val, sysctl_wmem_max);
41194121
sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
41204122
sk->sk_sndbuf = max_t(int, val * 2, SOCK_MIN_SNDBUF);
41214123
break;

0 commit comments

Comments
 (0)