diff mbox series

[RFC,14/14] sendmsg: truncate source buffer if mptcp sndbuf size was set from userspace

Message ID 20191114173225.21199-15-fw@strlen.de
State Superseded, archived
Headers show
Series [RFC] mptcp: wmem accounting and nonblocking io support | expand

Commit Message

Florian Westphal Nov. 14, 2019, 5:32 p.m. UTC
If userspace uses SO_SNDBUF to set a value, then truncate the buffer
according to remaining wmem.

Otherwise, running selftest script with "-m mmap -b 4096" shows very
large sucessful write() calls, as we're only limited by how much data
the underlying tcp flow is willing to accept.

NB: It might make sense to carry SO_SNDBUF down to the subflows,
but thats left out for now.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/mptcp/protocol.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index fbbff667e07a..eb3499ca4f36 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -498,6 +498,15 @@  static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 	pr_debug("conn_list->subflow=%p", ssk);
 
+	if (unlikely(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) {
+		int limit = sk_stream_wspace(sk);
+
+		if (WARN_ON_ONCE(limit <= 0))
+			limit = 1;
+
+		iov_iter_truncate(&msg->msg_iter, limit);
+	}
+
 	lock_sock(ssk);
 	ret = mptcp_sendmsg_frag(sk, ssk, msg, NULL, &timeo, &mss_now,
 				 &size_goal);