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 ECB7B3A0E8A for ; Thu, 2 Apr 2026 08:18:10 +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=1775117892; cv=none; b=LOIIi5eS6ObAcsbSaTFzTsmr9zW9PuhkTIgI+63PziwGKNykwLUWORkMqe8k1aWNDPDmdtG8Yeh02bhMwMjtcMYwDRNCzJbkBOtAm039AzScZtx0HEAAaxxgaQhH9jS7f8N5+reuVPPgmFGpK4YYk4it4Mpjn94g5SoRqPAGYX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775117892; c=relaxed/simple; bh=NzXbQuc9ZBk4ObBGtzGs9iu2lFssJbUQBjuKFCUY22k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KsdrFezH9EXCpFeZPb60uUbtstc3oQgmmKc4GilxUMZibZVgE8CX8X7Mk7SgDgEj3oTq/uGna4g665Mv49woXJFNvJC1lRQZfRE1zl6fGixe7FLLy8SlfCNUg1yldcJCYw/XOjFVMprShXd7K27A1uk1TtvIW4SzNlGlMGPjWDI= 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=ee+ShTDa; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=YSvHRj+7; 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="ee+ShTDa"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="YSvHRj+7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775117890; 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=eDGMK8W32A9IJKOzV8D749M8i2eS/0zQjVDT1eVv+dU=; b=ee+ShTDaotIHVZmwm7wMtTBxWonWx9v8oqeRfbeMg5CHi/wOC2VTr7OJ2UeGr8lCU+scN5 a73bM09TEh5cvBzFSnGpnbZKPaKvg+9oNL3FxNQ5PZa9MiXsv3mKXpLDkU97hdKSqUHPJK hrT5fQ75II2RGoHK1wSORNvECzsPtBg= 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-553-oRYLSiehN9WVt7MTtsLG3w-1; Thu, 02 Apr 2026 04:18:08 -0400 X-MC-Unique: oRYLSiehN9WVt7MTtsLG3w-1 X-Mimecast-MFC-AGG-ID: oRYLSiehN9WVt7MTtsLG3w_1775117888 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48886f1bbd4so4264375e9.1 for ; Thu, 02 Apr 2026 01:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775117888; x=1775722688; 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=eDGMK8W32A9IJKOzV8D749M8i2eS/0zQjVDT1eVv+dU=; b=YSvHRj+7wUwvBpJRtb7I57yo1kaQJd4ehuUeQPyZSwB/A17rrDIKVo6nFIcg3e/+Ex WqcM34pPw90YEXzCsNjUVUhbP3FMkautsfEoip7I2zNmRhUUpu4SQO32E8EQ805ehDFh 2qONuEQJ9yjxuYVgE23E2uinMlUDVCKxYs9vhEgD34/KrlCWYcrhQ5BqbdGaGtxzD2Ea la6YX2Kuds5fwkjpqLFFW7YeGBj4I4MFKNMDz6q3baaMIKfTQzkNIv5dXv2QYBKRSsnR 4HgGI5qMCzoTSSmOioD+om3GFMoSlSIGyG6dpG8QBfVIGMlwRcIVISy5ohVs16aV3H+I hNjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775117888; x=1775722688; 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=eDGMK8W32A9IJKOzV8D749M8i2eS/0zQjVDT1eVv+dU=; b=EgDuUzLqmcHLGj0ATBAdQjMg0B+2s4JJLHDzd7GTVhlvkljb/Aows7UJcxkX0ajd+V w35Yod5hD0q/aeIJK/KjER+r80q45BnwYUFgzc4rQuM7HhId2KAcIeXeOWbA26AFeedz pGTsYjGAOlq6ZNzhNrMv/Hx28QG4lS1F+6yQjNJriDfCikQm2E7UeMa1faF9Iqg2uhsa Ewc1aFICvjfjTHx7+oz7DKywWnPiaiUEPI5w8fLMhNxhkVHF3RxjaB1liCuhc1+m2VrB uOJPRP1fIk+dsM2WVlD8WbMbP7NnXUB+FFV2ESNLLEgikC5mtZksrvMn5YmwUPa7LrtV Xszw== X-Forwarded-Encrypted: i=1; AJvYcCVDvCPktn1WlA2u6PmF4uWBdvHz58Jvxdmz5WbwR9Il4m+TehZiCE7CnUvY512BYiZw+jOzDJYih2jUmb8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz250qFTMR67BTR5SYso5DXJXQd8Af5VwfKuJcKpzDGwhMsvOto vwJ14+FXBKbGNrubYU3fX3O3lgEI8+6P1zgNAtGs2o5SJQNdFAwdDkcnHcDI3NGpAbTnBityjbr N1V59Y28TvhbHMv9eNfMHOFxAtJ5zfc5M1pE9zUcwCAhVL54x0R0eYaWxesS9RCuYrw== X-Gm-Gg: ATEYQzzB5/IdV/WcLgfgNfvf44Qlq0EHuXF6B60aMJa3W1EoNxGAleofHWZWoXj6qdV 5gAi5k2ZJDwiTapT3U6b5WoMSmvShLW2f4lv+v43PlFPSQJ2nmEBNBsq8uIE4ixElqzsY9Q1AZe UpVoyLZdd//zxw8AGGL52E9V3IkELpsq6Hypu6fdbisUFhm9BAMV7qCsT54ospaqnDoVkytZP2H 1KGhkr0QcI/RU8G5z4JKEpm7n+a5TjfZ1ELdEKGMIe0PvNQI++KdYGtqDm/AdBVAuWr3ffOi+ow ZraqGzgfxn0Z3hmQV3Fy5O/c5GADjS9RV+ZdGlhqm0MWnegJsvFbNcpdBDJDZQ3ijriISpSvgHO p4rIovUbzWjsyINpOPxWT0IMMJ3HTqQXRbpTDTfzkVou+bOblWOduDgpe8oDz X-Received: by 2002:a05:600c:8184:b0:483:9139:4c1d with SMTP id 5b1f17b1804b1-48883590456mr113866135e9.14.1775117887559; Thu, 02 Apr 2026 01:18:07 -0700 (PDT) X-Received: by 2002:a05:600c:8184:b0:483:9139:4c1d with SMTP id 5b1f17b1804b1-48883590456mr113865405e9.14.1775117887065; Thu, 02 Apr 2026 01:18:07 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4887e735532sm214476005e9.0.2026.04.02.01.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2026 01:18:06 -0700 (PDT) From: Luigi Leonardi Date: Thu, 02 Apr 2026 10:18:02 +0200 Subject: [PATCH net 2/2] 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: <20260402-fix_peek-v1-2-ad274fcef77b@redhat.com> References: <20260402-fix_peek-v1-0-ad274fcef77b@redhat.com> In-Reply-To: <20260402-fix_peek-v1-0-ad274fcef77b@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.2 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 + +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, + }, {}, }; -- 2.53.0