Skip to contentSkip to conversation

mptcp: sendmsg: reset iter on error

PATCH In review Florian Westphal 3 participants 3 messages Aug 14, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mptcp: sendmsg: reset iter on error

Once we've copied data from the iterator we need to revert in case we end up not sending any data.

This bug doesn't trigger with normal 'poll' based tests, because we only feed a small chunk of data to kernel after poll indicated POLLOUT. With blocking IO and large writes this triggers. Receiver ends up with less data than it should get.

Fixes 72511aab95c94d ("mptcp: avoid blocking in tcp_sendpages")
Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +6 -2
index d5aaa98b9136..2e7e87304930 100644
@@ -725,8 +725,10 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 		if (!psize)
 			return -EINVAL;
 
-		if (!sk_wmem_schedule(sk, psize + dfrag->overhead))
+		if (!sk_wmem_schedule(sk, psize + dfrag->overhead)) {
+			iov_iter_revert(&msg->msg_iter, psize);
 			return -ENOMEM;
+		}
 	} else {
 		offset = dfrag->offset;
 		psize = min_t(size_t, dfrag->data_len, avail_size);
@@ -737,8 +739,10 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
 	 */
 	ret = do_tcp_sendpages(ssk, page, offset, psize,
 			       msg->msg_flags | MSG_SENDPAGE_NOTLAST | MSG_DONTWAIT);
-	if (ret <= 0)
+	if (ret <= 0) {
+		iov_iter_revert(&msg->msg_iter, psize);
 		return ret;
+	}
 
 	frag_truesize += ret;
 	if (!retransmission) {
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Florian Westphal

Once we've copied data from the iterator we need to revert in case we end up not sending any data.

This bug doesn't trigger with normal 'poll' based tests, because we only feed a small chunk of data to kernel after poll indicated POLLOUT. With blocking IO and large writes this triggers. Receiver ends up with less data than it should get.

Quoted 6 lines
Fixes 72511aab95c94d ("mptcp: avoid blocking in tcp_sendpages")
Signed-off-by Florian Westphal <fw(a)strlen.de>

---
net/mptcp/protocol.c | 8 ++++++--

1 file changed, 6 insertions(+), 2 deletions(-)
Reviewed-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

--
Mat Martineau
Intel

maintainer
#2 lore raw
In reply to Florian Westphal

From: Florian Westphal <fw(a)strlen.de>
Date: Fri, 14 Aug 2020 15:56:34 +0200

Quoted 10 lines

Once we've copied data from the iterator we need to revert in case we end up not sending any data.

This bug doesn't trigger with normal 'poll' based tests, because we only feed a small chunk of data to kernel after poll indicated POLLOUT. With blocking IO and large writes this triggers. Receiver ends up with less data than it should get.

Fixes 72511aab95c94d ("mptcp: avoid blocking in tcp_sendpages")
Signed-off-by Florian Westphal <fw(a)strlen.de>

Applied and queued up for -stable, thanks.