From nobody Sun Jun 14 09:58:36 2026 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 8C2EC3D890F for ; Wed, 15 Apr 2026 15:09:46 +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=1776265787; cv=none; b=TAapJcbh76MEd/ZAPrVHesYcrupp2hqGOOKVk0ymiL8E3R9V9AEHr899nsE30dlWxx6LAd71BXxtioi4vu5A5rtI5X6HlZJRFteds8XgLCtewiXdWKmMwFgQligkePEmQnQ0WIKXGZcU0fmnKvKgljEi0kYyh4whoOvElTQzDrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776265787; c=relaxed/simple; bh=8KxSLwY587LR57aGsCLpqgDw1kJidOt4vFYe6TGecyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m0Ix/E1CrGOefZ9Wv9h7J009OHeDgw9+DW9Sx2sDueqSIcopfJ/tzG6EUqxH9NEzJe+SaydxjLa8TdbFyBcZQmpuVApWKGY0x8i7jFuELM6Hvy+y9uBPpzF63tgsljybo67csxdtcdy1fp7/hjJV1Hkj/yJL9ydYQiZFgLkBVss= 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=B3i75YCJ; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=KuT5V+ZD; 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="B3i75YCJ"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="KuT5V+ZD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776265785; 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=GGbKEVk7Q+3WFRVihAcafbqDB4/UKYyFXHFteVNPtTg=; b=B3i75YCJCypjiEog0x0BthTUZZv2+T93KXOogawOe20DG5nZ4GavjoEJjWtFlVWNDr9Pim +35e9tz4saHZkc8b/fIzeRlaONKRLEO7DW2DZKtzp2Mda9edhNwB1uX8F816mdarD4ylOw JpID/ECRkjeuJJqaAjfTWRxvAutaduY= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-153-Oy_CTsgmMmyYihzNiRvxeA-1; Wed, 15 Apr 2026 11:09:43 -0400 X-MC-Unique: Oy_CTsgmMmyYihzNiRvxeA-1 X-Mimecast-MFC-AGG-ID: Oy_CTsgmMmyYihzNiRvxeA_1776265782 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-43d7b7bacddso2281331f8f.0 for ; Wed, 15 Apr 2026 08:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776265782; x=1776870582; 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=GGbKEVk7Q+3WFRVihAcafbqDB4/UKYyFXHFteVNPtTg=; b=KuT5V+ZDxxwtul6OrsVNM8Sat89SsEhCBRx0bHYl/l5KUpaBA85cIRvWe1WrY24gjB ex453lm0Z0SJq+kD5nvTjO/giQ6Lj+QyV1tsL2syuK2TfEQRqrjARtYQJNYocaoq3ncq YD6aTD7DWoj9f0vgCFxodyhbONRIt5a78QOu1QDj6k0bxDJ7xxuF+K8NVueubrPf5Q// d77bZUus/+i+/EoYOjjWsCHP8rmnbYcpMXvx8HX6aeybJZGDafr2tPAHV7/f0B23B6R3 KKgDG4BNpzg9Vi2PsZvnuCaJYP8rDlQ3Ofv3eeQoe/6xLXSm11Fcz5XHwppwPMxrDf2p ZRxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776265782; x=1776870582; 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=GGbKEVk7Q+3WFRVihAcafbqDB4/UKYyFXHFteVNPtTg=; b=NilISk3mo8ks6WKLOr23jAdDjqrkXQURc2NZmh7C+wm6c83fpklFkbvcX0UMPr4GBQ WXsQOf8gId22DSg+GUkPgy4HkqObBcDk2wbqZMQHVBdy3Rb7kfC/PQtH7A3sGnjiaAJ/ W7icUxsCSm/KXj6pGEWcVO6UJX/NxpMiaJYagND2HGph1txlLj7daak1+WS24aja5+la LlvCpCmETAS3Cgj2pM7hWk9JODllkv1C3RZtKHK0fB7Xop6fvG6tqe9gK/fsVoNM28u4 jH6F/aav6L2dAMasBK/0Ml8CFi5vkPtf3BqwKuJiAD2hiu5Y6t+dkqgtnF1LGUqTspCi ci2Q== X-Forwarded-Encrypted: i=1; AFNElJ+dKILp5sV8c3rpXBmD90mn6ASgMIBrWFeku9B81vHE9L2SGwAWc4cBXSJnmSxjmsCIonGBfurbJ9G+n+M=@vger.kernel.org X-Gm-Message-State: AOJu0YxSlwlylm8vzypuL1LmYpwF+6PO/6uT29IQ7oMbsJn89bf44VCT Y898X1CJUk+O/GImkR5ZV7Y2TsW2nqSUaicHwhxkV44FHB/YMWcWvIRQUlzfH4ddLNpxLw2UAtw cwQRfZVTmTbTChUIu0zvFbH+iFYpRz8MP9cpG6R1S/S025rpbLKATulJgypMRr6XooA== X-Gm-Gg: AeBDievgNGeq0dFZ0LlmL0YJOLuSglvkgf6X24jXQUYsY7goNcGf6ezqUwUsQYOaDQF zT/ZaBDt14JrIk4W6xhi1Q5qYGkDQhjGr8/j/h22Cbucm1PswQSu9znl8EhzV7TxQNRNC0eS3o1 rX36GE7tWT7Y2zYwqMq/2KAxAha/+nku36ZtRmFm7vzy97pHkX+JYWi7E4yoG5nLc1YvriJDKKK PcVeWPOCPCqw+v/+/6Y2vUv1V4l5TVhtvJTPqeng/ctgYvgyRtJd69Yk9F4xfzKfW0DcBX9rN+v OgAYlYVQdiX9WQYTOGgGXET3feMiTA3gLT3shsBXGDw382nmj62RBEhgt/XNu1kIbGbr+6jyPQ3 pMeIEBJFJckZjF9V8mIE7MxxY8m1M0TrAssBp/hMFuOedLJN7w/V0BIU+QrQV X-Received: by 2002:a5d:64c4:0:b0:43d:30ea:9383 with SMTP id ffacd0b85a97d-43d64259b42mr30842194f8f.8.1776265781763; Wed, 15 Apr 2026 08:09:41 -0700 (PDT) X-Received: by 2002:a5d:64c4:0:b0:43d:30ea:9383 with SMTP id ffacd0b85a97d-43d64259b42mr30842115f8f.8.1776265781194; Wed, 15 Apr 2026 08:09:41 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43ead35bf1esm5907557f8f.16.2026.04.15.08.09.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 08:09:40 -0700 (PDT) From: Luigi Leonardi Date: Wed, 15 Apr 2026 17:09:28 +0200 Subject: [PATCH net v4 1/3] vsock/virtio: fix MSG_PEEK ignoring skb offset when calculating bytes to copy 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: quoted-printable Message-Id: <20260415-fix_peek-v4-1-8207e872759e@redhat.com> References: <20260415-fix_peek-v4-0-8207e872759e@redhat.com> In-Reply-To: <20260415-fix_peek-v4-0-8207e872759e@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 `virtio_transport_stream_do_peek()` does not account for the skb offset when computing the number of bytes to copy. This means that, after a partial recv() that advances the offset, a peek requesting more bytes than are available in the sk_buff causes `skb_copy_datagram_iter()` to go past the valid payload, resulting in a -EFAULT. The dequeue path already handles this correctly. Apply the same logic to the peek path. Fixes: 0df7cd3c13e4 ("vsock/virtio/vhost: read data from non-linear skb") Reviewed-by: Stefano Garzarella Acked-by: Arseniy Krasnov Signed-off-by: Luigi Leonardi --- net/vmw_vsock/virtio_transport_common.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index a152a9e208d0..b5015ab2ee1e 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -545,9 +545,8 @@ virtio_transport_stream_do_peek(struct vsock_sock *vsk, skb_queue_walk(&vvs->rx_queue, skb) { size_t bytes; =20 - bytes =3D len - total; - if (bytes > skb->len) - bytes =3D skb->len; + bytes =3D min_t(size_t, len - total, + skb->len - VIRTIO_VSOCK_SKB_CB(skb)->offset); =20 spin_unlock_bh(&vvs->rx_lock); =20 --=20 2.53.0 From nobody Sun Jun 14 09:58:36 2026 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 B3E7A3D9021 for ; Wed, 15 Apr 2026 15:09:46 +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=1776265788; cv=none; b=iUijmNfDOyT+vTvs5iQTMQAt9rjolFI+pmzalgBewmjOX/asWLgGgZVgEn4lgdY1tgQmx+8wYqi+IpEYihHYbd/R/hmSzAbmM6Tc68Em1kHS6sUEkdp6H3RSN5e3PoM3ty60/D1jytJ0/4miwdpZFB9M5hqGFtyRdBL5m3Tyi2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776265788; c=relaxed/simple; bh=/iCPhgiq7mE33glA4s7a0f83jNJCKI2MOCQ/JRlKmDg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lk0iWiIl8n4V2dLOdRUOXcG002HjIiMoFnzmOEWSbTcLwcrKilAb8NxU2GjVgp0DQm/YAiUiLtG7fiemIs4ErSzTauruUP9IG9Bv24OlaD5wbUN1SF38Af/fga0Fblj3IdeWOY+VbGNxFV2q8uPrjVe566loMLhjxc7jYhicKT4= 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=aVNMVtsd; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=YJUuVLMS; 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="aVNMVtsd"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="YJUuVLMS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776265786; 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=FA7f9IhhC8d9N5AuSbx4NBgDg1Ch+I8A/gLFTYNnbg8=; b=aVNMVtsdJkVtdBymnUCADBGIJCYp0p+Rw5bvrnwZWLdF5/ozoGynwR0ycC4XXzEL8lNDaX 2Haa8KeoX0U5hZFjuDQeEuoIFU+LmF4HSX53WoDLAqWZfXP5MyJqdCZZ/lWSg9A+YJf3Ss bG4pZvOICfk0ALOuMVhIe5jB3awUaiM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-265-6-gCBPw4P5SnPQSCb8kJbA-1; Wed, 15 Apr 2026 11:09:44 -0400 X-MC-Unique: 6-gCBPw4P5SnPQSCb8kJbA-1 X-Mimecast-MFC-AGG-ID: 6-gCBPw4P5SnPQSCb8kJbA_1776265783 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-488cc31ea57so44385525e9.3 for ; Wed, 15 Apr 2026 08:09:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776265783; x=1776870583; 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=FA7f9IhhC8d9N5AuSbx4NBgDg1Ch+I8A/gLFTYNnbg8=; b=YJUuVLMSO5A/q/PIDYvowfJC25Z6ilDU/3Pposk4drOAKbIGD9mMybwBSqmXg6fEq6 gEgaBAlVTJRbrmtEnZ4F1jWZWbi/2LwY215fDZtCr69u5fQclQNKwor/OCztn6Ldsz5I zNgJi6Eh89Pw/KkDoCQZO1NsEch1avLqrqmIJ/zfc3dhGtY54GZC+uQ9N6tXsXJCe4o7 SenYJdFwwLZLlpOyhgzct59DhPT6eWh8VkIJsYIxfSa7tWK3ZgkE/v7deUL0VdTNvnxc /nNh5JmJaEXFSPlseajrYljqM9ij4hr/BbTY9kpwEiQedNyQ/M4q4RvgkcOLPVKZooQe YVBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776265783; x=1776870583; 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=FA7f9IhhC8d9N5AuSbx4NBgDg1Ch+I8A/gLFTYNnbg8=; b=eZqmv4FOnJ+30Aa9W11R6pO3I5jFSUuD6Ga8y3BZmGFJcJBNcTnH9Pbd47YfDFPibM 5vtSW6ofODHFeT8fz2ljRkaaxpNdpuR9xyr3edtE4AaLVqwLPtkb7x0OYdbMZVYvt4LS C9elO/hAlXvG3Uz+ObJbHmHVEH0YF32NDjOHCF/0hTPGoppqeS5k0Ph9eawL3lcG6MTH gxOijlnfnpuufugVEmPTpsVnBTw0SfCtgumSwT2g//KlMzh9kJ3eK4ucB1ICdEYajY5H 5LCTsyt2jgdureiMa0+f2UJ2FAKLP3DggOS26i7MAzq702ZiAdTuaHXEfyp342Gno7SS MRkQ== X-Forwarded-Encrypted: i=1; AFNElJ8jdpdcoMV5VnRSL3tZH5qpgA+/LHNPQIv8zRinrwfwkcdjXObaOZVAdoyQmOEmzuQShPUTKhHT3FUgUmk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4ZnhyzkL2NgrUR/Y7+MOb3FY/nsUd64QMONZZfFafRpVyoL+z wE3+wmUZBVVkj4lAH9khSyfFMMUm3J6hhOGe6v7YrNE3sUw9avtGetOEKRIxELcaUxfBobPYOih PgaCVhVJhc3o4X1iqbbjHbzqak5Q44MZPwlaWXdn5mf+sp5eezCiPcRlZox7rB/Hhww== X-Gm-Gg: AeBDievPlKE43KGC3yUNr8imfhVwIV0hKGMQgKqkzH0sbPS4TOSqzCgz0p0rBeKIinn HqLRoiZgxOueaICqAB5Y7JlIxfS8C7hLxKaVsoh0t5Kj8zFWRyDPOEkf3rLqViBtjo8gDHWDqAT laCgu8FLDqf8bDpXnsjz44e9GI4sETgL76Lb5TfO6O7bu4E5fQAnsMtj98xDeGPl8btmfMC8B1N 2zieGTDV+nX7c4ZbVHZohPIlYw6HxyHfzwPVEMKHNcIWCUAQl5kHjjpEm+t7657bqrSijuMyTZG RD6HUf/UrWpQV4J8ym0iCZrVRksLcBlfKtLgvfKfePW0Nn7bYBN9dCfEMOXdjM5MJgkdcCZS2KX M9wLyP2NFoOnAkCn7iQitfq5UfmrXEvfdjT+1A2U+I1bK/CNii5AkaypLKf96 X-Received: by 2002:a05:600c:a413:b0:488:a639:b787 with SMTP id 5b1f17b1804b1-488d67f39admr230392125e9.11.1776265783253; Wed, 15 Apr 2026 08:09:43 -0700 (PDT) X-Received: by 2002:a05:600c:a413:b0:488:a639:b787 with SMTP id 5b1f17b1804b1-488d67f39admr230391525e9.11.1776265782768; Wed, 15 Apr 2026 08:09:42 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43ead35bf1esm5907557f8f.16.2026.04.15.08.09.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 08:09:42 -0700 (PDT) From: Luigi Leonardi Date: Wed, 15 Apr 2026 17:09:29 +0200 Subject: [PATCH net v4 2/3] vsock/test: fix MSG_PEEK handling in recv_buf() 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: quoted-printable Message-Id: <20260415-fix_peek-v4-2-8207e872759e@redhat.com> References: <20260415-fix_peek-v4-0-8207e872759e@redhat.com> In-Reply-To: <20260415-fix_peek-v4-0-8207e872759e@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 `recv_buf` does not handle the MSG_PEEK flag correctly: it keeps calling `recv` until all requested bytes are available or an error occurs. The problem is how it calculates the number of bytes read: MSG_PEEK doesn't consume any bytes and will re-read the same bytes from the buffer head, so summing the return value every time is wrong. Moreover, MSG_PEEK doesn't consume the bytes in the buffer, so if more bytes are requested than are available, the loop will never terminate, because `recv` will never return EOF. For this reason, we need to compare the number of bytes read with the number of bytes expected. Add a check: if the MSG_PEEK flag is present, update the byte counter and break out of the loop only after at least the expected number of bytes have been received; otherwise, retry after a short delay to avoid consuming too many CPU cycles. This allows us to simplify the `test_stream_credit_update_test` by reusing `recv_buf`, like some other tests already do. Suggested-by: Stefano Garzarella Signed-off-by: Luigi Leonardi Reviewed-by: Stefano Garzarella --- tools/testing/vsock/util.c | 15 +++++++++++++++ tools/testing/vsock/vsock_test.c | 13 +------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 1fe1338c79cd..fe316b02a590 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -381,7 +381,13 @@ void send_buf(int fd, const void *buf, size_t len, int= flags, } } =20 +#define RECV_PEEK_RETRY_USEC (10 * 1000) + /* Receive bytes in a buffer and check the return value. + * + * When MSG_PEEK is set, recv() is retried until it returns at least + * expected_ret bytes. The function returns on error, EOF, or timeout + * as usual. * * expected_ret: * <0 Negative errno (for testing errors) @@ -403,6 +409,15 @@ void recv_buf(int fd, void *buf, size_t len, int flags= , ssize_t expected_ret) if (ret <=3D 0) break; =20 + if (flags & MSG_PEEK) { + if (ret >=3D expected_ret) { + nread =3D ret; + break; + } + timeout_usleep(RECV_PEEK_RETRY_USEC); + continue; + } + nread +=3D ret; } while (nread < len); timeout_end(); diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index 5bd20ccd9335..bdb0754965df 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1500,18 +1500,7 @@ static void test_stream_credit_update_test(const str= uct test_opts *opts, } =20 /* Wait until there will be 128KB of data in rx queue. */ - while (1) { - ssize_t res; - - res =3D recv(fd, buf, buf_size, MSG_PEEK); - if (res =3D=3D buf_size) - break; - - if (res <=3D 0) { - fprintf(stderr, "unexpected 'recv()' return: %zi\n", res); - exit(EXIT_FAILURE); - } - } + recv_buf(fd, buf, buf_size, MSG_PEEK, buf_size); =20 /* There is 128KB of data in the socket's rx queue, dequeue first * 64KB, credit update is sent if 'low_rx_bytes_test' =3D=3D true. --=20 2.53.0 From nobody Sun Jun 14 09:58:36 2026 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 55F513DBD4D for ; Wed, 15 Apr 2026 15:09:49 +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=1776265790; cv=none; b=PjEPSvQ8Qcr614qRlt/1VuSk5qp065Dgm47STJ68TIM8AJLlcYfvlPJfuG86ihWZoq23RWJiTzaf6P7I187FiXr+XR0jj319Ck7N5pZgfU1YZzlsuYd1CLqE6X4YejFiI1UrnQkT3EZQvOn0X6AQdjUIhabkVnH2vHC3+hYNdsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776265790; c=relaxed/simple; bh=LicrGY4V+zsv5KZ7wlpKw3NN40iL41s8FOtyi0yIhNg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RBWzCvdrozjaNxYaaRoVWMq6SyLPgdk+5gJyYuwYxi5dZ1hJtfn5R5PXJQwgQgnA96isJqns8C4bLQTBRiuGnE7UZEe+VyB2podiYQFsaeACHBTiyGCpL0IxkFTB6jxtBmOzfcZmxBCjgDbVB1OM7KyO/nUypnO3bWNPAKcNQBM= 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=dyXobKPU; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=o2A2d6F+; 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="dyXobKPU"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="o2A2d6F+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776265788; 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=BKxh1xV1gWd+m52UTAHmFCb6N+6HL0A4jah73SCv02s=; b=dyXobKPU3JTxpqO7pJAwggxD2XE52pYdqlpL/Owv/dSgfrUpZpMcKytlchoLq90+KcJ0KX Yxtk5Aei5dcueg9SU16tOJwg1YBEpODykIrWMyzaQEK8Zq3fUuak6ztfO9Ic4YUmjPiuGC iAoVgZjvv6D0kualSkVjqlM2qg9NKME= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-222-TNj6q6w4Oh-EgsV2f6qKVg-1; Wed, 15 Apr 2026 11:09:47 -0400 X-MC-Unique: TNj6q6w4Oh-EgsV2f6qKVg-1 X-Mimecast-MFC-AGG-ID: TNj6q6w4Oh-EgsV2f6qKVg_1776265786 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-43d1fec59c9so3664540f8f.0 for ; Wed, 15 Apr 2026 08:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776265786; x=1776870586; 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=BKxh1xV1gWd+m52UTAHmFCb6N+6HL0A4jah73SCv02s=; b=o2A2d6F+75vl5Ap9D8rf4PS4GkwQlkp8oaYJoChMnv8akyPduPm/7tFmSEBy3UgzUu n8YO5kpxdw9wuAAPV1UlrzOAm5s5vCcBt6QUaF4eGqVhmlu6L6to1SIXOL6BjK3U/s29 RpuK2p4t7gEnLzB3vzZUuDd4iAK/YSm4/WDGvKkvY+tt4s7Gt10ICHp0vv7magaGi5HW Cb3bI48NL1+4MLNFxAOu09XejI4vkftZnaUfrxqUngI/Do4Qz9SGAtoZ9Er9yKOoorvN ecOXYNMICPoyLy3m5n+GTpV4c59sRT2uYtifpCSWIQHhviK9LKMD3qmmX/aXukRYEVtA YwPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776265786; x=1776870586; 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=BKxh1xV1gWd+m52UTAHmFCb6N+6HL0A4jah73SCv02s=; b=Dq88lvMyX1rG/gyFxUdT3tVXqtjhodA8oYW2bShfRj+1xCsKmI66X2K+yuLiDWc9Cr /bjPQQ9aipVgIL4DGpguIf6MqSb5xWnxhfSGLwECPozYslqiGZQAvxWq/tPznB7VWmJV cw+MrXRucsddgG4yPqPkIBDSUfeQJUw/h8LRR5InEPXftcrlMcloFcMwiO/Sm5ClIl4A J4fqokMx5uCq44kbw077ptsG1ys5YG9M6oRS0xvt6d+eBxUVsWVYgCY6CpOmkmu9NbmY rLD++bRmAvl0HfRt7qBCDddkmCR8NDy9HpapRLnGudQy7djK1Z+XNjFlEPneVsTkThYL Kr1w== X-Forwarded-Encrypted: i=1; AFNElJ8aAYkMnGDNnkjSnOheRgdJDo3rwV+/258lm6jXZ9GUj0HScFuQvJZVMBdCyyiXkTBhKqgFDZAl9fyVASs=@vger.kernel.org X-Gm-Message-State: AOJu0YwgEEGW2J4vkSDk1vC2I/q3Ke3vgogxg0k6UMt9JA27KQRZStC/ lYkhnNlbCjB+1uaAmm/YhQtOSEy7lWjIZXajgH9znaW8Nf19svbu7QBmSQYlqSbs8Gw4QImRkmb GDotHvjrojt2wKMtwRUWTXuS5GvWGHsWa3Gq3pfaERg2geutmLvD+efyRUN3lSFLG7A== X-Gm-Gg: AeBDiev2ESmuXPshgjwT0j+JjcG0ePkTP0ifFXJr36VKwTjNRFjPWxQB6qDs1e0qeSU Y+32wjg7mRHJngs357qS80qP6E3P+roaECo3NcRSQTelPrdfg/+6mzUMaVWtHmewr6+CHuWBX/Z +OMFRgL3NMkyRsN/iYmFDTuPu6CUZYDO15zvbSiyWDMQ/sp1g7QuN9Zoo1vWI1vVDNHJhPDbyJG 0xaRWngzANsyByp+IkorpW7GLSLZKsQ4K4mGHgyIT0B8mYwFKga7HOXGq+xuz6uxsBIz1eTeE6P kGLWdUTEIim0ZpaSE0nf78q71BcZojgTnPfyOCAL4aSZ0vGpL1mWgdbbOr1XIxv1UJbdenxKiyi kNjAH7x8IsFLO2+ClsMJRHS3VxZm537bpdYDjctoGCCDTBsXdTxVrpaO3zVzp X-Received: by 2002:a05:6000:2a84:b0:43d:7a5e:8162 with SMTP id ffacd0b85a97d-43d7a5e8360mr12790580f8f.15.1776265785697; Wed, 15 Apr 2026 08:09:45 -0700 (PDT) X-Received: by 2002:a05:6000:2a84:b0:43d:7a5e:8162 with SMTP id ffacd0b85a97d-43d7a5e8360mr12790549f8f.15.1776265785199; Wed, 15 Apr 2026 08:09:45 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43ead35bf1esm5907557f8f.16.2026.04.15.08.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 08:09:43 -0700 (PDT) From: Luigi Leonardi Date: Wed, 15 Apr 2026 17:09:30 +0200 Subject: [PATCH net v4 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: quoted-printable Message-Id: <20260415-fix_peek-v4-3-8207e872759e@redhat.com> References: <20260415-fix_peek-v4-0-8207e872759e@redhat.com> In-Reply-To: <20260415-fix_peek-v4-0-8207e872759e@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 an 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. The test re-uses `test_stream_msg_peek_client()` to also cover this scenario. Reviewed-by: Stefano Garzarella Signed-off-by: Luigi Leonardi --- tools/testing/vsock/vsock_test.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index bdb0754965df..76be0e4a7f0e 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -346,6 +346,38 @@ static void test_stream_msg_peek_server(const struct t= est_opts *opts) return test_msg_peek_server(opts, false); } =20 +static void test_stream_peek_after_recv_server(const struct test_opts *opt= s) +{ + unsigned char buf_normal[MSG_PEEK_BUF_LEN]; + unsigned char buf_peek[MSG_PEEK_BUF_LEN]; + int fd; + + fd =3D 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_normal, 1, 0, 1); + + /* Peek with a buffer larger than the remaining data */ + recv_buf(fd, buf_peek, sizeof(buf_peek), MSG_PEEK, sizeof(buf_peek) - 1); + + /* Consume the remaining data */ + recv_buf(fd, buf_normal, sizeof(buf_normal) - 1, 0, sizeof(buf_normal) - = 1); + + /* Compare full peek and normal read. */ + if (memcmp(buf_peek, buf_normal, sizeof(buf_peek) - 1)) { + fprintf(stderr, "Full peek data mismatch\n"); + exit(EXIT_FAILURE); + } + + close(fd); +} + #define SOCK_BUF_SIZE (2 * 1024 * 1024) #define SOCK_BUF_SIZE_SMALL (64 * 1024) #define MAX_MSG_PAGES 4 @@ -2509,6 +2541,11 @@ static struct test_case test_cases[] =3D { .run_client =3D test_stream_tx_credit_bounds_client, .run_server =3D test_stream_tx_credit_bounds_server, }, + { + .name =3D "SOCK_STREAM MSG_PEEK after partial recv", + .run_client =3D test_stream_msg_peek_client, + .run_server =3D test_stream_peek_after_recv_server, + }, {}, }; =20 --=20 2.53.0