Forwarded: [PATCH] iommu: Fix dev_iommu leak on mock fwspec initialization failure

From: syzbot

Date: Tue Nov 03 2026 - 04:30:11 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

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>
---
I reproduced the same leak from the syzbot report. This fixes the mock
device path as Robin requested in response to Tal's patch [1].

[1] https://lore.kernel.org/all/7e209fb2-4bda-4207-9109-c67c8df41e05@xxxxxxx/

#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