[Devel] [PATCH hci-8.2 2/4] ms/gpu/buddy: Fix use-after-free in split_block() call sites
Mirian Shilakadze
mirian.shilakadze at virtuozzo.com
Wed Nov 18 14:38:11 MSK 2026
From: Francois Dugast <francois.dugast at intel.com>
When split_block() fails it returns before calling mark_split(), leaving
the block in the FREE state and still linked in the rbtree. The four
err_undo paths then call __gpu_buddy_free() without first removing the
block from the tree, which leads to two distinct bugs:
- If the buddy is also free, __gpu_buddy_free() merges the two siblings
by calling gpu_block_free(mm, block) while block->rb is still linked
in the tree. Any subsequent rbtree traversal will follow the now-
dangling pointer, causing a use-after-free.
- In alloc_from_freetree(), where there is no buddy guard,
__gpu_buddy_free() always reaches mark_free() -> rbtree_insert() with
block still in the tree, corrupting the rbtree.
The same pattern is already used correctly in __force_merge(): call
rbtree_remove() to unlink the block before handing it to
__gpu_buddy_free(). Apply the same fix to all four err_undo sites.
Reported-by: Sashiko <sashiko-bot at kernel.org>
Assisted-by: GitHub Copilot:claude-sonnet-4.6
Reviewed-by: Matthew Auld <matthew.auld at intel.com>
Link: https://lore.kernel.org/r/20260522092600.32818-2-francois.dugast@intel.com
Signed-off-by: Francois Dugast <francois.dugast at intel.com>
(cherry picked from commit 0251963afd22d1365d07bf81135ef0c694f6c3b5)
Context adjusted: the allocator is drivers/gpu/drm/drm_buddy.c with drm_
names here, and only three of the four err_undo sites exist (there is
no offset aligned allocation function).
https://virtuozzo.atlassian.net/browse/VSTOR-155318
Feature: fix ms/drm
Signed-off-by: Mirian Shilakadze <mirian.shilakadze at virtuozzo.com>
---
drivers/gpu/drm/drm_buddy.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/drm_buddy.c b/drivers/gpu/drm/drm_buddy.c
index 640d93070bb7..87c65923259f 100644
--- a/drivers/gpu/drm/drm_buddy.c
+++ b/drivers/gpu/drm/drm_buddy.c
@@ -684,8 +684,10 @@ __alloc_range_bias(struct drm_buddy *mm,
buddy = __get_buddy(block);
if (buddy &&
(drm_buddy_block_is_free(block) &&
- drm_buddy_block_is_free(buddy)))
+ drm_buddy_block_is_free(buddy))) {
+ rbtree_remove(mm, block);
__drm_buddy_free(mm, block, false);
+ }
return ERR_PTR(err);
}
@@ -794,8 +796,10 @@ alloc_from_freetree(struct drm_buddy *mm,
return block;
err_undo:
- if (tmp != order)
+ if (tmp != order) {
+ rbtree_remove(mm, block);
__drm_buddy_free(mm, block, false);
+ }
return ERR_PTR(err);
}
@@ -880,8 +884,10 @@ static int __alloc_range(struct drm_buddy *mm,
buddy = __get_buddy(block);
if (buddy &&
(drm_buddy_block_is_free(block) &&
- drm_buddy_block_is_free(buddy)))
+ drm_buddy_block_is_free(buddy))) {
+ rbtree_remove(mm, block);
__drm_buddy_free(mm, block, false);
+ }
err_free:
if (err == -ENOSPC && total_allocated_on_err) {
--
2.47.3
More information about the Devel
mailing list