From: bob <[email protected]>
ras_umc_update_eeprom_ram_data() appends nr_page_pfns records to
data->bps, a heap array that ras_umc_realloc_err_data_space() grows in
steps aligned to 512 entries. It only reallocates when space_left is
exactly zero, which is enough only if every append is a power of two that
divides the allocation size, so that space_left always reaches zero
before the next append.
Commit 6cd157c105a0 ("drm/amd/ras: filter out invalid pages from
extended page addresses") made ras_umc_expand_row_pages() return only
the addresses that pass the sanity check, so the number of pages per
record can be any value from 1 to max_pages_per_row (16 or 128). With
0 < space_left < nr_page_pfns the check does not fire and the loop
writes past the end of data->bps. space_left (an int) then goes negative,
so "!space_left" never holds again and every following record writes
further beyond the allocation, by up to max_pages_per_row - 1 entries
each.
For example, after the array is filled up to 500 of 512 entries, a record
that yields 16 valid pages writes entries 500..515 into an array of 512.
The function is reached while loading the bad page records from the EEPROM
at probe time (ras_umc_load_bad_pages()) and when a new bad page is
added at runtime (ras_umc_add_bad_pages()).
Reallocate whenever the remaining space is smaller than what is about to
be appended. ras_umc_realloc_err_data_space() adds at least 256 entries
(ALIGN(old + 256, 512) - old >= 256), more than the at most 128 entries
of one record, so a single reallocation is enough.
This issue was found by manual code review with the help of an AI coding
assistant (Claude Opus 5.5), which also drafted this patch. It has been
compile-tested with W=1 and smatch on x86_64 allmodconfig (no new
warnings). It has not been runtime-tested: it needs a UniRAS-capable GPU
(UMC v12/v13/v15) with suitable bad page records, and no reproducer
was built.
Fixes: 6cd157c105a0 ("drm/amd/ras: filter out invalid pages from extended page
addresses")
Signed-off-by: bob <[email protected]>
---
drm/amd/ras: fix heap overflow when appending bad page records
---
drivers/gpu/drm/amd/ras/core/ras_umc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/ras/core/ras_umc.c
b/drivers/gpu/drm/amd/ras/core/ras_umc.c
index 78560467ee84..b143a5a871e8 100644
--- a/drivers/gpu/drm/amd/ras/core/ras_umc.c
+++ b/drivers/gpu/drm/amd/ras/core/ras_umc.c
@@ -670,8 +670,8 @@ static int ras_umc_update_eeprom_ram_data(struct
ras_core_context *ras_core,
if (!nr_page_pfns)
return 0;
- if (!data->space_left &&
- ras_umc_realloc_err_data_space(ras_core, data, 256))
+ if (data->space_left < (int)nr_page_pfns &&
+ ras_umc_realloc_err_data_space(ras_core, data, 256))
return -ENOMEM;
for (j = 0; j < nr_page_pfns; j++) {
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261203-fix-u2-amdgpu-ras-umc-overflow-7ba9951d9f22
Best regards,
--
bob <[email protected]>