[lkml]   [2022]   [May]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[tip: core/urgent] mm: Fix PASID use-after-free issue
The following commit has been merged into the core/urgent branch of tip:

Commit-ID: 2667ed10d9f01e250ba806276740782c89d77fda
Author: Fenghua Yu <>
AuthorDate: Thu, 28 Apr 2022 11:00:41 -07:00
Committer: Thomas Gleixner <>
CommitterDate: Sun, 01 May 2022 10:17:17 +02:00

mm: Fix PASID use-after-free issue

The PASID is being freed too early. It needs to stay around until after
device drivers that might be using it have had a chance to clear it out
of the hardware.

The relevant refcounts are:

mmget() /mmput() refcount the mm's address space
mmgrab()/mmdrop() refcount the mm itself

The PASID is currently tied to the life of the mm's address space and freed
in __mmput(). This makes logical sense because the PASID can't be used
once the address space is gone.

But, this misses an important point: even after the address space is gone,
the PASID will still be programmed into a device. Device drivers might,
for instance, still need to flush operations that are outstanding and need
to use that PASID. They do this at file->release() time.

Device drivers call the IOMMU driver to hold a reference on the mm itself
and drop it at file->release() time. But, the IOMMU driver holds a
reference on the mm itself, not the address space. The address space (and
the PASID) is long gone by the time the driver tries to clean up. This is
effectively a use-after-free bug on the PASID.

To fix this, move the PASID free operation from __mmput() to __mmdrop().
This ensures that the IOMMU driver's existing mmgrab() keeps the PASID
allocated until it drops its mm reference.

Fixes: 701fac40384f ("iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit")
Reported-by: Zhangfei Gao <>
Suggested-by: Jean-Philippe Brucker <>
Suggested-by: Jacob Pan <>
Signed-off-by: Fenghua Yu <>
Signed-off-by: Thomas Gleixner <>
Tested-by: Zhangfei Gao <>
Reviewed-by: Jean-Philippe Brucker <>
kernel/fork.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index 9796897..35a3bef 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -792,6 +792,7 @@ void __mmdrop(struct mm_struct *mm)
+ mm_pasid_drop(mm);
@@ -1190,7 +1191,6 @@ static inline void __mmput(struct mm_struct *mm)
if (mm->binfmt)
- mm_pasid_drop(mm);

 \ /
  Last update: 2022-05-01 10:26    [W:0.091 / U:0.204 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site