From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx5.sberdevices.ru (mx5.sberdevices.ru [95.181.183.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BE16125A0 for ; Sun, 5 Apr 2026 19:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.181.183.35 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775416485; cv=none; b=fO5Of/sef2K2lJiHCh/CyHMeukmWJ7iN8pWg7DRwVUDM2FiJ8pdvBQge/zMGxO8FZpc1SztwUvIZbM6vn6A+izIHaOUUDZ0tNmPbt7BpfOGQgLP39Zcs2cCMN99zkegZFrd9eJoR8tG4tGRiijheXZhgEV4UAm+4pzCVkJHjxxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775416485; c=relaxed/simple; bh=eiSFwjlxUO+t4zZraR8vU7Ip4xeMeSVGuESmqO4n3pk=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=FY/oy25dSOHvSLgCZcr49DStHHMErP7jY1CaVP0lnnyZeRXM5RjtEEw4xG4EYLdxRuWaLSmPgwc3PR2eRNyutL5gNtbT5BaUVzlwox2m7dwlA36sdQdplNUxu6tNwjwhou+3iFukXNx9qHh6qiRqux2M6mZlWTBD+zBOyF3Eyg8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com; spf=pass smtp.mailfrom=salutedevices.com; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b=SL+2Z2Ub; arc=none smtp.client-ip=95.181.183.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=salutedevices.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=salutedevices.com header.i=@salutedevices.com header.b="SL+2Z2Ub" Received: from p-antispam-ksmg-gc-msk01.sberdevices.ru (localhost [127.0.0.1]) by mx5.sberdevices.ru (Postfix) with ESMTP id 24DEF240003; Sun, 5 Apr 2026 22:14:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx5.sberdevices.ru 24DEF240003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salutedevices.com; s=post; t=1775416474; bh=Ad5uUb0JCpyeuMo5rFDJwdCtmi97e4MfK4yhXpG3fPs=; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type:From; b=SL+2Z2Ub3Brrnh9JXB8lzQqRTnN5OG76FczGJACcBoUcgDK+mojVh+CE9g+uc5Jce EH9Xk8fmud+UcXFlIO3JN5oHuh+pggSvYAOasv3UzHTsqhzjlfhUxY78m2di9uBFgF y+IvmxrioTNbhFCE6J86iGYAraGKFZ+M7Cb61Sb67IJi/Pj+cCs+i8tdEuKA7t1fp8 SVDrhUTYWHdpwchdsKpiYHNLcqYdL1lV5E94FDQ+9ImABleHJXZlShfyv2SRaM3Fyq Smb803l2m4m2hftzGTfeaqENbL62VzZlJAetw/Z7d70iHE/rGeD/QkGxVbj3iPMoOZ fc+uafSYDBxSg== Received: from smtp.sberdevices.ru (p-exch-cas-a-m1.sberdevices.ru [172.24.201.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "sberdevices.ru", Issuer "R12" (not verified)) by mx5.sberdevices.ru (Postfix) with ESMTPS; Sun, 5 Apr 2026 22:14:32 +0300 (MSK) Message-ID: <2521971f-798d-4560-b2d8-bb540591d4b1@salutedevices.com> Date: Sun, 5 Apr 2026 22:14:26 +0300 Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net 2/2] vsock/test: add MSG_PEEK after partial recv test Content-Language: ru To: Luigi Leonardi , Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman CC: , , , References: <20260402-fix_peek-v1-0-ad274fcef77b@redhat.com> <20260402-fix_peek-v1-2-ad274fcef77b@redhat.com> From: Arseniy Krasnov In-Reply-To: <20260402-fix_peek-v1-2-ad274fcef77b@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: p-exch-cas-a-m2.sberdevices.ru (172.24.201.210) To p-exch-cas-a-m1.sberdevices.ru (172.24.201.216) X-KSMG-AntiPhishing: NotDetected X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Envelope-From: avkrasnov@salutedevices.com X-KSMG-AntiSpam-Info: LuaCore: 96 0.3.96 f0df504111d78c4fb91ce829559989c2d1ddd192, {Tracking_from_domain_doesnt_match_to}, 127.0.0.199:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;salutedevices.com:7.1.1;smtp.sberdevices.ru:7.1.1,5.0.1, FromAlignment: s X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiSpam-Lua-Profiles: 201980 [Apr 05 2026] X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Version: 6.1.1.22 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.1.8310, bases: 2026/04/05 16:38:00 #28374316 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-KATA-Status: Not Scanned X-KSMG-LinksScanning: NotDetected X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 5 02.04.2026 11:18, Luigi Leonardi wrote: > Add a test that verifies MSG_PEEK works correctly after a partial > recv(). > > This is to test a bug that was present in the `virtio_transport_stream_do_peek()` > when computing the number of bytes to copy: After a partial read, the > peek function didn't take into consideration the number of bytes that > were already read. So peeking the whole buffer would cause a out-of-bounds read, > that resulted in a -EFAULT. > > This test does exactly this: do a partial recv on a buffer, then try to > peek the whole buffer content. > > Signed-off-by: Luigi Leonardi > --- > tools/testing/vsock/vsock_test.c | 64 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 64 insertions(+) > > diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c > index 5bd20ccd9335caafe68e8b7a5d02a4deb3d2deec..308f9f8f30d22bec5aaa282356e400d8438fe321 100644 > --- a/tools/testing/vsock/vsock_test.c > +++ b/tools/testing/vsock/vsock_test.c > @@ -346,6 +346,65 @@ static void test_stream_msg_peek_server(const struct test_opts *opts) > return test_msg_peek_server(opts, false); > } > > +#define PEEK_AFTER_RECV_LEN 100 Hi, may be we can just reuse MSG_PEEK_BUF_LEN which was already used in MSG_PEEK tests ? Thanks > + > +static void test_stream_peek_after_recv_client(const struct test_opts *opts) > +{ > + unsigned char buf[PEEK_AFTER_RECV_LEN]; > + int fd; > + int i; > + > + fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); > + if (fd < 0) { > + perror("connect"); > + exit(EXIT_FAILURE); > + } > + > + for (i = 0; i < sizeof(buf); i++) > + buf[i] = (unsigned char)i; > + > + control_expectln("SRVREADY"); > + > + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); > + > + close(fd); > +} > + > +static void test_stream_peek_after_recv_server(const struct test_opts *opts) > +{ > + unsigned char buf[PEEK_AFTER_RECV_LEN]; > + int half = PEEK_AFTER_RECV_LEN / 2; > + ssize_t ret; > + int fd; > + > + fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL); > + if (fd < 0) { > + perror("accept"); > + exit(EXIT_FAILURE); > + } > + > + control_writeln("SRVREADY"); > + > + /* Partial recv to advance offset within the skb */ > + recv_buf(fd, buf, half, 0, half); > + > + /* Try to peek more than what remains: should return only 'half' > + * bytes. Note: we can't use recv_buf() because it loops until > + * all requested bytes are returned. > + */ > + ret = recv(fd, buf, sizeof(buf), MSG_PEEK); > + if (ret < 0) { > + perror("recv"); > + exit(EXIT_FAILURE); > + } else if (ret != half) { > + fprintf(stderr, "MSG_PEEK after partial recv returned %d (expected %d)\n", > + ret, half); > + exit(EXIT_FAILURE); > + } > + > + close(fd); > +} > + > #define SOCK_BUF_SIZE (2 * 1024 * 1024) > #define SOCK_BUF_SIZE_SMALL (64 * 1024) > #define MAX_MSG_PAGES 4 > @@ -2520,6 +2579,11 @@ static struct test_case test_cases[] = { > .run_client = test_stream_tx_credit_bounds_client, > .run_server = test_stream_tx_credit_bounds_server, > }, > + { > + .name = "SOCK_STREAM MSG_PEEK after partial recv", > + .run_client = test_stream_peek_after_recv_client, > + .run_server = test_stream_peek_after_recv_server, > + }, > {}, > }; > >