From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 3C1CB38D681 for ; Wed, 8 Apr 2026 10:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775643495; cv=none; b=SvcFij56Ki3Fm0ceq75f9m9rcWumZu6BqH4j0qwAvjXCpIm+J/Ul6BebC4RU6L3m996RWrfkyBj0cI8MDrd+zM9H8vAPwmQmqk2X/1o6Qb6iwD1zRG2Wx0dOS0LjxISUsVt0dq6o15npjj0lf+9NIDDgNDJu3CU4sodnQPYVXTE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775643495; c=relaxed/simple; bh=6xSUwHLjkibUmQWK2HeD5Idw7sBp7VhBE/kVSPW3QPs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OxCT4beL3/UkjOxaID1yitOaYMmg84y5YwzaswFCQh2RC2Y8tbGSHzlHThX4lHQbQ55MOIfaoeD23vPFyMG+pIxAm4VbItEij0p9bWCfMbqkQRf3NLGmF/kFqtM3eMWU+juKDspuVuVs9Wkk42HYusE/VE0bci3i6bVpcUzogkU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HPw6BsiC; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=rXAAA3bs; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HPw6BsiC"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="rXAAA3bs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775643489; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kfb2nFt+DWPOPwjJLlcYgP+BepPoSw8wC9wFBQagHJw=; b=HPw6BsiCL3JuCDoNCEKyxxqaZUNF6TEOKP0b4TbfVAE3ciHgma2AfRtQSXxCE56UwlyVB3 g7m8nFndJ2B4izprEmLBM+QSA3BK02EKCfaSj8WjeXBnGhBtq4inzWsiUTp/Zv1xx6mtRN 8Qy9UeUWa1i4p+aY2xDELqIeQjRP2Mc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-a2CfBZc5PAufc-U3RCI9aw-1; Wed, 08 Apr 2026 06:18:08 -0400 X-MC-Unique: a2CfBZc5PAufc-U3RCI9aw-1 X-Mimecast-MFC-AGG-ID: a2CfBZc5PAufc-U3RCI9aw_1775643487 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-488af485ce9so23415775e9.0 for ; Wed, 08 Apr 2026 03:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775643487; x=1776248287; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kfb2nFt+DWPOPwjJLlcYgP+BepPoSw8wC9wFBQagHJw=; b=rXAAA3bsiaRt3mvZCAWgOOBUKm+GB8C3WGb+FIQ/AG9adI50ax4uxohvRk/ymY28rW 8uxXjISrwJqJS/gGcgtvwbwQJ1P5mG/nFNc9dcUsUSYNlzMjRVeZtuosR4auS1KgjZiL 9mvZVDyAZ0OHqqElGF5qUo3W++2XU3au95NjPIC4yUW164q8hr5YyJZlPfU4VYI/XMJp bu0fjNJWEQtUdwCaWkvJJKfD2OstpTfj4ZNe0jphzk0kcDmkLPuDQJChQBDKXiGS14Fb 7URjXpV7oBIbZM2vTI2+mUe0mxhvTc1010viXRuB9Qrp4Z3uJSRIgp20eN0PyCVhzCn+ Le+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775643487; x=1776248287; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kfb2nFt+DWPOPwjJLlcYgP+BepPoSw8wC9wFBQagHJw=; b=o9Ozf4QyffQQoefEDcTXumMUIWlVg/o1D6VPs7EbpM0K0piRDEHNIeOaLx88eMyS8C woh2ifbFV6RTSsgjCAxGPHutBVbs+yMumHY3pLgDzdcer9L/QZ7atT7eLnfZrQ4ATwJv YERI99sBHnTf0+JUZYQO53ofpth4SFt70iOD3UsJpoW3Kddd8XCfI+i2MZt362tD7pIq Lnx2AQQoRTQp3rGVbjhX4J7BJLdHQjLiv9uda/DXg2grsuIbR88JLBkUvMdVUHDar8sF RB8AWpAyCj4SIpL1YVEPb8dsSr+8it1XWczzlngH/qlkxHPE99l4r3Qe+hfpFK5H4Gi4 1lOQ== X-Forwarded-Encrypted: i=1; AJvYcCVWdLXqCnLae7jElt3RemPPk+bYWDmE0MCnsxR3ksk1+E7Sx8Zd2IwubLxY6VTYZKtKFs7QxNjUMoq3ls0=@vger.kernel.org X-Gm-Message-State: AOJu0YzO94ITY5ctEyUGQUZCM9em9HF+dPeyI39Un3Aa/1bPYkXPsJS/ 9cjcAA0ORvExMNSNymsFaolesGyYpPLC9C1E0nfk11rCbcEWHnVhAYrtyBxG+se6bc3a7WRQD8F Tuvw5EZm6XsRonGoZUU0Mpe16F5agoZswCJWdnCuoRqAZtNFeEhIdKpQZXFtHB66bqw== X-Gm-Gg: AeBDievgdF610cSv88CLUHJrwFkep1gzNmXIhbL+D1aUXstRJsqN7b94IqpM6klZfl9 Uva4DGkxcRSU+1FbXK+VbnI0FvfO53LL+8cxdBuEJVIXf38shmt9RfNST/5Avg8pMp/mhg7AqL7 On8waPvki2oUeoKrtz3C06ZCpRIoY6TofIoNVEDIle+fNzhooQevCvBouK+rESmIMrnJ4O3zncw 7R+m1K38VT1hfecJH1OlCo6VYiM3MsfMkaTliWA9cYQcrRhf10mcJpoZrqMNOoDVh5bs3E5VIhw Mn/6Rwu2gomBS7eIT4InP5NLs/8OIIvK6bfV8GcuY+8umP/lo6/DZixYmsUjBHQS4u3z1Hzb+rV wTFt8QHOsVit2ukEDOB+KdkLb5HlQLO2WYVsH//7zrEKpruyNyMrDonscJ9C6Pn8RIubJ8Poo8w == X-Received: by 2002:a05:600c:1da1:b0:488:78f2:6b0 with SMTP id 5b1f17b1804b1-488998f488cmr282885495e9.29.1775643487300; Wed, 08 Apr 2026 03:18:07 -0700 (PDT) X-Received: by 2002:a05:600c:1da1:b0:488:78f2:6b0 with SMTP id 5b1f17b1804b1-488998f488cmr282884915e9.29.1775643486788; Wed, 08 Apr 2026 03:18:06 -0700 (PDT) Received: from sgarzare-redhat (host-79-45-205-236.retail.telecomitalia.it. [79.45.205.236]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488c76d9ed4sm34393955e9.2.2026.04.08.03.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 03:18:06 -0700 (PDT) Date: Wed, 8 Apr 2026 12:18:01 +0200 From: Stefano Garzarella To: Luigi Leonardi Cc: Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , Eugenio =?utf-8?B?UMOpcmV6?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Arseniy Krasnov , kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net v2 3/3] vsock/test: add MSG_PEEK after partial recv test Message-ID: References: <20260407-fix_peek-v2-0-2e2581dc8b7c@redhat.com> <20260407-fix_peek-v2-3-2e2581dc8b7c@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20260407-fix_peek-v2-3-2e2581dc8b7c@redhat.com> On Tue, Apr 07, 2026 at 11:13:57AM +0200, 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 | 43 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > >diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c >index bdb0754965df..d38a90a86f34 100644 >--- a/tools/testing/vsock/vsock_test.c >+++ b/tools/testing/vsock/vsock_test.c >@@ -346,6 +346,44 @@ static void test_stream_msg_peek_server(const struct test_opts *opts) > return test_msg_peek_server(opts, false); > } > >+static void test_stream_peek_after_recv_client(const struct test_opts *opts) >+{ >+ unsigned char buf[MSG_PEEK_BUF_LEN]; What about: unsigned char buf[MSG_PEEK_BUF_LEN] = { 0 }; so we can remove the memset() call? >+ int fd; >+ >+ fd = vsock_stream_connect(opts->peer_cid, opts->peer_port); >+ if (fd < 0) { >+ perror("connect"); >+ exit(EXIT_FAILURE); >+ } >+ >+ memset(buf, 0, sizeof(buf)); >+ >+ 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[MSG_PEEK_BUF_LEN]; >+ int fd; >+ >+ fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL); >+ if (fd < 0) { >+ perror("accept"); >+ exit(EXIT_FAILURE); >+ } >+ >+ /* Partial recv to advance offset within the skb */ >+ recv_buf(fd, buf, 1, 0, 1); >+ >+ /* Ask more bytes than available */ >+ recv_buf(fd, buf, sizeof(buf), MSG_PEEK, sizeof(buf) - 1); What about checking also what we read like we do in test_msg_peek_server() ? Not a strong opinion, but if we go in that direction, maybe we can just reuse test_stream_msg_peek_client() also for this test case. Thanks, Stefano >+ >+ close(fd); >+} >+ > #define SOCK_BUF_SIZE (2 * 1024 * 1024) > #define SOCK_BUF_SIZE_SMALL (64 * 1024) > #define MAX_MSG_PAGES 4 >@@ -2509,6 +2547,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, >+ }, > {}, > }; > > >-- >2.53.0 >