Forwarded: [PATCH] iommu: Fix dev_iommu leak on mock fwspec initialization failure
From: syzbot
Date: Sat Nov 07 2026 - 01:21:46 EST
For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.
***
Subject: [PATCH] iommu: Fix dev_iommu leak on mock fwspec initialization failure
Author: diasyzhangqing@xxxxxxxxx
From: Qing Zhang <diasyzhangqing@xxxxxxxxx>
If iommu_fwspec_init() fails to allocate the fwspec after allocating
dev->iommu, iommu_mock_device_add() returns without freeing dev->iommu.
The mock device was never registered, so the normal IOMMU cleanup path
does not run, and releasing the mock device leaves dev_iommu leaked.
Clean up in iommu_mock_device_add() while holding iommu_probe_device_lock.
Only free dev->iommu if this call allocated it, preserving any pre-existing
object. Check for NULL since initialization can fail before allocation.
Fixes: 2a918911ed3d ("iommufd: Register iommufd mock devices with fwspec")
Reported-by: syzbot+fe84fc6a684e0beb86e2@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=fe84fc6a684e0beb86e2
Suggested-by: Robin Murphy <robin.murphy@xxxxxxx>
Signed-off-by: Qing Zhang <diasyzhang@xxxxxxxxxxx>
---
This was previously sent on Nov 3 through syzbot's forwarding to this
thread, after the direct submission to the list bounced. Resending.
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
drivers/iommu/iommu.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index b486b8bbd1fc..207241a553b9 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -379,10 +379,14 @@ EXPORT_SYMBOL_GPL(iommu_device_register_bus);
int iommu_mock_device_add(struct device *dev, struct iommu_device *iommu)
{
+ bool dev_iommu_present;
int rc;
mutex_lock(&iommu_probe_device_lock);
+ dev_iommu_present = dev->iommu;
rc = iommu_fwspec_init(dev, iommu->fwnode);
+ if (rc && !dev_iommu_present && dev->iommu)
+ dev_iommu_free(dev);
mutex_unlock(&iommu_probe_device_lock);
if (rc)
--
2.43.7