drm/amdgpu: fix ATOM parameter space index bounds check
Subsystems (3)
PATCH 1/1 drm/amdgpu: fix ATOM parameter space index bounds check
atom_get_src_int() and atom_put_dst() use idx as a dword index into the uint32_t *ps array (ctx->ps[idx]), but compare it against ctx->ps_size which is in bytes. A malformed ATOM table operand with idx between ps_size/4 and ps_size-1 passes the bounds check but accesses up to 3 dwords (12 bytes) beyond the stack-allocated parameter buffer.
For example with ps_size = 16 bytes (4 dwords), idx = 5 passes the check (5 < 16) but ctx->ps[5] reads/writes the 6th dword at byte offset 20, 4 bytes past the allocation.
Divide ps_size by 4 in both comparisons to match the dword indexing.
--- drivers/gpu/drm/amd/amdgpu/atom.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/atom.c +2 -2
@@ -232,7 +232,7 @@ static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr, (*ptr)++;/* get_unaligned_le32 avoids unaligned accesses from atombios * tables, noticed on a DEC Alpha. */ -if (idx < ctx->ps_size) +if (idx < ctx->ps_size /4 ) val =get_unaligned_le32 ((u32 *)&ctx->ps[idx]);else pr_info ("PS index out of range: %i > %i\n" , idx, ctx->ps_size);
@@ -510,7 +510,7 @@ static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr, idx =U8 (*ptr); (*ptr)++;DEBUG ("PS[0x%02X]" , idx); -if (idx >= ctx->ps_size) { +if (idx >= ctx->ps_size /4 ) {pr_info ("PS index out of range: %i > %i\n" , idx, ctx->ps_size);return ; }
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] drm/amdgpu: confusing log message for ATOM PS index out of range --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] drm/amdgpu: confusing log message for ATOM PS index out of range
--
commit dd873e6794eea339db29a3fa2da08121624e1439
Author: Aldo Ariel Panzardo <[email protected]>
drm/amdgpu: fix ATOM parameter space index bounds check
This commit divides ctx->ps_size by 4 in atom_get_src_int() and atom_put_dst() to prevent out-of-bounds dword accesses into the parameter buffer.
drivers/gpu/drm/amd/amdgpu/atom.c static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr, · line 238
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/atom.c +1
-1@@ -232,7 +232,7 @@ static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr, (*ptr)++;/* get_unaligned_le32 avoids unaligned accesses from atombios * tables, noticed on a DEC Alpha. */ -if (idx < ctx->ps_size) +if (idx < ctx->ps_size /4 ) val =get_unaligned_le32 ((u32 *)&ctx->ps[idx]);else pr_info ("PS index out of range: %i > %i\n" , idx, ctx->ps_size);
[Severity: Low]
Does this print a mathematically confusing log message? Since the check now validates idx against ctx->ps_size / 4, if idx is between ctx->ps_size / 4 and ctx->ps_size - 1, the log could print something like "5 > 16". Should we also divide ctx->ps_size by 4 in the pr_info() statement to match the dword indexing?
drivers/gpu/drm/amd/amdgpu/atom.c static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr, · line 514
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/atom.c +1
-1@@ -510,7 +510,7 @@ static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr, idx =U8 (*ptr); (*ptr)++;DEBUG ("PS[0x%02X]" , idx); -if (idx >= ctx->ps_size) { +if (idx >= ctx->ps_size /4 ) {pr_info ("PS index out of range: %i > %i\n" , idx, ctx->ps_size);
[Severity: Low]
Similarly, does this print the byte size instead of the dword size? Since the out of bounds check now uses ctx->ps_size / 4, this could also print contradictory statements when the error condition is hit.
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/atom.c +0
-0return ; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1