FAILED: Patch "drm/buddy: Prevent BUG_ON by validating rounded allocation" failed to apply to 6.12-stable tree
Subsystems (4)
Sasha Levin
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 5488a29596cdba93a60a79398dc9b69d5bdadf92 Mon Sep 17 00:00:00 2001
From: Sanjay Yadav <[email protected]>
Date: Thu, 8 Jan 2026 17:02:29 +0530
Subject: [PATCH] drm/buddy: Prevent BUG_ON by validating rounded allocation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When DRM_BUDDY_CONTIGUOUS_ALLOCATION is set, the requested size is rounded up to the next power-of-two via roundup_pow_of_two(). Similarly, for non-contiguous allocations with large min_block_size, the size is aligned up via round_up(). Both operations can produce a rounded size that exceeds mm->size, which later triggers BUG_ON(order > mm->max_order).
Example scenarios:
- 9G CONTIGUOUS allocation on 10G VRAM memory:
roundup_pow_of_two(9G) = 16G > 10G
- 9G allocation with 8G min_block_size on 10G VRAM memory:
round_up(9G, 8G) = 16G > 10G
Fix this by checking the rounded size against mm->size. For non-contiguous or range allocations where size > mm->size is invalid, return -EINVAL immediately. For contiguous allocations without range restrictions, allow the request to fall through to the existing __alloc_contig_try_harder() fallback.
This ensures invalid user input returns an error or uses the fallback path instead of hitting BUG_ON.
v2: (Matt A)
- Add Fixes, Cc stable, and Closes tags for context
--- drivers/gpu/drm/drm_buddy.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/drm_buddy.c +9 -0
@@ -1156,6 +1156,15 @@ int drm_buddy_alloc_blocks(struct drm_buddy *mm, order =fls (pages) -1 ; min_order =ilog2 (min_block_size) -ilog2 (mm->chunk_size); +if (order > mm->max_order || size > mm->size) { +if ((flags &DRM_BUDDY_CONTIGUOUS_ALLOCATION ) && + !(flags &DRM_BUDDY_RANGE_ALLOCATION )) +return __alloc_contig_try_harder (mm, original_size, + original_min_size, blocks); + +return -EINVAL ; + } + do { order = min(order, (unsigned int)fls(pages) - 1); BUG_ON(order > mm->max_order);
Signature · 1 line
2.51.0