OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>,
	andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v2 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers
Date: Sun, 15 Nov 2026 10:35:20 +0000	[thread overview]
Message-ID: <010701a1dec69ac9-bf9daa4a-6cb1-4816-b5e7-cea3599a4584-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261115102811.2745757-2-alexander.ivanov@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] vhost: NULL worker passed to __vhost_vq_attach_worker() in
  vhost_propagate_workers()
- [Low] vhost: missing Fixes: trailer for use-after-free fix of NWORKERS
  workers
--

commit 67a253d12d149aa08cf82eb2515b2911f096d6d2
Author: Alexander Ivanov <alexander.ivanov@virtuozzo.com>

drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers

The commit makes vhost_set_workers() and vhost_propagate_workers() attach workers through __vhost_vq_attach_worker() instead of storing vq->worker directly. This keeps attachment_cnt correct, so VHOST_FREE_WORKER returns -EBUSY while a virtqueue still uses the worker.

> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index 1057ba7e3fc7..5092eed75b8f 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
> @@ -1094,7 +1094,11 @@ static void vhost_propagate_workers(struct vhost_dev *dev, int nworkers)
>  	int i, j = 0;
>  
>  	for (i = nworkers; i < dev->nvqs; i++) {
> -		dev->vqs[i]->worker = dev->vqs[j]->worker;
> +		struct vhost_worker *worker;
> +
> +		worker = rcu_dereference_check(dev->vqs[j]->worker,
> +					       lockdep_is_held(&dev->mutex));
> +		__vhost_vq_attach_worker(dev->vqs[i], worker);

[Severity: Medium]
Can worker be NULL here? __vhost_vq_attach_worker() starts with mutex_lock(&worker->mutex), so a NULL argument is a NULL pointer dereference.

vhost-vdpa calls vhost_dev_init() with use_worker=false, so no default worker is ever attached and every vq->worker stays NULL. VHOST_SET_NWORKERS has no use_worker check, and vhost_set_workers() only attaches new workers to vqs[1..n-1]. vhost_propagate_workers() then reads NULL from vqs[0] and passes it on. Before this patch the NULL was only copied, which was harmless.

A narrower case exists on use_worker devices. A killed worker leaves vq->worker NULL, so a source vq can be NULL at propagate time.

Would returning -EINVAL from vhost_set_workers() when !dev->use_worker, and skipping a NULL source worker here, cover both cases?

[ ... ]

> -		dev->vqs[i]->worker = worker;
> +		__vhost_vq_attach_worker(dev->vqs[i], worker);

[Severity: Low]
This is a bug fix, but the commit message has no Fixes: tag. Should it include:

  Fixes: 705a4b3eefde ("drivers/vhost: add ioctl to increase the number of workers")

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261115102811.2745757-1-alexander.ivanov@virtuozzo.com?part=1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-11-15 10:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 10:28 [Devel] [PATCH hci-8.1 v2 0/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
2026-11-15 10:28 ` [Devel] [PATCH hci-8.1 v2 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers Alexander Ivanov
2026-11-15 10:35   ` no-reply [this message]
2026-11-15 11:39     ` Alexander Ivanov
2026-11-15 10:28 ` [Devel] [PATCH hci-8.1 v2 2/2] drivers/vhost/blk: add support for worker ioctls Alexander Ivanov
2026-11-15 10:35   ` no-reply

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=010701a1dec69ac9-bf9daa4a-6cb1-4816-b5e7-cea3599a4584-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=devel@openvz.org \
    /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