From: Yi Liu <yi.l.liu@intel.com>
To: Baolu Lu <baolu.lu@linux.intel.com>,
Nicolin Chen <nicolinc@nvidia.com>, <joro@8bytes.org>,
Jason Gunthorpe <jgg@nvidia.com>
Cc: Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
"Kevin Tian" <kevin.tian@intel.com>,
Jean-Philippe Brucker <jpb@kernel.org>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1 3/4] iommu: Unpublish the old attach handle before the group replace callback
Date: Mon, 2 Nov 2026 11:30:02 +0800 [thread overview]
Message-ID: <5512edd1-3c52-4e8a-a38f-3a5f1457cdaf@intel.com> (raw)
In-Reply-To: <5751040a-e180-4d29-851d-3ccab96878a3@linux.intel.com>
On 11/1/26 13:53, Baolu Lu wrote:
> On 9/30/2026 5:51 AM, Nicolin Chen wrote:
>> iommu_replace_group_handle() looks like it hides the detaching handle
>> ahead
>> of the driver callback. But in fact, xa_reserve() calls xa_cmpxchg(),
>> which
>> stores only when the current entry matches @old=NULL. For a replace,
>> there
>> must be an entry sitting there by definition (i.e. @old cannot be
>> NULL), so
>> the compare fails, XA_ZERO_ENTRY is never written, and the call decays
>> into
>> a plain read.
>>
>> Therefore, the old handle stays published during
>> __iommu_group_set_domain()
>> and only gets replaced after the call. This creates a window, during
>> which
>> an asynchronous fault path might hit UAF:
>>
>> core, holding group->mutex fault path, no group->mutex
>> ========================== ===========================
>>
>> xa_reserve() ,-- old handle stays published
>> no-op, the slot is occupied |
>> __iommu_group_set_domain() |
>> driver attach/detach ops |
>> iopf_queue_flush_dev() |
>> | iommu_attach_handle_get()
>> | reads old_handle
>> xa_store(new entry) `-- window closes
>> mutex_unlock()
>> kfree(old_handle) [caller]
>> UAF: old_handle->domain-
>> >iopf_handler()
>>
>> Replace the xa_reserve() with xa_store(XA_ZERO_ENTRY) to unpublish the
>> old
>> handle.
>>
>> Fixes: 8519e689834a ("iommu: Extend domain attach group with handle
>> support")
>> Cc:stable@vger.kernel.org
>> Assisted-by: LLM
>> Signed-off-by: Nicolin Chen<nicolinc@nvidia.com>
>> ---
>> drivers/iommu/iommu.c | 23 +++++++++++++----------
>> 1 file changed, 13 insertions(+), 10 deletions(-)
>
> This doesn't fix the same-domain replace issue, which can still result
> in a use-after-free bug. I agree that this needs a separate lifetime
> mechanism as stated in the cover letter. But is it possible to prevent
> the same-domain replace case from going through this interface?
fwiw, iommufd already guards this at the device-replace layer
(iommufd_device_do_replace() short-circuits when hwpt == old_hwpt) [1],
so IOMMUFD callers can't currently trigger this. But that's a
caller-side convention, not something
iommu_replace_group_handle()/iommu_replace_device_pasid() enforce
themselves - so it's still
reachable if a future/other caller doesn't do the same check. Worth
deciding whether to push the guard down into the core API, or document
it as a caller contract.
[1]
https://github.com/torvalds/linux/blob/6628e7d4c6b25c8d18f1345e3a20d21829aae7e4/drivers/iommu/iommufd/device.c#L888
Regards,
Yi Liu
next prev parent reply other threads:[~2026-11-02 3:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 21:51 [PATCH v1 0/4] iommu: Fix attach handle publication ordering Nicolin Chen
2026-09-29 21:51 ` [PATCH v1 1/4] iommu: Unpublish the attach handle before the group detach callback Nicolin Chen
2026-10-29 7:18 ` Tian, Kevin
2026-11-01 2:01 ` Baolu Lu
2026-09-29 21:51 ` [PATCH v1 2/4] iommu: Unpublish the attach handle before the PASID " Nicolin Chen
2026-10-29 7:18 ` Tian, Kevin
2026-11-01 2:13 ` Baolu Lu
2026-09-29 21:51 ` [PATCH v1 3/4] iommu: Unpublish the old attach handle before the group replace callback Nicolin Chen
2026-10-29 7:25 ` Tian, Kevin
2026-10-29 11:00 ` Yi Liu
2026-10-29 18:45 ` Jason Gunthorpe
2026-10-30 8:03 ` Tian, Kevin
2026-10-30 8:22 ` Yi Liu
2026-10-30 15:21 ` Jason Gunthorpe
2026-11-01 5:53 ` Baolu Lu
2026-11-02 3:30 ` Yi Liu [this message]
2026-11-02 5:54 ` Nicolin Chen
2026-11-02 6:05 ` Baolu Lu
2026-09-29 21:51 ` [PATCH v1 4/4] iommu: Unpublish the old attach handle before the PASID " Nicolin Chen
2026-10-29 7:26 ` Tian, Kevin
2026-11-01 5:54 ` Baolu Lu
2026-10-28 18:58 ` [PATCH v1 0/4] iommu: Fix attach handle publication ordering Nicolin Chen
2026-10-29 11:00 ` Yi Liu
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=5512edd1-3c52-4e8a-a38f-3a5f1457cdaf@intel.com \
--to=yi.l.liu@intel.com \
--cc=baolu.lu@linux.intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=will@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 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.