Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v2] vhost/net: fix clear_user start address in VHOST_GET_FEATURES_ARRAY
@ 2026-06-26  7:04 rom.wang
  2026-06-26 11:31 ` Eugenio Perez Martin
  0 siblings, 1 reply; 8+ messages in thread
From: rom.wang @ 2026-06-26  7:04 UTC (permalink / raw)
  To: Michael S . Tsirkin, Jason Wang, Eugenio Pérez, Paolo Abeni,
	kvm, virtualization, netdev
  Cc: linux-kernel, Yufeng Wang

From: Yufeng Wang <wangyufeng@kylinos.cn>

The clear_user() call in VHOST_GET_FEATURES_ARRAY incorrectly starts
at argp, which is the beginning of the features array, overwriting the
data just written by copy_to_user(). It should start after the copied
elements at argp + copied * sizeof(u64) to only zero the trailing
unused space.

Use size_mul() for both the offset and length calculations so the
arithmetic stays consistent with the surrounding code and remains
overflow-safe.

Fixes: 333c515d1896 ("vhost-net: allow configuring extended features")
Signed-off-by: Yufeng Wang <wangyufeng@kylinos.cn>

---
Changes in v2:
- Use size_mul() for the offset calculation as well, per review feedback.

Link to v1: https://lore.kernel.org/all/20260526080336.61296-1-r4o5m6e8o@163.com/

Note:
Thank you for your review and suggestions.

I tried to add a switch in tools/virtio/vhost_net_test.c.
The switch is meant to use VHOST_GET_FEATURES_ARRAY and
VHOST_SET_FEATURES_ARRAY instead of the legacy versions.

However, when I ran `make virtio` in the tools directory,
the build failed with an error: missing asm/percpu_types.h.
I fixed that error, but then another error appeared.

Would it be acceptable to postpone the submission of
this test case until I have sorted out all the build
errors?
---
 drivers/vhost/net.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 77b59f49bddb..4b963dafa233 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -1784,7 +1784,8 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
 			return -EFAULT;
 
 		/* Zero the trailing space provided by user-space, if any */
-		if (clear_user(argp, size_mul(count - copied, sizeof(u64))))
+		if (clear_user(argp + size_mul(copied, sizeof(u64)),
+			       size_mul(count - copied, sizeof(u64))))
 			return -EFAULT;
 		return 0;
 	case VHOST_SET_FEATURES_ARRAY:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-08-06  6:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26  7:04 [PATCH v2] vhost/net: fix clear_user start address in VHOST_GET_FEATURES_ARRAY rom.wang
2026-06-26 11:31 ` Eugenio Perez Martin
2026-08-04  8:01   ` [PATCH 0/3] tools/virtio: exercise VHOST_*_FEATURES_ARRAY ioctls rom.wang
2026-08-04  8:01     ` [PATCH 1/3] tools/virtio: add device-id compat header for virtio rom.wang
2026-08-04  8:01     ` [PATCH 2/3] tools/virtio: add __must_be_array stub rom.wang
2026-08-04  8:01     ` [PATCH 3/3] tools/virtio: add --features-array switch rom.wang
2026-08-05  8:02       ` sashiko-bot
2026-08-06  6:48       ` rom.wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox