In iommu_mock_device_add(), iommu_fwspec_init() allocates dev->iommu via dev_iommu_get(). If an error occurs before device_add() is invoked, the function returns early without freeing dev->iommu. Because device_add() was never called on the mock device, subsequent cleanup via put_device() does not trigger bus release notifications, and dev->iommu is permanently leaked: dev_iommu_get drivers/iommu/iommu.c:408 [inline] iommu_fwspec_init+0xe2/0x1e0 drivers/iommu/iommu.c:3086 iommu_mock_device_add+0x31/0x110 drivers/iommu/iommu.c:385 Fix this by jumping to the error cleanup path on failure in iommu_mock_device_add(), ensuring dev_iommu_free() is called if dev->iommu is set. Fixes: 2a918911ed3d ("iommufd: Register iommufd mock devices with fwspec") Assisted-by: Gemini:gemini-4-argon Gemini:gemini-3.8-flash syzbot Reported-by: syzbot+fe84fc6a684e0beb86e2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=fe84fc6a684e0beb86e2 Link: https://syzkaller.appspot.com/ai_job?id=6848de3a-be64-4f80-b509-bec63672a688 To: To: "Joerg Roedel (AMD)" To: "Will Deacon" To: "Guixin Liu" Cc: Cc: "Robin Murphy" --- v2: - Free dev->iommu on early error in iommu_mock_device_add() instead of modifying iommu_fwspec_init() - Update the commit message to explain the leak on early return and trim the kmemleak report v1: https://lore.kernel.org/all/57f56c9f-1822-4606-98fd-ebb96dbf8de8@mail.kernel.org/T/ --- diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index b486b8bbd..47b684497 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -386,10 +386,16 @@ int iommu_mock_device_add(struct device *dev, struct iommu_device *iommu) mutex_unlock(&iommu_probe_device_lock); if (rc) - return rc; + goto err_free; rc = device_add(dev); if (rc) + goto err_free; + + return 0; + +err_free: + if (dev->iommu) dev_iommu_free(dev); return rc; } base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 -- This is an AI-generated patch subject to moderation. Reply with '#syz upstream' to Sign-off the patch as a human author and send it to the upstream kernel mailing lists. Reply with '#syz reject' to reject it ('#syz unreject' to undo). See https://goo.gle/syzbot-ai-patches for information about AI-generated patches. You can comment on the patch as usual, syzbot will try to address the comments and send a new version of the patch if necessary. syzbot engineers can be reached at syzkaller@googlegroups.com.