From: Jeff Barnes <jeffbarnes@linux.microsoft.com>
To: Alex Williamson <alex@shazbot.org>
Cc: kvm@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] vfio/container: hold group_lock across backend ioctl passthrough
Date: Mon, 23 Nov 2026 16:10:25 -0500 [thread overview]
Message-ID: <20261123211025.485602-1-jeffbarnes@linux.microsoft.com> (raw)
vfio_fops_unl_ioctl() forwards unrecognized ioctls to the IOMMU backend
by reading container->iommu_driver and container->iommu_data and calling
driver->ops->ioctl() without holding container->group_lock.
When the last group is detached, vfio_group_detach_container() takes
group_lock for write, releases the backend and clears both pointers.
An ioctl running concurrently on the container fd can therefore use
backend state that is being torn down. With the Type1 backend, a
VFIO_IOMMU_GET_INFO racing with the last group detach walks iommu->
iova_list while vfio_iommu_type1_release() frees it, and faults on a
poisoned list pointer (dead000000000100).
The other container entry points that use the backend, namely
VFIO_CHECK_EXTENSION and VFIO_SET_IOMMU, already take group_lock.
Do the same for the passthrough path and hold it for read across the
backend call. This is consistent with the existing lock order, as
backends only take their own locks (e.g. iommu->lock) below group_lock.
This patch was developed with the assistance of GitHub Copilot CLI
(Claude Sonnet 5.5), which helped analyze the race, draft the fix and
this description, and build-check the result. The author reviewed the
change and tested it on a downstream 6.6 kernel.
Fixes: cba3345cc494 ("vfio: VFIO core")
Cc: stable@vger.kernel.org
Signed-off-by: Jeff Barnes <jeffbarnes@linux.microsoft.com>
---
drivers/vfio/container.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/vfio/container.c b/drivers/vfio/container.c
index 003281dbf8bc..38ef3b3dd0de 100644
--- a/drivers/vfio/container.c
+++ b/drivers/vfio/container.c
@@ -346,11 +346,14 @@ static long vfio_fops_unl_ioctl(struct file *filep,
ret = vfio_ioctl_set_iommu(container, arg);
break;
default:
+ /* Keep the backend alive until the ioctl completes. */
+ down_read(&container->group_lock);
driver = container->iommu_driver;
data = container->iommu_data;
if (driver) /* passthrough all unrecognized ioctls */
ret = driver->ops->ioctl(data, cmd, arg);
+ up_read(&container->group_lock);
}
return ret;
--
2.43.0
reply other threads:[~2026-11-23 21:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261123211025.485602-1-jeffbarnes@linux.microsoft.com \
--to=jeffbarnes@linux.microsoft.com \
--cc=alex@shazbot.org \
--cc=kvm@vger.kernel.org \
--cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox