Re: [PATCH v2 00/13] objtool: Detect and warn about indirect calls in __nocfi functions

Peter Zijlstra
2025-05-28T16:36:06Z

On Wed, May 28, 2025 at 06:30:35PM +0200, Peter Zijlstra wrote:
> On Wed, May 28, 2025 at 09:44:52AM +0200, Peter Zijlstra wrote:
> > On Tue, May 06, 2025 at 12:18:49PM -0700, Josh Poimboeuf wrote:
> >
> > > Weird, I'm not seeing that.
> >
> > I Ate'nt Crazeh...
> >
> > https://lore.kernel.org/all/202505280410.2qfTQCRt-lkp@intel.com/T/#u
> >
> > I'll go poke at it, see if today is the day I can figure out WTF
> > happens.
>
> It manages to trip the CFI_UNDEFINED case in op->dest.reg == cfa->base
> in update_cfi_state().
>
> I figured it ought to tickle the regular 'mov %rbp, %rsp' case above
> there, but it doesn't, for some reason it has cfa.base == SP at this
> point.
>
> This happens... /me looks in scrollback ... at POP_REGS 'pop
> %rbp'. ARGH!!
>
>
> So the sequence of fail is:
>
> push %rbp
> mov %rsp, %rbp # cfa.base = BP
>
> SAVE
> ...
> push %rbp
> ...
> pop %rbp # cfa.base = SP

This is the POP !drap and dest==base case.

> ...
> mov %rbp, %rsp # UNDEF
> nop # FAIL
> RESTORE
>
> Note that the MOV+NOP is the 4 bytes ERETS needs.