* [PATCH] vfio: cdev: Reject duplicate bind before updating KVM file
@ 2026-10-01 9:31 Aneesh Kumar K.V (Arm)
0 siblings, 0 replies; only message in thread
From: Aneesh Kumar K.V (Arm) @ 2026-10-01 9:31 UTC (permalink / raw)
To: kvm, linux-kernel; +Cc: Aneesh Kumar K.V (Arm), Alex Williamson
The cdev path only supports one bound/open device fd, but
VFIO_DEVICE_BIND_IOMMUFD only checked the per-file access_granted flag
before capturing the KVM file reference. A second fd for the same device
could therefore replace device->kvm, fail later in vfio_df_open()
because open_count is already nonzero, and then clear the active KVM
association during error cleanup.
Reject the bind while holding dev_set->lock if the device is already
open, matching the existing cdev single-open rule before touching the
device-wide KVM state.
Cc: Alex Williamson <alex@shazbot.org>
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
drivers/vfio/device_cdev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/vfio/device_cdev.c b/drivers/vfio/device_cdev.c
index 1d9515c967b0..ab46563604ac 100644
--- a/drivers/vfio/device_cdev.c
+++ b/drivers/vfio/device_cdev.c
@@ -124,8 +124,8 @@ long vfio_df_ioctl_bind_iommufd(struct vfio_device_file *df,
return ret;
mutex_lock(&device->dev_set->lock);
- /* one device cannot be bound twice */
- if (df->access_granted) {
+ /* The cdev path only supports one bound/open device fd. */
+ if (df->access_granted || device->open_count) {
ret = -EINVAL;
goto out_unlock;
}
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-01 9:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-01 9:31 [PATCH] vfio: cdev: Reject duplicate bind before updating KVM file Aneesh Kumar K.V (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®