Re: [PATCH 5/7] x86/bugs: Only harden syscalls when needed

From: Andrew Cooper
Date: Fri Apr 12 2024 - 06:25:07 EST


On 11/04/2024 4:38 pm, Josh Poimboeuf wrote:
> On Thu, Apr 11, 2024 at 11:06:37AM +0100, Andrew Cooper wrote:
>>> +#define __do_syscall(table, func_direct, nr, regs) \
>>> +({ \
>>> + unsigned long __rax, __rdi, __rsi; \
>>> + \
>>> + asm_inline volatile( \
>>> + ALTERNATIVE("call " __stringify(func_direct) "\n\t", \
>>> + ANNOTATE_RETPOLINE_SAFE \
>>> + "call *%[func_ptr]\n\t", \
>> This wants to be a plain maybe-thunk'd indirect call, and without the
>> ANNOTATE_RETPOLINE_SAFE.
>>
>> Or you're going to get into cases where some combinations of command
>> line options do unexpected things e.g. retpolining everything except the
>> syscall dispatch.
> In that case won't X86_FEATURE_INDIRECT_SAFE get cleared, resulting in
> the above using a direct call? Or did I miss something?

That works until the next time anyone touches the logic.  Then it's
latent vulnerability, or an incorrect trial of a non-default option.

I guarantee you'll save someone (probably someone on this CC list) a
headache in the future by not introducing an unnecessary special case here.

~Andrew