linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/bpf: Fix FineIBT vs eBPF
@ 2023-11-20 14:46 Peter Zijlstra
  2023-11-20 14:46 ` [PATCH 1/2] cfi: Flip headers Peter Zijlstra
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Peter Zijlstra @ 2023-11-20 14:46 UTC (permalink / raw)
  To: peterz
  Cc: paul.walmsley, palmer, aou, tglx, mingo, bp, dave.hansen, x86,
	hpa, davem, dsahern, ast, daniel, andrii, martin.lau, song,
	yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
	Arnd Bergmann, samitolvanen, keescook, nathan, ndesaulniers,
	linux-riscv, linux-kernel, netdev, bpf, linux-arch, llvm,
	jpoimboe, joao, mark.rutland

Hi!

There's a problem with FineIBT and eBPF using __nocfi when
CONFIG_BPF_JIT_ALWAYS_ON=n, in which case the __nocfi indirect call can target
a normal function like __bpf_prog_run32().

Specifically the various preambles look like:

   FineIBT				JIT

   __cfi_foo:
      endbr64
      subl	$hash, %r10d
      jz	1f
      ud2
   1: nop
   foo:					foo:
      osp nop3				   endbr64
      ...				   ...

So while bpf_dispatcher_*_func() does a __nocfi call to foo()+0 and this
matches what the JIT generates, it does not work for regular FineIBT functions,
since their +0 endbr got poisoned and things go *boom*.

Cure this by teaching the BPF JIT about all the various CFI forms. Notably this
removes the last __nocfi call on x86.

If the BPF folks agree (and the robots don't find fail) I'd like to take this
through the x86 tree, because I have a few more patches that turn the non-fatal
'osp nop3' poison into a 4 byte ud1 instruction which is rather fatal. As a
result this problem will also surface on !IBT hardware.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-12-04 16:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-20 14:46 [PATCH 0/2] x86/bpf: Fix FineIBT vs eBPF Peter Zijlstra
2023-11-20 14:46 ` [PATCH 1/2] cfi: Flip headers Peter Zijlstra
2023-11-20 14:46 ` [PATCH 2/2] x86/cfi,bpf: Fix BPF JIT call Peter Zijlstra
2023-11-20 15:59   ` Peter Zijlstra
2023-11-22  2:18   ` Alexei Starovoitov
2023-11-22 11:15     ` Peter Zijlstra
2023-11-22 12:41       ` Peter Zijlstra
2023-11-22 12:54         ` Peter Zijlstra
2023-11-23  0:51         ` Alexei Starovoitov
2023-11-23  0:43       ` Alexei Starovoitov
2023-12-01 23:54       ` Sami Tolvanen
2023-12-04 16:28         ` Nick Desaulniers
2023-11-22  1:41 ` [PATCH 0/2] x86/bpf: Fix FineIBT vs eBPF Alexei Starovoitov
2023-11-22 10:17   ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).