netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] x86/bpf: Fix FineIBT vs eBPF
@ 2023-11-30 13:36 Peter Zijlstra
  2023-11-30 13:36 ` [PATCH v2 1/2] cfi: Flip headers Peter Zijlstra
  2023-11-30 13:36 ` [PATCH v2 2/2] x86/cfi,bpf: Fix BPF JIT call Peter Zijlstra
  0 siblings, 2 replies; 35+ messages in thread
From: Peter Zijlstra @ 2023-11-30 13:36 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.

Changes since v1:
 - added wee comment to asm/cfi.h (ast)
 - added asm comments to bytecode (ast)
 - renamed bpf_func_proto() to __bpf_prog_runX() (ast)
 - added bpf_prog_aux::ksym_prefix (ast)


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

end of thread, other threads:[~2023-12-09  4:51 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-30 13:36 [PATCH v2 0/2] x86/bpf: Fix FineIBT vs eBPF Peter Zijlstra
2023-11-30 13:36 ` [PATCH v2 1/2] cfi: Flip headers Peter Zijlstra
2023-12-04 19:18   ` Sami Tolvanen
2023-11-30 13:36 ` [PATCH v2 2/2] x86/cfi,bpf: Fix BPF JIT call Peter Zijlstra
2023-12-03 22:56   ` Alexei Starovoitov
2023-12-04  9:13     ` Peter Zijlstra
2023-12-04 11:11       ` Peter Zijlstra
2023-12-04 12:52         ` Peter Zijlstra
2023-12-04 17:25           ` Jiri Olsa
2023-12-04 18:16             ` Peter Zijlstra
2023-12-04 18:33               ` Peter Zijlstra
2023-12-04 18:58                 ` Sami Tolvanen
2023-12-05  1:18                 ` Alexei Starovoitov
2023-12-06 15:35                   ` Peter Zijlstra
2023-12-06 16:38                   ` Peter Zijlstra
2023-12-06 18:37                     ` Peter Zijlstra
2023-12-06 21:39                       ` Alexei Starovoitov
2023-12-07  9:31                         ` Peter Zijlstra
2023-12-07 22:32                           ` Alexei Starovoitov
2023-12-08 10:29                             ` Peter Zijlstra
2023-12-08 13:40                               ` Peter Zijlstra
2023-12-08 17:21                                 ` Peter Zijlstra
2023-12-08 19:40                                   ` Alexei Starovoitov
2023-12-08 20:27                                     ` Peter Zijlstra
2023-12-08 20:35                                     ` Peter Zijlstra
2023-12-08 20:41                                       ` Alexei Starovoitov
2023-12-08 20:52                                         ` Peter Zijlstra
2023-12-08 20:58                                           ` Alexei Starovoitov
2023-12-08 22:45                                             ` Peter Zijlstra
2023-12-09  4:51                                               ` Alexei Starovoitov
2023-12-08 19:32                                 ` Alexei Starovoitov
2023-12-08 20:18                                   ` Peter Zijlstra
2023-12-08 20:45                                     ` Alexei Starovoitov
2023-12-08 20:56                                       ` Peter Zijlstra
2023-12-08 21:04                                         ` Alexei Starovoitov

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).