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.133.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 E075E38C403 for ; Tue, 7 Apr 2026 09:14:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775553251; cv=none; b=mWC3bi6HehZqZgWCriqmHGsLmW7DjepqsPEPwxNjSR5H/7QQEXmXTOL0TJSQdg6tR9Wr4FP2opzLJ99sZgLd2zBsd4pOcIjeXJuoEss7+cr5L2gM0Saq+6jADpXC1KgtqhMcJ5gFnabBKDDyHYylzurrnmELIL1XLfPT/0Pec6c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775553251; c=relaxed/simple; bh=ip2wtGgcP4DvQiglidvGP+GnoassWfKVZlJvs+MlGRs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iCCUEB7/z7Sw9ThefHcKp0lJHKj9VrT6VlXF2YdjRMHRLWl4gI91ICl+39C0CEe47PXFhXI5Gj4XbjzjBS7PHkkLFDW8DJZZxOs2DLIrxPIdTseMLHL83XDSCfUcjoYrrvTqdoQMHCoMLocwpD08nqu0m6mjdhkz9NfBq7IwbRQ= 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=Dep0sHNL; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=fY9eb6h4; arc=none smtp.client-ip=170.10.133.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="Dep0sHNL"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="fY9eb6h4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775553248; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5pofFwwc6ykPOXmyxDteFf7vraGRelyLMlwG/8lag20=; b=Dep0sHNLxICjsbyO3iSiNVFL9gPa6ldEDyrdBzY2e8QKq/W4rUXySaGa2EmgVIUzFRohQ9 CvfUAIy3ywiuZIuGDPyrBDiALP5fuj+S6ZDQi8xLISoTGcUonGMzW6iQ3odocss0pESxao KANIfsZXlJNkwoQG4t6KHvlif8EuoMw= 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-540-bJS_cAIYMHq3us5oU53pWA-1; Tue, 07 Apr 2026 05:14:06 -0400 X-MC-Unique: bJS_cAIYMHq3us5oU53pWA-1 X-Mimecast-MFC-AGG-ID: bJS_cAIYMHq3us5oU53pWA_1775553245 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-488b171f1a5so10806715e9.0 for ; Tue, 07 Apr 2026 02:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775553245; x=1776158045; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5pofFwwc6ykPOXmyxDteFf7vraGRelyLMlwG/8lag20=; b=fY9eb6h4x/t00R4VcEiVmNVRumeGOI0SoU4s9EV4GpkrcPUVzgfmnZyvvf/xarfwPY Re3s/68iclRT9X7q+EygTPq0taKK3LJUDGtUCI98kSZJbRkJZyENQ87/PhQs/log/ZMZ x9XPE1PN2bVfPj557zNQfdWUnzaAnEzBjqb/B7ddEofhGA3604TL2yFc84x81bcqmukd G10wtsZPUsS5JV5qKKIqGhF+mtpmJvJs1see7enSLTkt1qouqx+8HFMAf+Axg+osAO9K QnBQz/k7uGVxPvfbzO8UVsO+0AwbItgm2b7qxMIhFYzT8qGoKRBohNXntqsuv0pHBrr9 oWfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775553245; x=1776158045; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=5pofFwwc6ykPOXmyxDteFf7vraGRelyLMlwG/8lag20=; b=orm/aaWe+YdZyZT3NrNbmc3RHXYHQ2Oa7Z2I1J+XyGf4VKnbxHngoq8NPgqoeNgV9v QtHl1VHADaSVEDa/4CwSdsj6TfZRgECBDnhwyNjB8nCadPoh2uX0IwUIt3B/q6am443C ZJeQ42Gh+GKUelL5iB+iY6y42IJF1Ro0G7TMn108wxaX4zv5E5crsnpHrWlxXVedIgw8 y79igSVtsH2ujU1hYWmByB6abSPKzUVVmDtOmZRxAKIBZMO6J/O1WyaGy0EFd/uqjyNV QN4kyUdhh0L/j1CzWym5+j7zYG4duxnYD9O5TsdVFG1yfqHxu89y5MP19+ANVMr8wxMi gzRg== X-Forwarded-Encrypted: i=1; AJvYcCWRlLmapnzC1R1tyl4Cs2vsZ5eWKf9nH7dP7535VI3WT2ltFFSxdxSjcPWxNx4MqHl1VwBT5GevtGrffys=@vger.kernel.org X-Gm-Message-State: AOJu0YzwXMbvw78KYjw7Son17dPeSmiUIDkJw+K7mdnUOR7otrT1jOh1 kd2mcnouC2OpDczVfx6UQyKXOfH/CQ890xgNCoqcdZ5Fk3VbhfshcXCP9MMI9Jf3YYnOMj0sVis bGrAZqq1QuY6r4l/KfILv7mEPC68fnopkyQNvfQsALNWWe2TARKGguf3ahULy6ijc8Q== X-Gm-Gg: AeBDieve7vY1P1VrxK4uO4jvyN5jiBBIzu/I/U0Vm5lnrOtUMW1WitZYPNw137Ew5EW lPgUxG3LZsprvlLDaqvEw0K6WD2qD37jJ4U0VG5NyCLjSmruHiiDxMX/mbbnos1kEmvjglOIpIW Yb59vvl8iS6LRUspV0MVuJE907npU8CmOkk468N+0PkychlH9rihTRRKCTyIByN+otmwWn0R0jQ i+RkgnK63R1f6MlFDBMPr8/f9RxT/QjBvFHZAT8WIcNRB4Om9N/11RDGCaLzIh6WLOC1sqtDT5R lAo8WMI3m9xxwUNQ8uQrHyHMFhR/pG81XETG6DPiFv0ewbOvIvVCwN8DK+pLXI0BwrmUF2Yh0+t QIIslQ5/n/P4SY2jZi4K5UXOIDomrtaj99vfv83I9f0zjqsXuPLXzhKwyhnMm X-Received: by 2002:a05:600c:1d86:b0:485:4388:3492 with SMTP id 5b1f17b1804b1-4889970d844mr239703795e9.11.1775553245348; Tue, 07 Apr 2026 02:14:05 -0700 (PDT) X-Received: by 2002:a05:600c:1d86:b0:485:4388:3492 with SMTP id 5b1f17b1804b1-4889970d844mr239703185e9.11.1775553244880; Tue, 07 Apr 2026 02:14:04 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48895e19c10sm342892015e9.8.2026.04.07.02.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 02:14:04 -0700 (PDT) From: Luigi Leonardi Date: Tue, 07 Apr 2026 11:13:57 +0200 Subject: [PATCH net v2 3/3] vsock/test: add MSG_PEEK after partial recv test 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260407-fix_peek-v2-3-2e2581dc8b7c@redhat.com> References: <20260407-fix_peek-v2-0-2e2581dc8b7c@redhat.com> In-Reply-To: <20260407-fix_peek-v2-0-2e2581dc8b7c@redhat.com> To: 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 , Arseniy Krasnov Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luigi Leonardi X-Mailer: b4 0.14.3 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]; + 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); + + 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