[PATCH v2 5.10] iommu/amd: Check return value of mmu_notifier_register()

From: Denis Arefev

Date: Thu Nov 26 2026 - 06:49:07 EST


From: Denis Arefev <arefev@xxxxxxxxx>

commit b09b56734fae28be9332021ae3e84c9b05020fda upstream.

Added a return value check for the function
mmu_notifier_register().

Return value of a function 'mmu_notifier_register'
called at iommu_v2.c:642 is not checked,
but it is usually checked for this function

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Denis Arefev <arefev@xxxxxxxxx>
Link: https://lore.kernel.org/r/20221118104252.122809-1-arefev@xxxxxxxxx
[joro: Fix commit message ]
Signed-off-by: Joerg Roedel <jroedel@xxxxxxx>
Signed-off-by: Denis Arefev <arefev@xxxxxxxxx>
---
Changes in v2:
- Drop the mm reference taken by get_task_mm() when
mmu_notifier_register() fails (mm_struct refcount leak).
v1: https://lore.kernel.org/all/20261125084142.30679-1-arefev@xxxxxxxxx/

drivers/iommu/amd/iommu_v2.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c
index 16776e3c6eab..37b757e91198 100644
--- a/drivers/iommu/amd/iommu_v2.c
+++ b/drivers/iommu/amd/iommu_v2.c
@@ -640,7 +640,9 @@ int amd_iommu_bind_pasid(struct pci_dev *pdev, u32 pasid,
if (pasid_state->mm == NULL)
goto out_free;

- mmu_notifier_register(&pasid_state->mn, mm);
+ ret = mmu_notifier_register(&pasid_state->mn, mm);
+ if (ret)
+ goto out_mm;

ret = set_pasid_state(dev_state, pasid_state, pasid);
if (ret)
@@ -668,6 +670,8 @@ int amd_iommu_bind_pasid(struct pci_dev *pdev, u32 pasid,

out_unregister:
mmu_notifier_unregister(&pasid_state->mn, mm);
+
+out_mm:
mmput(mm);

out_free:
--
2.43.0