drm/i915/ttm: fix uaf with lmem_userfault_list handling
authorMatthew Auld <matthew.auld@intel.com>
Mon, 7 Nov 2022 16:54:13 +0000 (16:54 +0000)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Mon, 14 Nov 2022 09:46:06 +0000 (09:46 +0000)
commit4f68332b2f89ab84285e5b6cb3d30e8b9894bef1
treef4893849d961c910f27077973b50efe067cdc384
parent094226ad94f471a9f19e8f8e7140a09c2625abaa
drm/i915/ttm: fix uaf with lmem_userfault_list handling

In the fault handler, make sure we check if the BO maps lmem after
we schedule the migration, since the current resource might change from
lmem to smem, if the pages are in the non-cpu visible portion of lmem.
This then leads to adding the object to the lmem_userfault_list even
though the current resource is no longer lmem. If we then destroy the
object, the list might still contain a link to the now free object, since
we only remove it if the object is still in lmem.

Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/7469
Fixes: ad74457a6b5a ("drm/i915/dgfx: Release mmap on rpm suspend")
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Anshuman Gupta <anshuman.gupta@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Andrzej Hajda <andrzej.hajda@intel.com>
Cc: Nirmoy Das <nirmoy.das@intel.com>
Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221107165414.56970-1-matthew.auld@intel.com
(cherry picked from commit 625b74460ec0978979f883fbee117e1b97e6e35e)
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
drivers/gpu/drm/i915/gem/i915_gem_ttm.c