Re: [tip:x86/pti] x86/retpoline: Fill return stack buffer on vmexit

From: Borislav Petkov
Date: Thu Jan 25 2018 - 07:46:10 EST


On Thu, Jan 25, 2018 at 12:20:49PM +0000, David Woodhouse wrote:
> I haven't had lunch yet, so I don't feel queasy

Oh, I caught you on time then :-)

> and I'm vaguely interested... *why* does it break kABI?

Kernels < 4.1 don't have the insn padding I did back then so when one
tries to backport this, struct alt_instr size changes. Fun.

> > +/* Like alternative_io, but for replacing a direct call with another one. */
> > +#define alternative_void_call(oldfunc, newfunc, feature, input...) \
> > + asm volatile (ALTERNATIVE("call %P[old]", "call %P[new]", feature) \
> > + : : [old] "i" (oldfunc), [new] "i" (newfunc), ## input)
>
> But you aren't doing the call at all in the other case, and
> alternatives *always* handled the case where the first 'alternative'
> instruction was a branch, didn't it?
>
> So couldn't it just be alternative(nop, call __fill_rsb_func)?
>
> But I still don't understand why it matters.

You need for both to be CALL instructions there so that gcc can manage
the callee clobbers properly - i.e., recognize that there's a function
call there.

Otherwise you need to do uglies like the hunk in arch/x86/Kconfig in

d61931d89be5 ("x86: Add optimized popcnt variants")

which I killed later after all as it broke profiling and other tools.

And besides, calling a NOPpy function on CONFIG_RETPOLINE=n is the least
of our troubles. Also, the installations running CONFIG_RETPOLINE=n are
going to be a very very very small number.

> > +void __fill_rsb(void)
> > +{
> > + unsigned long loops;
> > +
> > + asm volatile (__stringify(__FILL_RETURN_BUFFER(%0, RSB_CLEAR_LOOPS, %1))
> > + ÂÂÂÂÂÂ: "=r" (loops), ASM_CALL_CONSTRAINT
> > + ÂÂÂÂÂÂ: : "memory" );
> > +}
> > +#endif
>
> The out-of-line function should be __clear_rsb() if it's using
> RSB_CLEAR_LOOPS, and __fill_rsb() if it's using RSB_FILL_LOOPS. I think
> we're only using one right now but Andi at least is posting patches
> which use the other, as part of the Skylake clusterfuck.

Ok.

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.