On Mon, Jun 22, 2026, at 12:15 PM, Sayed Kaif wrote:
> The generic ebl_set_initial_registers_sample() implementation used a
> fixed-size Dwarf_Word dwarf_regs[64] buffer while operating on
> ebl->frame_nregs entries. The only bound check was an assert:
>
> assert (ebl->frame_nregs < 64);
>
> which is compiled out in release builds.
>
> Several architectures using the generic implementation have
> frame_nregs values greater than 64 (for example ppc64=145,
> sparc=103 and riscv=66). As a result, the initialization loop can
> write beyond the end of the stack buffer, and subsequent register
> mapping may perform additional out-of-bounds writes.

Thank you for the catch regarding the assert;
unfortunately, this patch is not appropriate to apply as sent.

ebl_set_initial_registers_sample() includes a fallback implementation
ONLY used on architectures where the register file is small enough
and a linear 1:1 mapping {with no gaps} is appropriate.
Generalizing it with an allocation on every call is not worth it.
For all other architectures incl. ppc64 {in future}
and aarch64 {in the current version} a custom
set_initial_registers_sample() will be needed.

Since this turned out to be confusing for reviewers,
a patch to clarify the behavior for not-yet-supported arch
may be warranted.

Probably the most appropriate is to add a check
for ebl->perf_frame_regs_mask == 0 (the 'canonical' sign
that perf frame handling is unsupported for this arch).
If this is zero, ebl_set_initial_registers_sample() should return false.

All the best,
     Serhei

Reply via email to