Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yu Zhang" <yuz08559@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] vhost-vdpa: drop the parent's vq callback before the call fd is released
Date: Fri, 07 Aug 2026 15:04:04 +0000	[thread overview]
Message-ID: <20260807150405.53F5B1F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260806150323.2154-1-yuz08559@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Torn read causing NULL pointer dereference and incomplete UAF fix for hardware VDPA drivers.
--

--- Patch [1]: [PATCH] vhost-vdpa: drop the parent's vq callback before the call fd is released ---
commit 59fc02f21fdc99bd2ce2389a383eab4badff2c47
Author: Yu Zhang <yuz08559@gmail.com>

vhost-vdpa: drop the parent's vq callback before the call fd is released

This commit clears the vdpa callback pointers before vhost_vring_ioctl()
releases the eventfd to prevent a use-after-free regression with VDUSE. It
aims to ensure the parent driver drops references to the callback context
before it is destroyed.

> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index c3d913bd7cac7..63ffa94bb4793 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -721,13 +721,34 @@ static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
>  			if (ops->get_status(vdpa) &
>  			    VIRTIO_CONFIG_S_DRIVER_OK)
>  				vhost_vdpa_unsetup_vq_irq(v, idx);
> +			/*
> +			 * The parent caches call_ctx.ctx in cb.trigger without
> +			 * holding a reference, so it has to stop using it
> +			 * before vhost_vring_ioctl() drops the last one.
> +			 */
> +			cb.callback = NULL;
> +			cb.private = NULL;
> +			cb.trigger = NULL;
> +			ops->set_vq_cb(vdpa, idx, &cb);

[Severity: Critical]
Can this non-atomic update cause a NULL pointer dereference for hardware
drivers?

For hardware drivers like vp_vdpa, the interrupt handler reads the callback
struct without locks. If a concurrent interrupt occurs during ops->set_vq_cb(),
could it read a torn state where it sees the old valid cb.callback but the
new NULL cb.private?

drivers/vdpa/virtio_pci/vp_vdpa.c:vp_vdpa_vq_handler() {
    ...
	if (vring->cb.callback)
		return vring->cb.callback(vring->cb.private);
    ...
}

If this happens, it would call vhost_vdpa_virtqueue_cb() with a NULL pointer,
causing a panic when attempting to dereference it.

Additionally, since there is no synchronize_irq() here, could an
already-executing hardware interrupt handler still race with the subsequent
vhost_vring_ioctl() freeing the eventfd, leaving the original use-after-free
unfixed for hardware drivers?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806150323.2154-1-yuz08559@gmail.com?part=1

      reply	other threads:[~2026-08-07 15:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 15:03 [PATCH] vhost-vdpa: drop the parent's vq callback before the call fd is released Yu Zhang
2026-08-07 15:04 ` 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=20260807150405.53F5B1F00A3E@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