From: sashiko-bot@kernel.org
To: "Yu Zhang" <yuz08559@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] vhost-vdpa: protect config_ctx from being freed under the config callback
Date: Sat, 08 Aug 2026 10:01:28 +0000 [thread overview]
Message-ID: <20260808100129.52B371F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260807100025.19750-3-yuz08559@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] An identical Use-After-Free pattern to the one fixed for `v->config_ctx` exists unpatched for `vq->call_ctx.ctx` in the virtqueue interrupt path.
--
--- Patch [2]: [PATCH 2/2] vhost-vdpa: protect config_ctx from being freed under the config callback ---
commit 8e0bc317868b822a05e8a68785677223512b3be4
Author: Yu Zhang <yuz08559@gmail.com>
vhost-vdpa: protect config_ctx from being freed under the config callback
This commit fixes a use-after-free by adding a spinlock to serialize accesses
to config_ctx in the config callback against its replacement in the
VHOST_VDPA_SET_CONFIG_CALL ioctl.
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index ae137d5be99c9..cae8089ab3ddf 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -194,10 +196,12 @@ static irqreturn_t vhost_vdpa_virtqueue_cb(void *private)
[Severity: Critical]
This is a pre-existing issue, but does an identical use-after-free pattern
exist for vq->call_ctx.ctx in the virtqueue interrupt path?
It appears vhost_vdpa_virtqueue_cb() reads and signals vq->call_ctx.ctx
locklessly:
drivers/vhost/vdpa.c:vhost_vdpa_virtqueue_cb() {
struct eventfd_ctx *call_ctx = vq->call_ctx.ctx;
if (call_ctx)
eventfd_signal(call_ctx);
}
Could this race with VHOST_SET_VRING_CALL in vhost_vring_ioctl(), which
swaps out vq->call_ctx.ctx and immediately frees the old context?
drivers/vhost/vhost.c:vhost_vring_ioctl() {
swap(ctx, vq->call_ctx.ctx);
...
if (!IS_ERR_OR_NULL(ctx))
eventfd_ctx_put(ctx);
}
If a userspace process with access to /dev/vduse concurrently invokes
VDUSE_VQ_INJECT_IRQ while VHOST_SET_VRING_CALL is executing, could
vduse_vq_signal_irqfd() end up calling eventfd_signal() on freed memory
since it uses the cached vq->cb.trigger?
drivers/vdpa/vdpa_user/vduse_dev.c:vduse_vq_signal_irqfd() {
if (vq->ready && vq->cb.trigger) {
eventfd_signal(vq->cb.trigger);
signal = true;
}
}
> static irqreturn_t vhost_vdpa_config_cb(void *private)
> {
> struct vhost_vdpa *v = private;
> - struct eventfd_ctx *config_ctx = v->config_ctx;
> + unsigned long flags;
>
> - if (config_ctx)
> - eventfd_signal(config_ctx);
> + spin_lock_irqsave(&v->config_lock, flags);
> + if (v->config_ctx)
> + eventfd_signal(v->config_ctx);
> + spin_unlock_irqrestore(&v->config_lock, flags);
>
> return IRQ_HANDLED;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260807100025.19750-1-yuz08559@gmail.com?part=2
prev parent reply other threads:[~2026-08-08 10:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 10:00 [PATCH 0/2] vhost-vdpa: fix a use-after-free on the config eventfd Yu Zhang
2026-08-07 10:00 ` [PATCH 1/2] vhost-vdpa: don't install the eventfd_ctx_fdget() error in config_ctx Yu Zhang
2026-08-08 10:01 ` sashiko-bot
2026-08-07 10:00 ` [PATCH 2/2] vhost-vdpa: protect config_ctx from being freed under the config callback Yu Zhang
2026-08-08 10:01 ` 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=20260808100129.52B371F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=yuz08559@gmail.com \
/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