From: "Bartłomiej Dmitruk" <bartlomiej.dmitruk@isec.pl>
To: Stefano Garzarella <sgarzare@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>
Cc: netdev@vger.kernel.org, virtualization@lists.linux.dev,
kvm@vger.kernel.org
Subject: [RFC PATCH] vsock: keep SOCK_SEQPACKET message boundaries on interrupted send
Date: Fri, 18 Sep 2026 00:01:00 +0200 [thread overview]
Message-ID: <20260917220101.55744-1-bartlomiej.dmitruk@isec.pl> (raw)
A credit-limited SOCK_SEQPACKET send transmits fragments as credit becomes
available, and the VIRTIO_VSOCK_SEQ_EOM flag is set only on the fragment
where msg_data_left() reaches 0. If vsock_connectible_sendmsg() exits via
out_err after a partial send -- notably the non-terminal -EINTR path
(signal_pending while blocked for credit), but also sk_err / peer
RCV_SHUTDOWN -- the already-transmitted fragments carry no EOM. The
receiver only advances msg_count / sets msg_ready on an EOM skb, so the
orphaned fragments are silently merged into the *next* message, violating
SOCK_SEQPACKET atomicity.
Reproduced on vsock_loopback: an -EINTR-aborted partial send of 'A's is
merged into the next 'B' message; recv() returns one [A...][B...] message
instead of just the 'B' message (reproducer + before/after below the ---).
Since a SEQPACKET message is bounded by min(peer_buf_alloc, buf_alloc)
(EMSGSIZE gate in virtio_transport_seqpacket_enqueue()), the sender can
wait for room for the whole remaining message before enqueuing, so the
message is committed atomically or not at all; an error while waiting then
leaves nothing on the wire. SOCK_STREAM behaviour is unchanged
(min_space == 1 reproduces the old "wait while space == 0").
RFC: an alternative is to close a partially-sent message with an explicit
EOM on the error path; feedback on the preferred approach welcome.
Signed-off-by: Bartłomiej Dmitruk <bartlomiej.dmitruk@isec.pl>
---
Testing (vsock_loopback, unprivileged, single process; reproducer in
t_vuln004.c): receiver buf_alloc=16384; a 14000-byte message is left unread
to shrink credit to 2384; an 8000-byte message is sent with alarm(1) so the
send is interrupted (-EINTR) after a partial 2384-byte fragment; the 14000
message is drained; then a 1000-byte message is sent.
before: recv() returns one 3384-byte message = 2384 'A' (orphan) + 1000 'B'
after: recv() returns one 1000-byte message = 1000 'B' (boundary intact)
Normal SEQPACKET send/recv (the 14000- and 1000-byte whole messages) works
unchanged.
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2250,9 +2250,16 @@
while (total_written < len) {
ssize_t written;
+ /* For SEQPACKET wait until the whole remaining message fits, so
+ * it is enqueued atomically. A credit-limited partial send that
+ * then errors out (e.g. -EINTR) would otherwise leave EOM-less
+ * fragments that the peer merges into the next message.
+ */
+ s64 min_space = (sk->sk_type == SOCK_SEQPACKET) ?
+ (s64)(len - total_written) : 1;
add_wait_queue(sk_sleep(sk), &wait);
- while (vsock_stream_has_space(vsk) == 0 &&
+ while (vsock_stream_has_space(vsk) < min_space &&
sk->sk_err == 0 &&
!(sk->sk_shutdown & SEND_SHUTDOWN) &&
!(vsk->peer_shutdown & RCV_SHUTDOWN)) {
next reply other threads:[~2026-09-17 22:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 22:01 Bartłomiej Dmitruk [this message]
2026-09-18 22:01 ` [RFC PATCH] vsock: keep SOCK_SEQPACKET message boundaries on interrupted send sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260917220101.55744-1-bartlomiej.dmitruk@isec.pl \
--to=bartlomiej.dmitruk@isec.pl \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=sgarzare@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox