lkml.org 
[lkml]   [2022]   [Feb]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 16/39] x86/bpf: Add ENDBR instructions to prologue and trampoline
On Thu, Feb 24, 2022 at 03:51:54PM +0100, Peter Zijlstra wrote:
> @@ -339,9 +350,18 @@ static int __bpf_arch_text_poke(void *ip
> u8 *prog;
> int ret;
>
> +#ifdef CONFIG_X86_KERNEL_IBT
> + if (is_endbr(*(u32 *)ip))
> + ip += 4;
> +#endif
> +
> memcpy(old_insn, nop_insn, X86_PATCH_SIZE);
> if (old_addr) {
> prog = old_insn;
> +#ifdef CONFIG_X86_KERNEL_IBT
> + if (is_endbr(*(u32 *)old_addr))
> + old_addr += 4;
> +#endif
> ret = t == BPF_MOD_CALL ?
> emit_call(&prog, old_addr, ip) :
> emit_jump(&prog, old_addr, ip);
> @@ -352,6 +372,10 @@ static int __bpf_arch_text_poke(void *ip
> memcpy(new_insn, nop_insn, X86_PATCH_SIZE);
> if (new_addr) {
> prog = new_insn;
> +#ifdef CONFIG_X86_KERNEL_IBT
> + if (is_endbr(*(u32 *)new_addr))
> + new_addr += 4;
> +#endif

All the above ifdef-itis should be able to be removed since is_endbr()
returns false for !IBT.

> ret = t == BPF_MOD_CALL ?
> emit_call(&prog, new_addr, ip) :
> emit_jump(&prog, new_addr, ip);
> @@ -2028,10 +2052,11 @@ int arch_prepare_bpf_trampoline(struct b
> /* skip patched call instruction and point orig_call to actual
> * body of the kernel function.
> */
> - orig_call += X86_PATCH_SIZE;
> + orig_call += X86_PATCH_SIZE + 4*HAS_KERNEL_IBT;

All the "4*HAS_KERNEL_IBT" everywhere is cute, but you might as well
just have IBT_ENDBR_SIZE (here and in other patches).

--
Josh

\
 
 \ /
  Last update: 2022-02-25 00:39    [W:2.316 / U:0.444 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site