From: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
To: andrey.zhadchenko@virtuozzo.com
Cc: devel@openvz.org
Subject: [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 11:28:10 +0100 [thread overview]
Message-ID: <20261115102811.2745757-2-alexander.ivanov@virtuozzo.com> (raw)
In-Reply-To: <20261115102811.2745757-1-alexander.ivanov@virtuozzo.com>
vhost_set_workers() and vhost_propagate_workers() store workers into
vq->worker directly, bypassing __vhost_vq_attach_worker(). The workers
they install keep attachment_cnt at 0, and the default worker keeps
counting every vq. VHOST_FREE_WORKER then destroys a worker a virtqueue
still points at, and the next vhost_vq_work_queue() on that vq is a
use-after-free. VHOST_ATTACH_VRING_WORKER on such a vq drives
attachment_cnt of its worker to -1. vhost-scsi already exposes both
interfaces to the device owner.
Attach the workers with __vhost_vq_attach_worker(), so VHOST_FREE_WORKER
fails with -EBUSY while a vq uses the worker and both interfaces can
coexist until userspace moves to the worker ioctls. Userspace issues
VHOST_SET_NWORKERS before VHOST_SET_VRING_KICK, so the attach takes the
path without synchronize_rcu() and VM startup is not slowed down.
https://virtuozzo.atlassian.net/browse/VSTOR-107537
Feature: vhost-blk: in-kernel accelerator for virtio-blk guests
Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
drivers/vhost/vhost.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
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);
if (++j >= nworkers)
j = 0;
}
@@ -1117,7 +1121,7 @@ static int vhost_set_workers(struct vhost_dev *dev, int n)
ret = -ENOMEM;
break;
}
- dev->vqs[i]->worker = worker;
+ __vhost_vq_attach_worker(dev->vqs[i], worker);
}
vhost_propagate_workers(dev, i);
--
2.53.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-15 10:30 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 ` Alexander Ivanov [this message]
2026-11-15 10:35 ` [Devel] [PATCH hci-8.1 v2 1/2] drivers/vhost: fix a use-after-free of VHOST_SET_NWORKERS workers no-reply
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=20261115102811.2745757-2-alexander.ivanov@virtuozzo.com \
--to=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.