Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nitin Gote <nitin.r.gote@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: Nitin Gote <nitin.r.gote@intel.com>
Subject: [PATCH v5 0/2] Fix UAF on dma-buf import attach failure
Date: Wed,  8 Jul 2026 14:45:06 +0530	[thread overview]
Message-ID: <20260708091512.205482-4-nitin.r.gote@intel.com> (raw)

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


             reply	other threads:[~2026-07-08  8:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  9:15 Nitin Gote [this message]
2026-07-08  8:46 ` ✓ CI.KUnit: success for Fix UAF on dma-buf import attach failure 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260708091512.205482-4-nitin.r.gote@intel.com \
    --to=nitin.r.gote@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox