Re: [PATCH v3 05/10] x86/ibt: Optimize FineIBT sequence

Kees Cook
2025-02-19T18:23:38Z

On Wed, Feb 19, 2025 at 07:18:33PM +0100, Peter Zijlstra wrote:
> On Wed, Feb 19, 2025 at 10:01:15AM -0800, Kees Cook wrote:
> > On Wed, Feb 19, 2025 at 05:21:12PM +0100, Peter Zijlstra wrote:
> > > Scott notes that non-taken branches are faster. Abuse overlapping code
> > > that traps instead of explicit UD2 instructions.
> >
> > Some kind of commenting is needed in here to explicitly call out the
> > embedded EA in the "subl" instruction. There is a tiny hint of it in the
> > disassembly dump of fineibt_preamble_start, but it's very subtle for
> > someone trying to understand this fresh.
>
> Ah, but you found my clue :-)
>
> How's this?
>
> ---
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -1080,6 +1080,9 @@ early_param("cfi", cfi_parse_cmdline);
> * 4: 41 81 <ea> 78 56 34 12 sub $0x12345678, %r10d
> * b: 75 f9 jne 6 <fineibt_preamble_start+0x6>
> * d: 0f 1f 00 nopl (%rax)
> + *
> + * Note that the JNE target is the 0xEA byte inside the SUB, this decodes as
> + * (bad) on x86_64 and raises #UD.
> */
> asm( ".pushsection .rodata \n"
> "fineibt_preamble_start: \n"

Better! Thank you. :)

--
Kees Cook