Re: [PATCH 13/14] x86: BHI stubs
From: Andrew Cooper
Date: Mon Sep 30 2024 - 18:23:50 EST
On 30/09/2024 10:30 pm, 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?
There's no encoding for CMOVcc which takes an $imm.
%r10 is guaranteed zero after the FineIBT prologue, but I don't see
anything in patch 11 which makes this true in the !FineIBT case.
~Andrew