Fix UAF on dma-buf import attach failure
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest2 patches 5 repliesIn review
- v11 patch 5 repliesSuperseded
Changes in v5 from the cover letter
- 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)
Patches in v5 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | drm/ttm: Fix UAF on dma-buf attach failure for sg BOsdrivers/ | +15 | 2 replies | |
| 2/2 | drm/xe: Keep imported sg BOs off LRU until dma-buf attach succeedsdrivers/ | +39 | 2 replies |
Reviews trailers per patch
1 of 2 patches has a Reviewed-by or Acked-by.
| Patch | Christian König |
|---|---|
| 1/2 | R-b |
| 2/2 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v5 0/2] Fix UAF on dma-buf import attach failure
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/0xc0There 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(-)
Signature · 1 line
2.50.1