Commit c4eff06f authored by Fenghua Yu's avatar Fenghua Yu Committed by Jason Zeng
Browse files

mm: Fix PASID use-after-free issue

mainline inclusion
from mainline-v5.18
commit 2667ed10
category: bugfix
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I67QJ2


CVE: NA

Intel-SIG: commit 2667ed10 ("mm: Fix PASID use-after-free issue")

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

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: 701fac40 ("iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit")
Reported-by: default avatarZhangfei Gao <zhangfei.gao@foxmail.com>
Suggested-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
Suggested-by: default avatarJacob Pan <jacob.jun.pan@linux.intel.com>
Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarZhangfei Gao <zhangfei.gao@foxmail.com>
Reviewed-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
Link: https://lore.kernel.org/r/20220428180041.806809-1-fenghua.yu@intel.com


Signed-off-by: default avatarJason Zeng <jason.zeng@intel.com>
parent 28cb7442
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment