Re: [PATCH 13/14] x86: BHI stubs

From: Josh Poimboeuf
Date: Mon Sep 30 2024 - 17:46:55 EST


On Mon, Sep 30, 2024 at 02:30:32PM -0700, Josh Poimboeuf wrote:
> On Fri, Sep 27, 2024 at 09:49:09PM +0200, Peter Zijlstra wrote:
> > +/*
> > + * At the function start, launder function arguments that are a pointer through
> > + * CMOVcc, this will create a write dependency in the speculation flow.
> > + *
> > + * Notably, the CFI preambles calling these will have ZF set and r10 zero.
> > + */
> > +
> > +.pushsection .noinstr.text, "ax"
> > +
> > + .align 8
> > +SYM_CODE_START(__bhi_args_6c1)
> > + ANNOTATE_NOENDBR
> > + .align 8
> > +SYM_INNER_LABEL(__bhi_args_0, SYM_L_LOCAL)
> > + UNWIND_HINT_FUNC
> > + cmovne %r10, %rdi
>
> IIUC, this works because if the "jz" in the CFI preamble mispredicts to
> the __bhi_args_* code, "cmovne" will zero out the speculative value of
> rdi.
>
> Why use %r10 instead of a literal $0? Also how do you know %r10 is 0?

BTW, this "speculative pointer clearing" feature is broader than just
BHI so I wouldn't call it that. It's really just a logical extension of
FineIBT IMO.

--
Josh