From nobody Mon Jun 15 23:16:57 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 57AD73ED109 for ; Tue, 14 Apr 2026 16:10:31 +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=1776183032; cv=none; b=DHKCvgpspnRNymp5j6B2QHscF6t3nsvqXce3IIUIcLD0WzV2F/l74IVWs/OnG7qEASTCUM3sI+l/ww2RA1us8WjxKrXhQLwCwbU/wOzsX9WqFPf6fG2v8B91329j+nxQAkUB8GV9B9bwgPtUNNAwVouhKodL954eG40Ag8Wb4e4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776183032; c=relaxed/simple; bh=8KxSLwY587LR57aGsCLpqgDw1kJidOt4vFYe6TGecyU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aZVGoP5lKz3GWcZb+/Kjq/Q+jOeLEe85Ty5Ow9FO50NZ55AyNFkT81kLPXRZ1wNnqS2+/uH6QenmQoyspIOemGcR9T0u9vF+TsnCh3pVCVcWsylEE2sOS0iL7f2JRKIBMlSwA6wNFFsarOygboPCD3f96Oh5X9REfFvrmaPz+54= 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=MMzKIUBo; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=a1bfUYR3; 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="MMzKIUBo"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="a1bfUYR3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776183030; 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=MMzKIUBoEDSROwAa381QSUT3xNo7/Gz/GZ7x1g2Crr/miHummwPM/3s+nQGOr/w7maZllm fVQ5O9M3k1aiZfvWam6ZG12AhlKVzqcFs0MBMPXchqf0Q2iNoD+QtNmi1Aau6UjN6MiWwQ iCRmkyB1S4ssDAyuV1+IJAIuR5ok81w= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-338-1xy2lHmjPZ-YCjvbSPAr6A-1; Tue, 14 Apr 2026 12:10:27 -0400 X-MC-Unique: 1xy2lHmjPZ-YCjvbSPAr6A-1 X-Mimecast-MFC-AGG-ID: 1xy2lHmjPZ-YCjvbSPAr6A_1776183027 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4362197d1easo4059498f8f.2 for ; Tue, 14 Apr 2026 09:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776183026; x=1776787826; 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=a1bfUYR3Z8jsK6ngfE5aV6nn4igFxI236y4VbJXay7vQrMsiH6r5dYiBZY4Sy96sGY tfdNGMKD3ESwrGm+mdtON02U0KStduVbPdcRwF6RPiY1il0ZOzV7dB9wJMGCBoTYllXB sC0Q3r2r2a3lTzUjXeQtqoi0BGsTv2ogjeBR4uJ/QLIelTB6MPfDvqQsa4HWSJ1HzTTf 2IMOrH9SB9p6ARIQ1WSkeDOJE9hfHoYyF+jP/8Z+B9M/EpjFmCcifOSpVnD+LcwpBWSr WhVsl8aYfcWhdqaVxpqcdFX6ua7qsMesqiYj+JChIpjW/QUfSLhZViSxQexmtVxF3RHE raOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776183026; x=1776787826; 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=riIyYsU29Cr4BVaM5PFj6lFt30TK3f0ZP8DWMMS7TNPvz87Ckx8d78bLRh09IQMZlC xd1OwIwV7a8ghNmEkn36Fpxao4n2Fw2OZH+c4pwE2Oi2+G1ARf3PFcxW+bjtqIUXX9I3 ZQ46yS7ZJAFwwhNTU/trl0MIkf/eZv7+ZVuTmVJ+I51NNLfOsg90yaiNPoFBl308+BQr OaU340IUaJ6BZmtLb6KPasrSK5ourwRL/AW2QdXSzLoUu+2QWr2h9uDr25FZQNeNzihl Wx9g5xCZY1Ki8xRhOo5kibJqm/2bldAiXWa5VrgiqhFZBhhNMp4ggdY9dLAvauqkFKLq 3GDQ== X-Forwarded-Encrypted: i=1; AFNElJ9cgOs6/V1Zrw4O6HBdtWj46BJywXWHcdV9qNA8JodkNu2Sz+jXGaL8UhE8KNebhKhd5+9yorT+OLyLqbg=@vger.kernel.org X-Gm-Message-State: AOJu0YybE+y1MKZKcz8FzqEs5EU/LmO/HWa+qUVMysYKHCZoPatpfpF4 DVbdtVE74mzyb6Yw3xW4txepH+bo20R8+qva8P1Xqh+bEUXmUESZv+vl92kcwwOQcpSejqGx0RA Zd153izf48NzSOejvnh6V3nduNzHMjX3621qjbEVaMwx2OG52bSxwEkcoXZzvVZOs5Q== X-Gm-Gg: AeBDieuHp4lx4UIk+uNkhYMbgUZmmpZuDajMAcziB18ZHcqAl/MfM/h3mDGMFPDp315 x71NLH1clfJxkmyh1XoSwGVCcBsejBYoKE2hGUEV/YNopPXnGWSSTTWPU7d5/hJEYs7dY9FFA2p mTb7OWbmnBCKDz0TNxHcgVSBbMuhWOd/GG7M7AUHdHjryZ78iIJPxHh+DRMPgIQ2bbqM+KSC9+7 L6CJNG0jLrz+bETW4+MDnOEfQHJkC91DN1ESoQJ8jmMSsgWfHmyYPRYjJcNCYA8CyTcg5m7lPcQ Tj8jRedyJdUKzqBsJ8gsPLeqhA1KgDjaRUCCGphyftVleu7edHVDy1rYXYB5rR9vSAN9lutHSgD /XesUGYSKkMjxkjKzf0D6wdqj7C9xfruEz50oiEnlwmWDV6ui9Dw7Wte2cJyD X-Received: by 2002:a05:6000:4284:b0:43d:762e:76ba with SMTP id ffacd0b85a97d-43d762e777dmr15595050f8f.17.1776183026403; Tue, 14 Apr 2026 09:10:26 -0700 (PDT) X-Received: by 2002:a05:6000:4284:b0:43d:762e:76ba with SMTP id ffacd0b85a97d-43d762e777dmr15594975f8f.17.1776183025862; Tue, 14 Apr 2026 09:10:25 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63dec090sm43035268f8f.12.2026.04.14.09.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 09:10:25 -0700 (PDT) From: Luigi Leonardi Date: Tue, 14 Apr 2026 18:10:21 +0200 Subject: [PATCH net v3 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: <20260414-fix_peek-v3-1-e7daead49f83@redhat.com> References: <20260414-fix_peek-v3-0-e7daead49f83@redhat.com> In-Reply-To: <20260414-fix_peek-v3-0-e7daead49f83@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 Mon Jun 15 23:16:57 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 C3B773ED12A for ; Tue, 14 Apr 2026 16:10:32 +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=1776183034; cv=none; b=CeZElr9TfJduvoY0ZaxgaGjFX0BPF7ziBuGMZx15qwVYYbh9wS1uyp9qN8+0uXnSYTgSS456x2E6uQg231bwea13odgdx474/pV0i1mYhcU9Dsu3etVGgWoNh31Eu0PfeLc+X2nGyo+LP78PtuO1iSuhKR1BuWi+W6whq6qAq4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776183034; c=relaxed/simple; bh=1yv4GGA0ycfjwtZCUCLrwar6tO3xyrHnQ4nzsY0/Lv4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KmKPEhM/DwGF5saSuHckmDwR+7Cwk2NqprVeLzW2AqI/5LHRSL9Cuysp7PXzrTGncgRsfmKLuhIk47vjDwL2eKK4KATCesI4MzYWrsFYEkyrsZoO93lM/hXotQnffs9Qq1an1U5geQd4q1KImR6r8MgjZ/X/IH9+91YhyLm/A1Y= 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=HkQYOFrW; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=gklIhUcD; 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="HkQYOFrW"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="gklIhUcD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776183031; 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=O8VspJYK7a4i3bSoWqkVfUZf2SDjKFNStSqOdJah6ic=; b=HkQYOFrWZQbILVb7lsKtFGd1G59+WMOrJldUsRmucxh3yW+uRWPTRMI+jtdNUqBaAq+WJn 6jbbSa4c72K/R88TD0s/egxN4sZBTgJbW4xxOORhYFu1NSIkDiKkOUvqhtuGL9gwpBZ7mf OSnpedpZM6dAUHb/ma16i34iiWBlqRY= 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-625-IJH-4vj9N2OufkZltqrBDw-1; Tue, 14 Apr 2026 12:10:29 -0400 X-MC-Unique: IJH-4vj9N2OufkZltqrBDw-1 X-Mimecast-MFC-AGG-ID: IJH-4vj9N2OufkZltqrBDw_1776183028 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-43d14a4bcd0so5944403f8f.3 for ; Tue, 14 Apr 2026 09:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776183028; x=1776787828; 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=O8VspJYK7a4i3bSoWqkVfUZf2SDjKFNStSqOdJah6ic=; b=gklIhUcD95701TnT0CVyujEbb46wOi7dd8UxHMB4UtOYjpCqQFOlRxUpb9kZfUKGfx VZhZaF8aDLt4d6bXlnT3EA6JQMsV1pyV3VoIg90QsbHcDB/3mIKxSVwXx9YipxrvwmRP FQfqzIf9mG2k/B+DVkc9NuPfE3uhKKfOi+L5e74b128Kb+y25Te9Hp64KCRM3aTZA4eo ZjTpNiMm1qt3Uh3hAvi+em6mzGTznPU/1knmvt15cpYqBRZ6IOsm0cRgmE1vjg9GdMCh oQPGMoyUb+FC55EZOCYAs8ALXkzmjhDoKNdK5kKLtAHiMycHv9V0PT1pq+rf07cAXl9M oX/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776183028; x=1776787828; 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=O8VspJYK7a4i3bSoWqkVfUZf2SDjKFNStSqOdJah6ic=; b=UB75jAswtz6D875BaNniEY4q0gMe+jPeXKKOCuMuF5YedrwGk+dL/m+doTWtL6EgmD rvxH5XJZU/bcl+7C4uyyyo33x4kobC3Jh/GsuOy9ZNxHUgMhsXrUQLf5w9nL7Xg6rD37 R5amBYN5FkPkZ1zNuKBMgbDMCRTEjausI02uB9Ma5+VIrBsKSeD1FvCmgU3N2sS32d+A VFEeDLxyDDBQ9OVKuLRHiU4SuFOgekWK32eswgwxaBq3xxlQRSOICquqQbcwG3XpqX2Y MhP26UjMvrVa7IDBxezfV4lB7Rv6hjfdTEdwjGgn6sQvLemtkmmdFaCHF3Ncr1waSOdh VgfQ== X-Forwarded-Encrypted: i=1; AFNElJ8ZmCIkjf/0Cl74QDZ1+duqsM1EdlqgAFzt/uvG/mPgmyGSLAFFzlPiXOOTsCfxaUQH0JQ1fv85fA2aKUM=@vger.kernel.org X-Gm-Message-State: AOJu0YzDlPSzLYeG/tavwBgdv6kSuGvgNeWmh+aKw8MNKkw1JOAv9Bxt e/48NFBGM2aZLzccLA/GsD45nr11gY8Uvmx4l//8WSWinZSSmsAyHPFCBt892XRH8MW4tRY9wDL X92sWZJi+pEOgxHECDPmstrzqlTLYaYhEZ81S2YTv5N5KkleGt73r+hibUYsf54GWMA== X-Gm-Gg: AeBDieuB/khSwKgVOGj29xxJhXC+v2/gsnv1tyr5PMBdQoSBTsuyoIytau4KVMugORb IiTbN4AV1tfjlj9JYBP5NipeMz946yG0zzwaUuX6c5Hbp26C/0sW8luKe6lvNWdmb4xF+3C5Rs9 xGcFAFVBDjKB7J3uNa1KCHASzo6KP00cMyuX5DqJamq35Fl2SuA5+YQBHlm3IvtzlJljA7Ewfrv 1zfP+xi8IG6wgDz8mDwbLIP3zCy/Bm57xIqhfPnaiuiY+7dWqaG4CKdPPkYk1YWRpQg2xWgSXmR BMYsRJ0+6UV5i9oSYd6aGgziMmO8tIBswB9QkpOIJoNjWfQdGg7BcIOclvy6NZcxvUSetVjSOZq REnbrPNIKMItECYuAjkkf1m39maW/NdB/LLfjFspnNJ4nIN9xMljj2aDAXbqC X-Received: by 2002:a05:6000:230d:b0:439:bcc2:bf0a with SMTP id ffacd0b85a97d-43d642b8d4cmr26748876f8f.23.1776183028024; Tue, 14 Apr 2026 09:10:28 -0700 (PDT) X-Received: by 2002:a05:6000:230d:b0:439:bcc2:bf0a with SMTP id ffacd0b85a97d-43d642b8d4cmr26748793f8f.23.1776183027431; Tue, 14 Apr 2026 09:10:27 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63dec090sm43035268f8f.12.2026.04.14.09.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 09:10:26 -0700 (PDT) From: Luigi Leonardi Date: Tue, 14 Apr 2026 18:10:22 +0200 Subject: [PATCH net v3 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: <20260414-fix_peek-v3-2-e7daead49f83@redhat.com> References: <20260414-fix_peek-v3-0-e7daead49f83@redhat.com> In-Reply-To: <20260414-fix_peek-v3-0-e7daead49f83@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 amount of bytes read: MSG_PEEK doesn't consume any bytes, 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 the requested amount is more than the bytes available, the loop will never terminate, because `recv` will never return EOF. For this reason we need to compare the amount of read bytes with the number of bytes expected. Add a check, and if the MSG_PEEK flag is present, update the counter of read bytes differently, and break if we read the expected amount. This allows us to simplify the `test_stream_credit_update_test`, by reusing `recv_buf`, like some other tests already do. This also fixes callers that pass MSG_PEEK to recv_buf(). Suggested-by: Stefano Garzarella Signed-off-by: Luigi Leonardi --- 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..2c9ee3210090 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 + /* Receive bytes in a buffer and check the return value. + * + * MSG_PEEK note: MSG_PEEK doesn't consume bytes from the buffer, so parti= al + * reads cannot be summed. Instead, the function retries until recv() retu= rns + * exactly expected_ret bytes in a single call. * * 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=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 Mon Jun 15 23:16:57 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 0ABC43ED10D for ; Tue, 14 Apr 2026 16:10:34 +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=1776183036; cv=none; b=aba7bFRNxIVrGmAz7mwRKGkEd3vsSQXvXQmP2hJ4xmjbBQoOmoU8L3Ig+z2JwNxgdie+nBI0qb24nS6MLYAhO6wXGSoodlbrWe12KwA9Fx4IyneJkqphAIPoXOtHuysrYY2B+jrSdhikjArNOQULlqi96TdrsHNr0iegD2fsdg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776183036; c=relaxed/simple; bh=jtcpbJn9RIdJlr0hVO963zpJX/82bBkk/hi4mZSImLE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X4Lzh5hqWHzUUoIeRWLbhpwy9ZU41QR6rEjUE1ZJ7wVD91DXDZhbupOPX9JTxte6Nh0+Y3C4W96gIxYXhozYpe9CB0KQd3AOVhFDTzkw1NdFbGoZkdk3kkLG/5X+Lsek/DX57YhkeQldPja/bzoHHO8LPMCVl2/Jywwo6e6fBr8= 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=WrxdQ8zd; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hJJ2T3f2; 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="WrxdQ8zd"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hJJ2T3f2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776183034; 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=T4qpSiwLjabUf/q5/q3aDN7iNzObMaLZodRYuDBTSlw=; b=WrxdQ8zdlZQkxM35azZWPSGWn1S2Q98Voe9tLapSHEPemlHPk4Tc66U5kkmYSZnsKUG2vU 4DSVOItTCpBp9loDVFhaa0OiEnAHrmMF8qmp2E6dm7yp7VDjFaID5Rg0hu3VbZ+40wTRGs Wm9EMAIa+mfJYFzdXIr3qGj4Am5Rt2U= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-hGPFzISnM02zNUeoqKB1Sw-1; Tue, 14 Apr 2026 12:10:30 -0400 X-MC-Unique: hGPFzISnM02zNUeoqKB1Sw-1 X-Mimecast-MFC-AGG-ID: hGPFzISnM02zNUeoqKB1Sw_1776183029 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d7d0947aeso961876f8f.3 for ; Tue, 14 Apr 2026 09:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776183029; x=1776787829; 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=T4qpSiwLjabUf/q5/q3aDN7iNzObMaLZodRYuDBTSlw=; b=hJJ2T3f2Zam6T20AAqDBmgX8BWH53DXbJXAdHDKMrpfSERy0VwfHy4aRieMjFiDBOb VARpsmbc3fiaExISRehlrqqePwAyo5xDCzX2Eh1Yoof2DgxzYxXv2BkHl5hsbG5cGBO1 U3lc5FanUERYTTk5yfn7fmK+/xBYvaFx02jZ6A1poTVCtIds+I+lK0Vc3PMCxpBYB8kE V/Gppu8z/7+wbLVUPSHeVjU0UgFFH6BoR6jLUFXJjn7fYY39cAuzOp7LpAGWyYVRWAS6 52i3c30YqC/KYrollK3KsqopkbXtIl8XEvA3GwJ98DKIwOg4ZvcZi1SD2goMSu7ZeAeG ScHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776183029; x=1776787829; 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=T4qpSiwLjabUf/q5/q3aDN7iNzObMaLZodRYuDBTSlw=; b=gERNpxZxwrwa9p6wMXisqPQDKLR6y8REDSj0mW6XiVAEs0jRxDiFPttPEtdS8xs3MG BWK+os4ToPBAmlU/pKiei+dec+Ayi9BPxjkVTb5SN1VQvDVUaZw2FVrK3PdNmV8r1qHV Jeo/t2/4GOTef64fwmf3IHGrLQNXn+pf/WBnh/X+pJ5CDuN2TP8xlayhX0aENWRAZ7UK fNhOdiVdu7u/JNpAOBX6//PWKhCOT75tFYWUk0vNyZ7LGSHuFmhwuPOdmi3KqZAvg4yP h9Wa0pyuKPtgy4pP98tQ4duhKsoTkIaXefDi7UFuTdHaD4dxgHBmghs2nZEO6o91q7Yq YXAQ== X-Forwarded-Encrypted: i=1; AFNElJ9aZkkkEhA61GAGDwZc2ryPnhGMGTcT0GC+f9J2nwXifWO2sJNlklKL+dE5jdXPpm76ccqAyBuhD1Aez64=@vger.kernel.org X-Gm-Message-State: AOJu0YzHB5TYK8StztYYRxN+RbmAt0gOw/TqBRle/MCrTrx/8hZsOaKZ aT+2aCR5OfWugLEAm6Daqa+Gl8mkvrHzVwyMVtTjmV99A3dzBOHdZW1/23lfiKCOrT0jurxLZ/X Mmd/J5NTS2JBbkLJKqDpEHec8gnD0C+dLASvqR1hsf6LMxxc+d8DiHObf7Wio8PIxuw== X-Gm-Gg: AeBDievd9Id5jDR5dMkcyWwvo4g0Gb+THHFcX/uUvSxaMwXvujg2gcJmh1/tE2mT2YK +KCFXzdu+2/XzGKqAsP0Owp+jwGR4/qk6/Lf+1LgUfBL13v499h5yPd2RuKbqRuUGmaTycUSWTW 5Xrh0pmadL4UPRdKdePHJuGHfysJfRqg85tQpvqdQ7sOV4ypJrYoGdRqzSwl6Zm7Kew5KIAy9B8 VANF/dxh9e8Cg5/UajUeOVAqXI1i1PznocYycN14w6EpjIzDpgT+Uzvm8SV05NkeR11yhg+te+h buaHq28ZiKJd6uEuLwSIG+7q8xR6EP6uhx9PgfV1+oOYjkVlCm0rM8vJUqFD5hTuT5eYp6FKbEK QYm8rKE32EDbROmq/jyRowk7NoIleIHeFFNqzb4ayh+7+4FFxO9PnYgyaCTvi X-Received: by 2002:a05:6000:1ac5:b0:43c:fa96:d939 with SMTP id ffacd0b85a97d-43d6429c737mr27847311f8f.22.1776183029366; Tue, 14 Apr 2026 09:10:29 -0700 (PDT) X-Received: by 2002:a05:6000:1ac5:b0:43c:fa96:d939 with SMTP id ffacd0b85a97d-43d6429c737mr27847250f8f.22.1776183028882; Tue, 14 Apr 2026 09:10:28 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63dec090sm43035268f8f.12.2026.04.14.09.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 09:10:28 -0700 (PDT) From: Luigi Leonardi Date: Tue, 14 Apr 2026 18:10:23 +0200 Subject: [PATCH net v3 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: <20260414-fix_peek-v3-3-e7daead49f83@redhat.com> References: <20260414-fix_peek-v3-0-e7daead49f83@redhat.com> In-Reply-To: <20260414-fix_peek-v3-0-e7daead49f83@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. Signed-off-by: Luigi Leonardi Reviewed-by: Stefano Garzarella --- 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..ab387a13f0ae 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); + + /* Ask more bytes than available */ + recv_buf(fd, buf_peek, sizeof(buf_peek), MSG_PEEK, sizeof(buf_peek) - 1); + + /* Recv rest of the 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