From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: gpu/buddy: Fix use-after-free in split_block() call sites
Date: Mon, 25 May 2026 19:06:37 +1000 [thread overview]
Message-ID: <review-patch1-20260522092600.32818-2-francois.dugast@intel.com> (raw)
In-Reply-To: <20260522092600.32818-2-francois.dugast@intel.com>
Patch Review
**Correctness: Good fix, addresses a real bug.**
The existing code at all four `err_undo` paths calls `__gpu_buddy_free(mm, block, false)` without first removing `block` from the rbtree. Since a failed `split_block()` returns before `mark_split()`, the block is still FREE and linked in the tree. `__gpu_buddy_free()` will then try to coalesce with the buddy, calling `gpu_block_free(mm, block)` which frees the block's memory while its `rb` node is still linked. This is confirmed by examining the existing code at `buddy.c:737-741` where the rbtree_remove was missing.
The fix correctly adds `rbtree_remove(mm, block)` before each `__gpu_buddy_free()` call, matching the pattern already used in `__force_merge()` at line 337.
**One observation on the `alloc_from_freetree` error path:**
```c
err_undo:
if (tmp != order) {
rbtree_remove(mm, block);
__gpu_buddy_free(mm, block, false);
}
```
The `if (tmp != order)` guard: after a failed `split_block()`, `block` points to the block that failed to split, which is still at order `tmp`. Since we entered the `while (tmp != order)` loop, `tmp > order` at that point. However, if `split_block()` succeeds but something updates `block` to point to a child (at `block = block->right; tmp--;`), by the time a *subsequent* iteration of the loop fails, `block` points to the right child which is at order `tmp-1` (the decremented value). So `tmp != order` is indeed always true here, as patch 2 correctly observes.
No issues. This should probably carry a `Cc: stable@vger.kernel.org` tag and a `Fixes:` tag.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-05-25 9:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 9:25 [PATCH v4 0/5] gpu/buddy: Per-order free and used block scoreboards Francois Dugast
2026-05-22 9:25 ` [PATCH v4 1/5] gpu/buddy: Fix use-after-free in split_block() call sites Francois Dugast
2026-05-25 9:06 ` Claude Code Review Bot [this message]
2026-05-22 9:25 ` [PATCH v4 2/5] gpu/buddy: Remove redundant condition in alloc_from_freetree() error path Francois Dugast
2026-05-22 10:10 ` Matthew Auld
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-22 9:25 ` [PATCH v4 3/5] gpu/buddy: Introduce __gpu_buddy_undo_splits() helper Francois Dugast
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-22 9:25 ` [PATCH v4 4/5] gpu/buddy: Track per-order free blocks with a scoreboard Francois Dugast
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-22 9:25 ` [PATCH v4 5/5] gpu/buddy: Track per-order used " Francois Dugast
2026-05-22 10:25 ` Arunpravin Paneer Selvam
2026-05-22 10:56 ` Matthew Auld
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-25 9:06 ` Claude review: gpu/buddy: Per-order free and used block scoreboards Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-05-11 16:41 [PATCH v2 0/3] " Francois Dugast
2026-05-11 16:41 ` [PATCH v2 1/3] gpu/buddy: Fix use-after-free in split_block() call sites Francois Dugast
2026-05-16 4:58 ` Claude review: " Claude Code Review Bot
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-20260522092600.32818-2-francois.dugast@intel.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