Linux virtualization list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Linfeng Sun" <linfeng.sun.dev@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	virtualization@lists.linux.dev,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v2] vhost-scsi: initialize command pools for late I/O virtqueues
Date: Wed, 16 Sep 2026 08:18:51 +0000	[thread overview]
Message-ID: <20260916081852.223451F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260916-fix-warning-in-sbitmap_get-v2-1-e61a09047089@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] vhost-scsi: double fetch of vq_index in SET_VRING_ADDR
--

commit 9fca211b81e6c842310a6804151d7dcf766af409
Author: Linfeng Sun <linfeng.sun.dev@gmail.com>

vhost-scsi: initialize command pools for late I/O virtqueues

This commit delays the allocation of command pools for skipped I/O
virtqueues during VHOST_SCSI_SET_ENDPOINT. When VHOST_SET_VRING_ADDR
subsequently completes their setup, it allocates the pools and activates
only the newly configured queue.

Link: https://patch.msgid.link/20260908-fix-warning-in-sbitmap_get-v1-1-767c2c211a2b@gmail.com

> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 4f8c0260bc9e7..efca343626664 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c

[ ... ]

> @@ -2464,12 +2503,19 @@ vhost_scsi_ioctl(struct file *f,
>  		mutex_unlock(&vs->dev.mutex);
>  		return r;
>  	default:
> +		if (ioctl == VHOST_SET_VRING_ADDR &&
> +		    get_user(vq_index, (u32 __user *)argp))
> +			return -EFAULT;
> +
>  		mutex_lock(&vs->dev.mutex);
>  		r = vhost_dev_ioctl(&vs->dev, ioctl, argp);
> -		if (r == -ENOIOCTLCMD)
> +		if (r == -ENOIOCTLCMD) {
>  			r = vhost_vring_ioctl(&vs->dev, ioctl, argp);
> -		else
> +			if (!r && ioctl == VHOST_SET_VRING_ADDR)
> +				r = vhost_scsi_activate_vq(vs, vq_index);

[Severity: Medium]
Could this introduce a double fetch vulnerability?

The index is fetched first here in vhost_scsi_ioctl():
    get_user(vq_index, (u32 __user *)argp)

And then later in the call chain it fetches the index again from the
same user pointer:

vhost_vring_ioctl() -> vhost_get_vq_from_user():
    get_user(idx, idxp);

If a malicious userspace thread (such as a VMM) modifies the index in the
payload between these two fetches, could it decouple virtqueue configuration
from activation? This might lead to state confusion where one virtqueue gets
its addresses configured by vhost_vring_set_num_addr(), while a completely
different virtqueue index (vq_index from the first fetch) is unexpectedly
activated by vhost_scsi_activate_vq().

While array_index_nospec() in vhost_scsi_activate_vq() prevents out-of-bounds
accesses, could activating a queue that wasn't actually targeted for address
configuration lead to unintended behavior?

> +		} else {
>  			vhost_scsi_flush(vs);
> +		}
>  		mutex_unlock(&vs->dev.mutex);
>  		return r;
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916-fix-warning-in-sbitmap_get-v2-1-e61a09047089@gmail.com?part=1

      reply	other threads:[~2026-09-16  8:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  8:02 [PATCH v2] vhost-scsi: initialize command pools for late I/O virtqueues Linfeng Sun
2026-09-16  8:18 ` sashiko-bot [this message]

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=20260916081852.223451F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=linfeng.sun.dev@gmail.com \
    --cc=mst@redhat.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@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