From: sashiko-bot@kernel.org
To: "Jia Jia" <physicalmtea@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v4 1/3] vhost: add helper to clear device IOTLB
Date: Sat, 15 Aug 2026 07:29:34 +0000 [thread overview]
Message-ID: <20260815072935.410ED1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260814072903.124991-2-physicalmtea@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Setting `d->iotlb = NULL` before acquiring `vq->mutex` in `vhost_clear_device_iotlb` creates a race condition with active vhost worker threads. This exposes the host kernel to a NULL pointer dereference or an IOMMU bypass (TOCTOU vulnerability) leading to arbitrary host memory corruption.
--
--- Patch [1]: [PATCH v4 1/3] vhost: add helper to clear device IOTLB ---
commit 721258d5c0d5f3c1aeaefcc8dc997b5bbedcd9c1
Author: Jia Jia <physicalmtea@gmail.com>
vhost: add helper to clear device IOTLB
This patch adds a common helper for tearing down the device IOTLB shared
by vhost backends. It drops each virtqueue's IOTLB pointer and metadata
cache before freeing the old table.
> diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
> index a0c1d54019aac..0861406f3246f 100644
> --- a/drivers/vhost/vhost.c
> +++ b/drivers/vhost/vhost.c
[ ... ]
> @@ -2298,6 +2298,30 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg
> }
> EXPORT_SYMBOL_GPL(vhost_vring_ioctl);
>
> +/* Caller must hold the device mutex. */
> +void vhost_clear_device_iotlb(struct vhost_dev *d)
> +{
> + struct vhost_iotlb *iotlb;
> + int i;
> +
> + iotlb = d->iotlb;
> + d->iotlb = NULL;
> +
> + for (i = 0; i < d->nvqs; ++i) {
[Severity: High]
Does setting d->iotlb = NULL before acquiring vq->mutex create a race
condition with active vhost worker threads?
If a worker thread is concurrently executing vhost_copy_to_user() while
holding vq->mutex, it could call translate_desc(), which locklessly
reads dev->iotlb:
struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem;
Since d->iotlb was already set to NULL by vhost_clear_device_iotlb(),
the worker thread might mistakenly fall back to a potentially NULL
dev->umem.
This could bypass the IOTLB translation and expose the host to memory
corruption via forged GIOVAs or result in a NULL pointer dereference.
> + struct vhost_virtqueue *vq = d->vqs[i];
> +
> + mutex_lock(&vq->mutex);
> + vq->iotlb = NULL;
> + __vhost_vq_meta_reset(vq);
> + mutex_unlock(&vq->mutex);
> + }
> +
> + vhost_clear_msg(d);
> + vhost_iotlb_free(iotlb);
> + wake_up_interruptible_poll(&d->wait, EPOLLIN | EPOLLRDNORM);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260814072903.124991-1-physicalmtea@gmail.com?part=1
next prev parent reply other threads:[~2026-08-15 7:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 7:29 [PATCH v4 0/3] vhost/vsock: fix device IOTLB feature lifecycle Jia Jia
2026-08-14 7:29 ` [PATCH v4 1/3] vhost: add helper to clear device IOTLB Jia Jia
2026-08-14 7:58 ` Stefano Garzarella
2026-08-15 7:29 ` sashiko-bot [this message]
2026-08-14 7:29 ` [PATCH v4 2/3] vhost/vsock: discard IOTLB when ACCESS_PLATFORM is cleared Jia Jia
2026-08-14 7:58 ` Stefano Garzarella
2026-08-15 7:29 ` sashiko-bot
2026-08-14 7:29 ` [PATCH v4 3/3] vhost/vsock: keep IOTLB across feature updates Jia Jia
2026-08-14 8:02 ` Stefano Garzarella
2026-08-14 11:56 ` Jia Jia
2026-08-15 7:29 ` sashiko-bot
2026-08-14 7:52 ` [PATCH v4 0/3] vhost/vsock: fix device IOTLB feature lifecycle Stefano Garzarella
2026-08-14 11:56 ` Jia Jia
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=20260815072935.410ED1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=physicalmtea@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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.