[PATCH 3.18 33/36] iommu/amd: Fix incorrect error handling in amd_iommu_bind_pasid()

From: Greg Kroah-Hartman
Date: Mon Jul 03 2017 - 09:36:45 EST


3.18-stable review patch. If anyone has any objections, please let me know.

------------------

From: Pan Bian <bianpan2016@xxxxxxx>

commit 73dbd4a4230216b6a5540a362edceae0c9b4876b upstream.

In function amd_iommu_bind_pasid(), the control flow jumps
to label out_free when pasid_state->mm and mm is NULL. And
mmput(mm) is called. In function mmput(mm), mm is
referenced without validation. This will result in a NULL
dereference bug. This patch fixes the bug.

Signed-off-by: Pan Bian <bianpan2016@xxxxxxx>
Fixes: f0aac63b873b ('iommu/amd: Don't hold a reference to mm_struct')
Signed-off-by: Joerg Roedel <jroedel@xxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
drivers/iommu/amd_iommu_v2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/iommu/amd_iommu_v2.c
+++ b/drivers/iommu/amd_iommu_v2.c
@@ -701,9 +701,9 @@ out_clear_state:

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

out_free:
- mmput(mm);
free_pasid_state(pasid_state);

out: