From nobody Mon Jun 15 00:04: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 EE6B43A1693 for ; Tue, 7 Apr 2026 09:14:07 +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=1775553249; cv=none; b=PH84FB/HO8sJrkEZsjsvAXSU5hLScz3HH39VV0ejIrmHBC1bhwC0BzRAB6vh3+olHhcmSUN9A5aMRAQ8zXlKpybKBKBqWVv+cGS+7HzoOMW2aqbGxYTIKJ26ECFOpt2cZyOMMsNxoZDV+3f3XA1OG9WKFKK2SH4l+gpCcn7F6EA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775553249; c=relaxed/simple; bh=gb7Ruua+gJ5a6hrcK6PHPahbGnBvVqCiLHNSA4MS8gc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F4YOFC7RA5WxbHS7IVeMlVWUyjFZiZhBRLGC2zIh0dz0ndl9Pk55qEqSMHJlYNUogTHaKzuy6HNAipVNS5FCBrvUwI4fgbw8ReScgXX9IjFPmChLgsKcObfVfOyBicHiuxjCY94h5q4vKAWp8a1vZ+w7rgvPv2wPoMzYI7P3wjk= 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=ZBy7e7Fq; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=GsH2L7bX; 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="ZBy7e7Fq"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="GsH2L7bX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775553246; 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=nou53lLTv7UEsO0o7KVxM0MjcDicbnJfC8/ClZPwZgg=; b=ZBy7e7FqMf6CRs1/Ueupy9bRz4jO4amypwZos6DhtiUejQF0Cmw1qPng8ZtU4tOlqKDhcv HT/7Q4+DRyGc0i1KSndxKvh6whCqMUFdURNzu3orGvhQQaHybG93x/HdWnIHKFvT2ue8Pw Ce6Tj8O5VY9RSGRvDx7TRtDbF6vgPBs= 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-1-qkXj1AB_MoKqCNtvnQNS8A-1; Tue, 07 Apr 2026 05:14:04 -0400 X-MC-Unique: qkXj1AB_MoKqCNtvnQNS8A-1 X-Mimecast-MFC-AGG-ID: qkXj1AB_MoKqCNtvnQNS8A_1775553243 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d121c4271so3332971f8f.3 for ; Tue, 07 Apr 2026 02:14:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775553243; x=1776158043; 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=nou53lLTv7UEsO0o7KVxM0MjcDicbnJfC8/ClZPwZgg=; b=GsH2L7bXkM6pI34lvmuFuLM7tSOXqGUQ12Q/qt/E8EKv8SQ0OzvOpHZgNV7g9Byk3G k+P/xWGGaalrwZfA2firuxNlGHG1N7MA1vS/y9L2+Gj9RjPHuxYN6J66QmjpClS1Vn0g oKR5qCZVIuFYag9p3O0CThtALRQtgOjdGf781IPI8oE/C762GBvdoECZS1l/v1TQ9Zn0 Q78a6utaxjE4CUXQxiwDriFUBdXUY4SQFyAmJNnrDABZCJNyYWqAXRm+frGtkvwL8N87 QNEsL98sPTWAiosVriPlaSl0dkICMZvmoNPYxST1q7LiDGnWpMppoXfmqoHA1FTeSi7M EVdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775553243; x=1776158043; 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=nou53lLTv7UEsO0o7KVxM0MjcDicbnJfC8/ClZPwZgg=; b=hLjHcqHjRDi+EPd8IjlVWeyRlD9o5UjAf3KRHmwoG3TB6TQw2YANFeN0F8wkAImmqw e5FluWlZ5+b/Tm+InxwdcfWdKmFluAj1iZ1wDpRtVwYJlpsQL7DEA5kk7XrrXsE+xslo 1lTyx1rKQJO0kk2Wqpb51UXsmwnTbpCeRqd9fQRihrDsbfzeVBx0mC/D6Epuh/tg/E3r rupq/aqxCrpRXY7MTKR+NxOMKUxVt2eJ2rYxEA0YDxDbxxb6XtuH/NRO3O+6ytLAvVJQ d604eVRT10Wt4+UcRc7EAJ8CWKN37crD15iiTVc4epBclbUIwyDOOsrV/1p0/HFp4WqG mtQA== X-Forwarded-Encrypted: i=1; AJvYcCUS915dIoHXO3apJXNX+ZAZ0tRpLPqLGX8HLyzBEBgVZ3B7gxHKOpEueEt2tC5h2UrNWEBQJij6dZ9g9H8=@vger.kernel.org X-Gm-Message-State: AOJu0YxNGPBbTDUBIhTWuneCLPmurCU3WaXLY22JPYUVwDoptxr8qMot /9mj2uKKuhNvym+8n9yNq9egbDjf+cgQdQjAZ84OSwzwXyL4a/EHxTpSl+GvzYQf06AK21VJ/ah IQtjb+O3WYDcSVSlb8C/FG8meh7g7WHiSSHeH+6IB5/FQg/71dgibaMFll8cc/hYZLA== X-Gm-Gg: AeBDies74fiYDhNCCB9EMtgIY0AFOzQnVEu63bfx/65EELzTMqED5B2eBqHvElH/1c+ bNcmDB5dSWkOCgZKe7UANj3aaKpPKI6mWH9NC9pmyo4xX6awNlB76Xnis6ERBa4S1i2fqmLTm9z Eh42oheisyo9i/vg1DQ3XlWyiKne7LXWei74u9Uw0qxlVFhqc9PjNG5t9+2jWYDoYaAbdS3FtCy 7zupXbsTUfCdUbb7MQvxw2xh7iSt6rZm5hm2hPRZsbzqSUVYinsnUls5LSrzzL5+Qne3qx/A+h0 9MXrHrSp54F5aTBvlkqJ9OjGjBiohFEdcSoVEL6mSGjy+4J/gigiPihM2JbmarYpBaLFs5gCy9W 65QLe3M5bcaaiGY65iTl7+RBKuFvAXkPeddRk2rOodhOxKsIs/XLOYUaFn43v X-Received: by 2002:a05:600c:8216:b0:488:ac01:72b6 with SMTP id 5b1f17b1804b1-488ac017468mr111080295e9.21.1775553242804; Tue, 07 Apr 2026 02:14:02 -0700 (PDT) X-Received: by 2002:a05:600c:8216:b0:488:ac01:72b6 with SMTP id 5b1f17b1804b1-488ac017468mr111079805e9.21.1775553242317; Tue, 07 Apr 2026 02:14:02 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 02:14:01 -0700 (PDT) From: Luigi Leonardi Date: Tue, 07 Apr 2026 11:13:55 +0200 Subject: [PATCH net v2 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: <20260407-fix_peek-v2-1-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 `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") Signed-off-by: Luigi Leonardi Reviewed-by: Stefano Garzarella Acked-by: Arseniy Krasnov --- 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 8a9fb23c6e85..4b65bfe5d875 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -547,9 +547,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 00:04: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 EE52B3A0EA2 for ; Tue, 7 Apr 2026 09:14:07 +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=1775553250; cv=none; b=ELC9eAM9qA8Rgs4/HvChnpySh0P/VxvMPhHveFemu2eJMZjuzaULo/tv9abHCF7NJYg9ObkcllnScEmhEsp4hKWQRv8zlqUzQOR9BK1+nym3O0Wc9heVd382i89gooZ4snET0Ty5+NI3iW9MSxvrEhttTfyw8iZ+hKXS/KXESgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775553250; c=relaxed/simple; bh=TPyeaXldjZ/vNi3cTj7MlzLbGl/Ixp9Pbj/uTFr2sk4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ao8sTSGhNxxSAIRJ64PP9iN6t9tJaSUmGZP2fu5raBG1DWL1hHbPbklGu1MOtoDlUrDe8v7q9/jlNaaTC+QYcW9HiB7RuPO8qKQzo29RITRplytRfcEna3H/NekGXUj+wRDzzOJZ0tgII5bX7BvpaPJqMuS8/AdxC6JaPxpx6Z4= 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=KkbVsg/B; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=X7rymZQj; 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="KkbVsg/B"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="X7rymZQj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775553246; 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=5MvBSgtjWIPj7YtiYQ1QdgeAu7KbULO0Duu0OFbmnZU=; b=KkbVsg/BGk866pUFTw9KdxzP4cD33xxofsxI9lrn/ZVUajcXinvur++vXHX/juRUjYVK0+ qgklgVujHGH7+HbkWq43bxDoSNMiwoHXY14gLZGJHxyVz8JNAz/D8E5bAb4N2gU0/LMzif fOez/lc2kGYV9QY8JjS4k8ldLZDID0o= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-3s07_bEtM324u-mDpXvpQQ-1; Tue, 07 Apr 2026 05:14:05 -0400 X-MC-Unique: 3s07_bEtM324u-mDpXvpQQ-1 X-Mimecast-MFC-AGG-ID: 3s07_bEtM324u-mDpXvpQQ_1775553244 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4839fc4cef6so58568065e9.0 for ; Tue, 07 Apr 2026 02:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775553244; x=1776158044; 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=5MvBSgtjWIPj7YtiYQ1QdgeAu7KbULO0Duu0OFbmnZU=; b=X7rymZQjmzMh+azmi4F5vc6e4635bgO7zxenf3Ts58RlzGBol7OgBILGGoGrjqWLlV m903/w/68zYOC4RU8j0lfYgqPUnGCIybxmdsKZY1bl4qLK3chXEAqdk2/X477IZnS+Og ExaLcvO8n5dzBabvo/YAZO5lj3/KFjnmwvHd7qTEfu/cr16WjQSbSz3F+W6z8iE8znVE 64MCoKWscpO5W7836p7DMMLMu0IttuCKCkJXAfm6zbhB2WJF2AsQezJf+KigvvfOqKY5 HE2Gj3yjMByuEn9O6Q0Bd0kP5yruq1NW5FSHtOhx4McPfcupv9akLzXQyG0HGYJKf92C ROVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775553244; x=1776158044; 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=5MvBSgtjWIPj7YtiYQ1QdgeAu7KbULO0Duu0OFbmnZU=; b=BNVM+olClFQgJvQu2G9gTnLPc6AruqNSPFudWL6pDeNTA1JRgDNQ/d8oVH/HkFkRKg muxJsqBSbQI0sN3m8o9J29eYofI2oHrZ0x5XQwHSJEhtASkzusSe5dSRPiKyLENyfFP3 ax34rxzlDg+ZraLsZds70W3BbY88iu8OZbHk/BsaKp8hKeK9QWJAKLXiDsK6fMaLbzZE mFmyu/+COyBxj+LeKHKv0gPg3ArGvUv/Dd4LcxdxN53qEgNzZjVeUmHOTu7jErdUja2L QQrKyVaOuyVaLE/QjugJGIyFFqd02tHIDwCPZJ9km+WDCDxYKGw9kzaY+1tj1MpU6mRE Ul0g== X-Forwarded-Encrypted: i=1; AJvYcCUXGz3CYYzouO8V0HDlxOGsJ0Ork+Fik7edhLaEIIPHNGNr/PGxEcT17m8v16vTumjaeH3guzw5f4GaaqU=@vger.kernel.org X-Gm-Message-State: AOJu0YxGXrE+BKL1UcQSuAQgDU48v2AXUmMrwxvnauqPTw+bglXQlMCA aolVXENjyX18lvKFtJDqwdzY8Dtiw0Y26yrRrlKgYXSPwsDiUm+lidaAKbMoDOM4BuOeUdaUeaY gPPMlGtcHYSmRkVIbV6ZfEhsDIFxRbst29Dq18+d2CuuOJay+WNQeuHz6nYFLXJld0Q== X-Gm-Gg: AeBDievklf2vLHvF5XXBdOGYBES3WBQLlIuR7q+WsmcFNmQeUtAZ88NkyWCCsLIflBA 8t5M6QFcxsmg3SaLX2SeM/VOd+kVyJoRzXLNgBRaTHqncXU2aCymFzkQtEg/1l+LOd0KCi2Ya50 MzbmBT1bhAFLEX00b2rjtgP8MbLlNcBqjE6bqggMM5TDS8/9bP7FxmZdspu4uGDHZwfS252PZSV m/eAIyGX3nhNv84AZ0yuxVtj7+AEMG5G5jIkAEdtzFhId04bUV+XSMO1cgwAI/8mZJFl+k2tqi7 MitKdnqNtvLSiWEetqPdJY0zOPEjxsiCeC3pQvCbIHZJHOj7PZJ/Nya0q8IpxcRXRJDzkIH7011 IX/X1QAUkA+JJd7vSSx+Q75GZ41WeeNYhV/zjwSl36k8B1IsykjmxhrLrxV1V X-Received: by 2002:a05:600c:620d:b0:485:fbd2:f72 with SMTP id 5b1f17b1804b1-4889945faa5mr212240085e9.1.1775553244225; Tue, 07 Apr 2026 02:14:04 -0700 (PDT) X-Received: by 2002:a05:600c:620d:b0:485:fbd2:f72 with SMTP id 5b1f17b1804b1-4889945faa5mr212239435e9.1.1775553243640; Tue, 07 Apr 2026 02:14:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 02:14:03 -0700 (PDT) From: Luigi Leonardi Date: Tue, 07 Apr 2026 11:13:56 +0200 Subject: [PATCH net v2 2/3] vsock/test: handle MSG_PEEK 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: <20260407-fix_peek-v2-2-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 `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`. Suggested-by: Stefano Garzarella Signed-off-by: Luigi Leonardi --- tools/testing/vsock/util.c | 8 ++++++++ tools/testing/vsock/vsock_test.c | 13 +------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 9430ef5b8bc3..f12425ca99ed 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -399,6 +399,14 @@ void recv_buf(int fd, void *buf, size_t len, int flags= , ssize_t expected_ret) if (ret =3D=3D 0 || (ret < 0 && errno !=3D EINTR)) break; =20 + if (flags & MSG_PEEK) { + if (ret =3D=3D expected_ret) { + nread =3D ret; + break; + } + 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 00:04: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 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: quoted-printable 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_t= est.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 t= est_opts *opts) return test_msg_peek_server(opts, false); } =20 +static void test_stream_peek_after_recv_client(const struct test_opts *opt= s) +{ + unsigned char buf[MSG_PEEK_BUF_LEN]; + int fd; + + fd =3D 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 *opt= s) +{ + unsigned char buf[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); + } + + /* 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[] =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_peek_after_recv_client, + .run_server =3D test_stream_peek_after_recv_server, + }, {}, }; =20 --=20 2.53.0