Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/2] Fix UAF on dma-buf import attach failure
@ 2026-07-08  9:15 Nitin Gote
  2026-07-08  8:46 ` ✓ CI.KUnit: success for " Patchwork
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Nitin Gote @ 2026-07-08  9:15 UTC (permalink / raw)
  To: intel-xe; +Cc: Nitin Gote

This series fixes a use-after-free that can happen when importing a
dma-buf and dma_buf_dynamic_attach() fails.

The imported BO is created as ttm_bo_type_sg with bo->base.resv pointing
at the exporter's dma_buf->resv before the attach is attempted. If the
attach fails, the importer holds no attachment and no dma-buf reference,
yet the BO still points at the exporter's resv. Once the exporter is
freed, a later dma_resv_lock(bo->base.resv) can hit freed memory:

  Oops: general protection fault, probably for non-canonical address
        0x6b6b6b6b6b6b6b9c
  Workqueue: ttm ttm_bo_delayed_delete [ttm]
  RIP: 0010:mutex_can_spin_on_owner+0x3f/0xc0

There are two places where the stale resv can be reached:

Patch 1 fixes the TTM delayed-delete path. Failed sg imports now
individualize bo->base.resv to the private _resv, keyed on
import_attach, while successful imports keep the shared exporter resv for
normal dma-buf cleanup.

Patch 2 fixes the xe LRU-walker path raised during review. xe was
creating imported sg BOs with a ttm_resource before attach succeeded,
making them visible to LRU walkers. An LRU walker could then take a BO
reference and lock bo->base.resv before the TTM release path could
individualize it. xe now creates imported sg BOs with empty initial
placement, keeping bo->resource NULL and off the LRU until after a
successful attach.

v5:
 - Add drm/xe patch to keep imported sg BOs off the LRU before attach
   succeeds; the TTM fix alone is not sufficient for xe if the BO is
   already LRU-visible. (Thomas)
   v4 patch:
   https://patchwork.freedesktop.org/patch/736663/?series=169129&rev=2
  - Patch 1 (drm/ttm) carries Christian's Reviewed-by from v4.

v4:
 - Moved import_attach check to after dma_resv_copy_fences() so fences
   are copied before returning for successful imports (Thomas).
 - Removed exporter-alive claim from commit message (Thomas).

v3:
 - Dropped the xe-side reordering approach since importer_priv must be
   valid when dma_buf_dynamic_attach() publishes the attachment.
 - Per Christian's suggestion on the v1 thread, keyed the check on
   import_attach rather than removing the sg guard entirely.
 - Fixes both xe and amdgpu in a single TTM patch.

Nitin Gote (2):
  drm/ttm: Fix UAF on dma-buf attach failure for sg BOs
  drm/xe: Keep imported sg BOs off LRU until dma-buf attach succeeds

 drivers/gpu/drm/ttm/ttm_bo.c | 24 ++++++++++------
 drivers/gpu/drm/xe/xe_bo.c   | 53 ++++++++++++++++++++++++++----------
 2 files changed, 54 insertions(+), 23 deletions(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-07-10  8:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08  9:15 [PATCH v5 0/2] Fix UAF on dma-buf import attach failure Nitin Gote
2026-07-08  8:46 ` ✓ CI.KUnit: success for " Patchwork
2026-07-08  9:15 ` [PATCH v5 1/2] drm/ttm: Fix UAF on dma-buf attach failure for sg BOs Nitin Gote
2026-07-08 12:37   ` Thomas Hellström
2026-07-09 10:13     ` Gote, Nitin R
2026-07-08  9:15 ` [PATCH v5 2/2] drm/xe: Keep imported sg BOs off LRU until dma-buf attach succeeds Nitin Gote
2026-07-08 12:52   ` Thomas Hellström
2026-07-09 10:14     ` Gote, Nitin R
2026-07-08  9:22 ` ✓ Xe.CI.BAT: success for Fix UAF on dma-buf import attach failure Patchwork
2026-07-08 10:53 ` ✓ Xe.CI.FULL: " Patchwork
2026-07-10  8:00 ` [PATCH v5 0/2] " Gote, Nitin R

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox