From: sashiko-bot@kernel.org
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 2/5] iommufd/device: Associate KVM file pointer with iommufd_device
Date: Mon, 25 May 2026 20:33:41 +0000 [thread overview]
Message-ID: <20260525203341.9FE971F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260525154816.1029642-3-aneesh.kumar@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Use-After-Free / Lifetime Mismatch due to borrowed KVM file reference
--
commit e5661ddf7c17ac12b18e45c9b4e38b80511ba1c0
Author: Shameer Kolothum <skolothumtho@nvidia.com>
iommufd/device: Associate KVM file pointer with iommufd_device
This commit extends iommufd_device_bind() to accept the device's KVM file
and stores it in the iommufd_device struct. This provides TSM vDevice support
access to the KVM associated with a VFIO device.
> diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
> index 170a7005f0bc8..718abdc0e627a 100644
> --- a/drivers/iommu/iommufd/device.c
> +++ b/drivers/iommu/iommufd/device.c
> @@ -216,7 +217,9 @@ void iommufd_device_destroy(struct iommufd_object *obj)
> * The caller must undo this with iommufd_device_unbind()
> */
> struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx,
> - struct device *dev, u32 *id)
> + struct device *dev,
> + struct file *kvm_file,
> + u32 *id)
> {
> struct iommufd_device *idev;
> struct iommufd_group *igroup;
[ ... ]
> @@ -266,6 +269,8 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx,
> if (!iommufd_selftest_is_mock_dev(dev))
> iommufd_ctx_get(ictx);
> idev->dev = dev;
> + /* reference is already taken in vfio_df_ioctl_bind_iommufd() */
> + idev->kvm_file = kvm_file;
[Severity: Critical]
Does this borrowed reference create a potential use-after-free regression if
the iommufd_device outlives the VFIO device?
If a concurrent ioctl on the iommufd device is maliciously stalled (for
example, using userfaultfd during a copy_to_user in IOMMU_GET_HW_INFO),
iommufd_object_remove() can time out after 60 seconds and return -EBUSY.
This would fail to remove the idev object, leaving it alive in the iommufd
xarray.
VFIO owns the KVM file reference and unconditionally drops it when the VFIO
device file is closed. If VFIO drops this reference while idev remains alive,
the file could be freed, leaving idev->kvm_file as a dangling pointer.
If the stalled ioctl is subsequently allowed to finish, a new
IOMMU_VIOMMU_ALLOC ioctl could look up the leaked idev and attempt to call
get_file(idev->kvm_file), resulting in a use-after-free on the freed struct
file.
Should this function take its own independent reference to kvm_file to
ensure the file remains valid for the entire lifetime of the iommufd_device?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260525154816.1029642-1-aneesh.kumar@kernel.org?part=2
next prev parent reply other threads:[~2026-05-25 20:33 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 15:48 [PATCH v5 0/5] Add iommufd ioctls to support TSM operations Aneesh Kumar K.V (Arm)
2026-05-25 15:48 ` [PATCH v5 1/5] vfio: cache KVM VM file references instead of raw struct kvm pointers Aneesh Kumar K.V (Arm)
2026-05-25 16:47 ` sashiko-bot
2026-05-26 8:11 ` Aneesh Kumar K.V
2026-05-26 10:52 ` Anthony Krowiak
2026-05-25 15:48 ` [PATCH v5 2/5] iommufd/device: Associate KVM file pointer with iommufd_device Aneesh Kumar K.V (Arm)
2026-05-25 20:33 ` sashiko-bot [this message]
2026-05-26 8:17 ` Aneesh Kumar K.V
2026-05-25 15:48 ` [PATCH v5 3/5] iommufd/viommu: Keep a reference to the KVM file Aneesh Kumar K.V (Arm)
2026-05-25 15:48 ` [PATCH v5 4/5] iommufd/tsm: add vdevice TSM bind/unbind ioctl Aneesh Kumar K.V (Arm)
2026-05-25 21:44 ` sashiko-bot
2026-05-25 15:48 ` [PATCH v5 5/5] iommufd/vdevice: add TSM request ioctl Aneesh Kumar K.V (Arm)
2026-05-25 22:18 ` sashiko-bot
2026-05-26 8:18 ` Aneesh Kumar K.V
2026-05-27 0:16 ` Alexey Kardashevskiy
2026-05-27 6:17 ` Dan Williams (nvidia)
2026-05-27 6:56 ` Tian, Kevin
2026-05-27 12:51 ` Jason Gunthorpe
2026-05-27 15:34 ` Aneesh Kumar K.V
2026-05-27 17:49 ` Aneesh Kumar K.V
2026-05-27 22:49 ` Dan Williams (nvidia)
2026-06-02 5:10 ` Aneesh Kumar K.V
2026-06-08 20:58 ` Dan Williams (nvidia)
2026-06-09 8:59 ` Aneesh Kumar K.V
2026-06-09 10:49 ` Alexey Kardashevskiy
2026-06-02 8:40 ` Alexey Kardashevskiy
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=20260525203341.9FE971F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--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.