[Devel] [PATCH hci-8.1 v2 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Sun Nov 15 13:35:20 MSK 2026


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 at 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



More information about the Devel mailing list