Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: rom.wang <r4o5m6e8o@163.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 3/3] tools/virtio: add --features-array switch
Date: Wed, 05 Aug 2026 08:02:07 +0000	[thread overview]
Message-ID: <20260805080207.E3EF61F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804080125.79403-4-r4o5m6e8o@163.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The kernel implementation of VHOST_GET_FEATURES_ARRAY zeroes out the returned features instead of the tail, causing incorrect ioctl behavior and causing the newly added test to fail.
--

--- Patch [3]: [PATCH 3/3] tools/virtio: add --features-array switch ---
commit 62c148ff31dfbcede0d6da6c8873dc84602618f3
Author: Yufeng Wang <wangyufeng@kylinos.cn>

tools/virtio: add --features-array switch

This patch adds a --features-array switch to vhost_net_test to exercise the
VHOST_SET_FEATURES_ARRAY and VHOST_GET_FEATURES_ARRAY ioctls. The test verifies
that the kernel correctly copies the features and clears the trailing space when
the requested count exceeds the kernel's defined feature entries.

> diff --git a/tools/virtio/vhost_net_test.c b/tools/virtio/vhost_net_test.c
> index 389d99a6d7c76..77191e60a7a35 100644
> --- a/tools/virtio/vhost_net_test.c
> +++ b/tools/virtio/vhost_net_test.c
[ ... ]
> @@ -467,11 +491,43 @@ static void help(int status)
[ ... ]
> +static void verify_get_features_array(struct vdev_info *dev)
> +{
> +	struct vhost_features_array *clean, *dirty;
> +	int r, i;
> +
> +	clean = calloc(1, struct_size(clean, features, GET_FEATURES_ARRAY_COUNT));
> +	assert(clean);
> +	clean->count = GET_FEATURES_ARRAY_COUNT;
> +	r = ioctl(dev->control, VHOST_GET_FEATURES_ARRAY, clean);
> +	assert(r >= 0);
> +
> +	/* Sentinel-fill so the kernel's clear_user() of the tail is visible. */
> +	dirty = calloc(1, struct_size(dirty, features, GET_FEATURES_ARRAY_COUNT));
> +	assert(dirty);
> +	dirty->count = GET_FEATURES_ARRAY_COUNT;
> +	memset(dirty->features, 0xa5, GET_FEATURES_ARRAY_COUNT * sizeof(dirty->features[0]));
> +	r = ioctl(dev->control, VHOST_GET_FEATURES_ARRAY, dirty);
> +	assert(r >= 0);
> +
> +	/* Must match; a wrong clear_user() start would leave them unequal. */
> +	for (i = 0; i < GET_FEATURES_ARRAY_COUNT; i++)
> +		assert(clean->features[i] == dirty->features[i]);

[Severity: High]
This is a pre-existing issue, but will this assert consistently fail against the
current kernel implementation of VHOST_GET_FEATURES_ARRAY?

Looking at vhost_net_ioctl() in drivers/vhost/net.c, when handling the array
features and zeroing the trailing space, it appears to start at argp:

        /* Zero the trailing space provided by user-space, if any */
        if (clear_user(argp, size_mul(count - copied, sizeof(u64))))
                return -EFAULT;

Because argp is not advanced by copied * sizeof(u64), clear_user() zeroes out
the newly copied features at the beginning of the array instead of the tail.

Since the kernel implementation leaves the actual trailing space uninitialized,
will this cause the test introduced here to always crash via the assertion?

> +
> +	printf("GET_FEATURES_ARRAY: 0x%llx 0x%llx (tail zeroed) OK\n",
> +	       (unsigned long long)clean->features[0],
> +	       (unsigned long long)clean->features[1]);
> +
> +	free(clean);
> +	free(dirty);
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260804080125.79403-1-r4o5m6e8o@163.com?part=3

  reply	other threads:[~2026-08-05  8:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-08-06  6:48       ` rom.wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260805080207.E3EF61F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=r4o5m6e8o@163.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox