public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/ttm: Fix bo resource use-after-free
Date: Thu, 05 Mar 2026 13:16:40 +1000	[thread overview]
Message-ID: <review-patch1-20260304-ttm_bo_res_uaf-v1-1-43f20125b67f@igalia.com> (raw)
In-Reply-To: <20260304-ttm_bo_res_uaf-v1-1-43f20125b67f@igalia.com>

Patch Review

**Bug Analysis:** The bug was introduced by commit `c06da4b3573a` which cached `bo->resource` into a local variable `res` at the top of `ttm_bo_swapout_cb()`. The problem is that `ttm_bo_handle_move_mem()` at line 1160 calls into the driver's `move` callback (line 157 of the same file), which replaces `bo->resource` with the new `evict_mem` and frees the old resource. After this call returns, the local `res` variable points to freed memory.

The stale `res` pointer was then used:
1. At the `ttm_resource_del_bulk_move(res, bo)` call
2. At the `ttm_resource_add_bulk_move(res, bo)` call  
3. At the `ttm_resource_move_to_lru_tail(res)` call — which is where the NULL deref in the stack trace occurs

**Fix correctness:** The fix simply removes the local `res` variable and replaces all uses with `bo->resource`, which always points to the current (valid) resource. This is correct because:
- After `ttm_bo_handle_move_mem()` completes successfully, `bo->resource` points to the newly allocated system memory resource
- The bulk_move and lru_tail operations should operate on the current resource, not the old (freed) one

**Minor observations:**

- The `place` initialization `{ .mem_type = bo->resource->mem_type }` at line 1110 is fine — `bo->resource` is valid at function entry and `place` captures the value (not the pointer).
- The fix is appropriately tagged with `Fixes:` and Cc's the relevant maintainers.
- No concerns about the locking — the `spin_lock(&bdev->lru_lock)` sections after the move are operating on the correct (new) resource.

**No issues found.** Clean, minimal, correct fix for a real UAF.

---
Generated by Claude Code Patch Reviewer

      parent reply	other threads:[~2026-03-05  3:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 23:27 [PATCH] drm/ttm: Fix bo resource use-after-free Thadeu Lima de Souza Cascardo
2026-03-05  3:16 ` Claude review: " Claude Code Review Bot
2026-03-05  3:16 ` Claude Code Review Bot [this message]

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=review-patch1-20260304-ttm_bo_res_uaf-v1-1-43f20125b67f@igalia.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /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