From: sashiko-bot@kernel.org
To: "Arunpravin Paneer Selvam" <Arunpravin.PaneerSelvam@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2] gpu/buddy: bail out of try_harder when alignment cannot be honoured
Date: Thu, 09 Jul 2026 13:29:54 +0000 [thread overview]
Message-ID: <20260709132955.5EE701F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709131050.1022759-1-Arunpravin.PaneerSelvam@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Integer truncation in `rounddown_pow_of_two(size)` on 32-bit architectures leads to out-of-bounds array access.
--
--- Patch [1]: [PATCH v2] gpu/buddy: bail out of try_harder when alignment cannot be honoured ---
commit e9f823b96a2660e1690b65d2c8c95099338dc996
Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
gpu/buddy: bail out of try_harder when alignment cannot be honoured
The try_harder contiguous fallback could return a range whose start
offset did not match the caller's min_block_size. When a candidate's
start is misaligned, realign it: free the misaligned run and reallocate
exactly @size at the next lower min_block_size boundary.
> diff --git a/drivers/gpu/buddy.c b/drivers/gpu/buddy.c
> index dc81fe0301ce8..3c73ae87f3c5b 100644
> --- a/drivers/gpu/buddy.c
> +++ b/drivers/gpu/buddy.c
[ ... ]
> static int __alloc_contig_try_harder(struct gpu_buddy *mm,
> u64 size,
> u64 min_block_size,
> struct list_head *blocks)
> {
> - u64 rhs_offset, lhs_offset, lhs_size, filled;
> + u64 rhs_offset, lhs_offset, filled;
> struct gpu_buddy_block *block;
> unsigned int tree, order;
> - LIST_HEAD(blocks_lhs);
> - unsigned long pages;
> u64 modify_size;
> int err;
>
> modify_size = rounddown_pow_of_two(size);
> - pages = modify_size >> ilog2(mm->chunk_size);
> - order = fls(pages) - 1;
> + order = ilog2(modify_size) - ilog2(mm->chunk_size);
[Severity: High]
This isn't a bug introduced by this patch, but could this integer truncation
lead to out-of-bounds array accesses on 32-bit architectures?
The size parameter is a u64, but the rounddown_pow_of_two() macro operates
on an unsigned long. On a 32-bit system, if a large size is passed
(e.g., 4GB) where the lower 32 bits are smaller than chunk_size or zero,
the truncation can result in modify_size becoming 0.
When modify_size is 0, ilog2(0) yields -1. This causes order (an unsigned
int) to underflow into a massive positive value. The if (order == 0) check
is bypassed, and this huge order value is then used to index into the
mm->free_trees[tree][order] array, which could crash the kernel during the
RB tree traversal.
> if (order == 0)
> return -ENOSPC;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260709131050.1022759-1-Arunpravin.PaneerSelvam@amd.com?part=1
next prev parent reply other threads:[~2026-07-09 13:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 13:10 [PATCH v2] gpu/buddy: bail out of try_harder when alignment cannot be honoured Arunpravin Paneer Selvam
2026-07-09 13:29 ` sashiko-bot [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-07-09 13:02 Arunpravin Paneer Selvam
2026-07-09 13:25 ` sashiko-bot
2026-06-29 7:43 Arunpravin Paneer Selvam
2026-07-02 10:48 ` Matthew Auld
2026-07-03 0:35 ` John Olender
2026-07-03 13:40 ` Arunpravin Paneer Selvam
2026-07-09 13:25 ` Arunpravin Paneer Selvam
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=20260709132955.5EE701F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Arunpravin.PaneerSelvam@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/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