netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpf: sock recvbuff must be limited by rmem_max in bpf_setsockopt()
@ 2019-01-19  6:20 Yafang Shao
  2019-01-22 17:42 ` Martin Lau
  0 siblings, 1 reply; 4+ messages in thread
From: Yafang Shao @ 2019-01-19  6:20 UTC (permalink / raw)
  To: ast, daniel; +Cc: netdev, shaoyafang, Yafang Shao

When sock recvbuff is set by bpf_setsockopt(), the value must by limited
by rmem_max.
It is the same with sendbuff.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 net/core/filter.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index 447dd1b..f30b58a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4111,10 +4111,12 @@ static unsigned long bpf_xdp_copy(void *dst_buff, const void *src_buff,
 		/* 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;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-23  3:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-19  6:20 [PATCH bpf-next] bpf: sock recvbuff must be limited by rmem_max in bpf_setsockopt() Yafang Shao
2019-01-22 17:42 ` Martin Lau
2019-01-22 17:55   ` Lawrence Brakmo
2019-01-23  1:58   ` 邵亚方(基础平台部)

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).