Skip to contentSkip to conversation

sock: fix sendmmsg for partial sendmsg

PATCH In review Soheil Hassas Yeganeh 3 participants 3 messages Nov 4, 2016 – Nov 9, 2016

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

PATCH 1/1 sock: fix sendmmsg for partial sendmsg

From: Soheil Hassas Yeganeh <[email protected]>

Do not send the next message in sendmmsg for partial sendmsg invocations.

sendmmsg assumes that it can continue sending the next message when the return value of the individual sendmsg invocations is positive. It results in corrupting the data for TCP, SCTP, and UNIX streams.

For example, sendmmsg([["abcd"], ["efgh"]]) can result in a stream of "aefgh" if the first sendmsg invocation sends only the first byte while the second sendmsg goes through.

Datagram sockets either send the entire datagram or fail, so this patch affects only sockets of type SOCK_STREAM and SOCK_SEQPACKET.

Fixes 228e548e6020 ("net: Add sendmmsg socket system call")
---
 net/socket.c | 2 ++
 1 file changed, 2 insertions(+)
net/socket.c +2 -0
index 5a9bf5e..272518b 100644
@@ -2038,6 +2038,8 @@ int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
 		if (err)
 			break;
 		++datagrams;
+		if (msg_data_left(&msg_sys))
+			break;
 		cond_resched();
 	}
 
Signature · 1 line
2.8.0.rc3.226.g39d4020
maintainer
#2 lore raw
In reply to Soheil Hassas Yeganeh

From: Soheil Hassas Yeganeh <[email protected]>
Date: Fri, 4 Nov 2016 15:36:49 -0400

Quoted 18 lines

From: Soheil Hassas Yeganeh <[email protected]>

Do not send the next message in sendmmsg for partial sendmsg invocations.

sendmmsg assumes that it can continue sending the next message when the return value of the individual sendmsg invocations is positive. It results in corrupting the data for TCP, SCTP, and UNIX streams.

For example, sendmmsg([["abcd"], ["efgh"]]) can result in a stream of "aefgh" if the first sendmsg invocation sends only the first byte while the second sendmsg goes through.

Datagram sockets either send the entire datagram or fail, so this patch affects only sockets of type SOCK_STREAM and SOCK_SEQPACKET.

Quoted 5 lines
Fixes 228e548e6020 ("net: Add sendmmsg socket system call")

Applied and queued up for -stable, thanks.