* [PATCH] gdb/amd-dbgapi-target: assert register size in fetch/store_registers
@ 2026-05-11 11:58 Tankut Baris Aktemur
2026-05-11 12:15 ` Lancelot SIX
0 siblings, 1 reply; 2+ messages in thread
From: Tankut Baris Aktemur @ 2026-05-11 11:58 UTC (permalink / raw)
To: gdb-patches; +Cc: lancelot.six
Assert that register size is not larger than the max register size as
a safety measure against buffer overflow.
---
gdb/amd-dbgapi-target.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c
index b7d5ee7de9f..421ec8599ed 100644
--- a/gdb/amd-dbgapi-target.c
+++ b/gdb/amd-dbgapi-target.c
@@ -1968,10 +1968,12 @@ amd_dbgapi_target::fetch_registers (struct regcache *regcache, int regno)
amdgpu_gdbarch_tdep *tdep = get_amdgpu_gdbarch_tdep (gdbarch);
amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (regcache->ptid ());
gdb_byte raw[AMDGPU_MAX_REGISTER_SIZE];
+ ULONGEST reg_size = register_type (gdbarch, regno)->length ();
+ gdb_assert (reg_size <= AMDGPU_MAX_REGISTER_SIZE);
+
amd_dbgapi_status_t status
= amd_dbgapi_read_register (wave_id, tdep->register_ids[regno], 0,
- register_type (gdbarch, regno)->length (),
- raw);
+ reg_size, raw);
if (status == AMD_DBGAPI_STATUS_SUCCESS)
regcache->raw_supply (regno, raw);
@@ -1994,6 +1996,8 @@ amd_dbgapi_target::store_registers (struct regcache *regcache, int regno)
gdb_assert (is_amdgpu_arch (gdbarch));
gdb_byte raw[AMDGPU_MAX_REGISTER_SIZE];
+ ULONGEST reg_size = register_type (gdbarch, regno)->length ();
+ gdb_assert (reg_size <= AMDGPU_MAX_REGISTER_SIZE);
regcache->raw_collect (regno, &raw);
amdgpu_gdbarch_tdep *tdep = get_amdgpu_gdbarch_tdep (gdbarch);
@@ -2018,8 +2022,7 @@ amd_dbgapi_target::store_registers (struct regcache *regcache, int regno)
amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (regcache->ptid ());
amd_dbgapi_status_t status
= amd_dbgapi_write_register (wave_id, tdep->register_ids[regno], 0,
- register_type (gdbarch, regno)->length (),
- raw);
+ reg_size, raw);
if (status != AMD_DBGAPI_STATUS_SUCCESS)
warning (_("Couldn't write register %s (#%d)."),
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gdb/amd-dbgapi-target: assert register size in fetch/store_registers
2026-05-11 11:58 [PATCH] gdb/amd-dbgapi-target: assert register size in fetch/store_registers Tankut Baris Aktemur
@ 2026-05-11 12:15 ` Lancelot SIX
0 siblings, 0 replies; 2+ messages in thread
From: Lancelot SIX @ 2026-05-11 12:15 UTC (permalink / raw)
To: Tankut Baris Aktemur, gdb-patches
On 11/05/2026 12:58, Tankut Baris Aktemur wrote:
> Assert that register size is not larger than the max register size as
> a safety measure against buffer overflow.
> ---
> gdb/amd-dbgapi-target.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/gdb/amd-dbgapi-target.c b/gdb/amd-dbgapi-target.c
> index b7d5ee7de9f..421ec8599ed 100644
> --- a/gdb/amd-dbgapi-target.c
> +++ b/gdb/amd-dbgapi-target.c
> @@ -1968,10 +1968,12 @@ amd_dbgapi_target::fetch_registers (struct regcache *regcache, int regno)
> amdgpu_gdbarch_tdep *tdep = get_amdgpu_gdbarch_tdep (gdbarch);
> amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (regcache->ptid ());
> gdb_byte raw[AMDGPU_MAX_REGISTER_SIZE];
> + ULONGEST reg_size = register_type (gdbarch, regno)->length ();
> + gdb_assert (reg_size <= AMDGPU_MAX_REGISTER_SIZE);
> +
> amd_dbgapi_status_t status
> = amd_dbgapi_read_register (wave_id, tdep->register_ids[regno], 0,
> - register_type (gdbarch, regno)->length (),
> - raw);
> + reg_size, raw);
>
> if (status == AMD_DBGAPI_STATUS_SUCCESS)
> regcache->raw_supply (regno, raw);
> @@ -1994,6 +1996,8 @@ amd_dbgapi_target::store_registers (struct regcache *regcache, int regno)
> gdb_assert (is_amdgpu_arch (gdbarch));
>
> gdb_byte raw[AMDGPU_MAX_REGISTER_SIZE];
> + ULONGEST reg_size = register_type (gdbarch, regno)->length ();
> + gdb_assert (reg_size <= AMDGPU_MAX_REGISTER_SIZE);
> regcache->raw_collect (regno, &raw);
>
> amdgpu_gdbarch_tdep *tdep = get_amdgpu_gdbarch_tdep (gdbarch);
> @@ -2018,8 +2022,7 @@ amd_dbgapi_target::store_registers (struct regcache *regcache, int regno)
> amd_dbgapi_wave_id_t wave_id = get_amd_dbgapi_wave_id (regcache->ptid ());
> amd_dbgapi_status_t status
> = amd_dbgapi_write_register (wave_id, tdep->register_ids[regno], 0,
> - register_type (gdbarch, regno)->length (),
> - raw);
> + reg_size, raw);
>
> if (status != AMD_DBGAPI_STATUS_SUCCESS)
> warning (_("Couldn't write register %s (#%d)."),
Hi Baris,
Thanks, this looks good to me, tested on gfx1031.
Approved-by: Lancelot Six <lancelot.six@amd.com>
Best,
Lancelot.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-11 12:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-11 11:58 [PATCH] gdb/amd-dbgapi-target: assert register size in fetch/store_registers Tankut Baris Aktemur
2026-05-11 12:15 ` Lancelot SIX
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox