On 4/20/2026 7:56 AM, Dylan Hatch wrote: > On Fri, Apr 17, 2026 at 8:45 AM Jens Remus <[email protected]> wrote:
>>> + case UNWIND_CFA_RULE_REG_OFFSET: >>> + case UNWIND_CFA_RULE_REG_OFFSET_DEREF: >>> + if (!regs) >> >> if (!regs || frame.cfa.regnum > 30) >> >>> + return -EINVAL; >>> + cfa = regs->regs[frame.cfa.regnum]; >> >> In unwind user this is guarded by a topmost frame check, as arbitrary >> registers are otherwise not available. Isn't this necessary in the >> kernel case? > > It is necessary, though as you point out the way I wrote the check is > not as obvious as it probably should be. > > The saved state->regs is set when the current frame is recovered from > the saved PC of a struct pt_regs, and then immediately set back to > NULL after the next frame has been recovered. In other words, the > state->regs is only ever set when it is relevant to the current frame, > which occurs when state->source == KUNWIND_SOURCE_REGS_PC. This only > happens when the topmost frame is recovered from a pt_regs, or when a > pt_regs is recovered from the stack due to an interrupt. > > I can make this more readable by adding an explicit check for > KUNWIND_SOURCE_REGS_PC in addition to state->regs != NULL. Thanks for the explanation! Maybe just add an explanation to the commit message and a short comment above the (!regs) test? /* regs only available in topmost frame */ Regards, Jens -- Jens Remus Linux on Z Development (D3303) [email protected] / [email protected] IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294 IBM Data Privacy Statement: https://www.ibm.com/privacy/

