From: Nicolin Chen <nicolinc@nvidia.com>
To: <joro@8bytes.org>, Lu Baolu <baolu.lu@linux.intel.com>,
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>,
Yi Liu <yi.l.liu@intel.com>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH v1 4/4] iommu: Unpublish the old attach handle before the PASID replace callback
Date: Tue, 29 Sep 2026 14:51:54 -0700 [thread overview]
Message-ID: <af5be72574fff8c81c2c199886fc67b688ccc3ba.1790718296.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1790718296.git.nicolinc@nvidia.com>
Similar to iommu_replace_group_handle(), iommu_replace_device_pasid() has
the same inert reserve as the group path and the UAF window:
core, holding group->mutex fault path, no group->mutex
========================== ===========================
xa_cmpxchg() ,-- old handle stays published
no-op, the slot is occupied |
__iommu_set_group_pasid() |
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()
Store XA_ZERO_ENTRY outright, just as the group path now does.
Fixes: 8a9e1e773f60 ("iommu: Introduce a replace API for device pasid")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommu.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 52e59f38cec18..2ff81e94a7b7b 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3751,8 +3751,13 @@ int iommu_replace_device_pasid(struct iommu_domain *domain,
}
entry = iommu_make_pasid_array_entry(domain, handle);
- curr = xa_cmpxchg(&group->pasid_array, pasid, NULL,
- XA_ZERO_ENTRY, GFP_KERNEL);
+ /*
+ * iommu_attach_handle_get() runs without the group mutex, so unpublish
+ * the old handle before the driver callback: a fault must not resolve
+ * to either domain while the switch is in progress. This reserves the
+ * slot too, so the store below cannot fail.
+ */
+ curr = xa_store(&group->pasid_array, pasid, XA_ZERO_ENTRY, GFP_KERNEL);
if (xa_is_err(curr)) {
ret = xa_err(curr);
goto out_unlock;
@@ -3776,7 +3781,7 @@ int iommu_replace_device_pasid(struct iommu_domain *domain,
if (curr == entry) {
WARN_ON(1);
ret = -EINVAL;
- goto out_unlock;
+ goto out_store;
}
curr_domain = pasid_array_entry_to_domain(curr);
@@ -3786,16 +3791,16 @@ int iommu_replace_device_pasid(struct iommu_domain *domain,
ret = __iommu_set_group_pasid(domain, group,
pasid, curr_domain);
if (ret)
- goto out_unlock;
+ entry = curr; /* restore the old handle */
}
+out_store:
/*
- * The above xa_cmpxchg() reserved the memory, and the
- * group->mutex is held, this cannot fail.
+ * The xa_store() above reserved the memory, and the group->mutex
+ * is held, this cannot fail.
*/
WARN_ON(xa_is_err(xa_store(&group->pasid_array,
pasid, entry, GFP_KERNEL)));
-
out_unlock:
mutex_unlock(&group->mutex);
return ret;
--
2.43.0
next prev parent reply other threads:[~2026-09-29 21:52 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
2026-11-02 5:54 ` Nicolin Chen
2026-11-02 6:05 ` Baolu Lu
2026-09-29 21:51 ` Nicolin Chen [this message]
2026-10-29 7:26 ` [PATCH v1 4/4] iommu: Unpublish the old attach handle before the PASID " 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=af5be72574fff8c81c2c199886fc67b688ccc3ba.1790718296.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.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=robin.murphy@arm.com \
--cc=will@kernel.org \
--cc=yi.l.liu@intel.com \
/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
all inboxes | Powered by JetHome®