Skip to content

objtool: Detect and warn about indirect calls in __nocfi functions

Peter Zijlstra kvm linux-efi linux-hyperv lkml 3 versions – Applied

Status from this message: The following commit has been merged into the x86/core branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest16 patches 19 repliesApplied
  2. v213 patches 38 repliesSuperseded
  3. v16 patches 25 repliesSuperseded

Changes in v3 from the cover letter

- renamed COP to EM_ASM
- reworked the KVM-IDT stuff (Sean, Josh)

[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/16x86/kvm/emulate: Implement test_cc() in Carch/x86/include/asm/text-patching.h arch/x86/kvm/emulate.c+15 -390 replies
2/16x86/kvm/emulate: Introduce EM_ASM_1arch/x86/kvm/emulate.c+58 -130 replies
3/16x86/kvm/emulate: Introduce EM_ASM_2arch/x86/kvm/emulate.c+47 -380 replies
4/16x86/kvm/emulate: Introduce EM_ASM_2Rarch/x86/kvm/emulate.c+12 -40 replies
5/16x86/kvm/emulate: Introduce EM_ASM_2Warch/x86/kvm/emulate.c+28 -190 replies
6/16x86/kvm/emulate: Introduce EM_ASM_2CLarch/x86/kvm/emulate.c+24 -150 replies
7/16x86/kvm/emulate: Introduce EM_ASM_1SRC2arch/x86/kvm/emulate.c+26 -82 replies
8/16x86/kvm/emulate: Introduce EM_ASM_3WCLarch/x86/kvm/emulate.c+19 -60 replies
9/16x86/kvm/emulate: Convert em_salc() to Carch/x86/kvm/emulate.c+9 -60 replies
10/16x86/kvm/emulate: Remove fastopsarch/x86/kvm/emulate.c+1 -1710 replies
11/16x86,hyperv: Clean up hv_do_hypercall()arch/x86/hyperv/hv_init.c arch/x86/hyperv/ivm.c arch/x86/include/asm/mshyperv.h +1 more+89 -1022 replies
12/16x86_64,hyperv: Use direct call to hypercall-pagearch/x86/hyperv/hv_init.c+30 -313 replies
13/16x86/fred: Install system vector handlers even if FRED isnt fully enabledarch/x86/include/asm/idtentry.h arch/x86/kernel/irqinit.c+6 -90 replies
14/16x86/fred: Play nice with invoking asm_fred_entry_from_kvm() on non-FRED hardwarearch/x86/entry/calling.h arch/x86/entry/entry_64_fred.S arch/x86/kernel/asm-offsets.c+32 -132 replies
15/16x86/fred: KVM: VMX: Always use FRED for IRQs when CONFIG_X86_FRED=yarch/x86/kvm/Kconfig arch/x86/kvm/vmx/vmx.c+8 -10 replies
16/16objtool: Validate kCFI callsarch/x86/kernel/machine_kexec_64.c arch/x86/kvm/vmx/vmenter.S arch/x86/platform/efi/efi_stub_64.S +6 more+72 -09 replies

Reviews trailers per patch

3 of 16 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMichael KelleySean ChristophersonWei LiuJosh Poimboeuf
SeriesA-b
1/16
2/16
3/16
4/16
5/16
6/16
7/16
8/16
9/16
10/16
11/16T-b R-b A-b
12/16R-b A-b
13/16
14/16Originally-by
15/16
16/16A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v3 thread

Cover letter [PATCH v3 00/16] objtool: Detect and warn about indirect calls in __nocfi functions

Hi!

On kCFI (CONFIG_CFI_CLANG=y) builds all indirect calls should have the CFI check on (with very few exceptions). Not having the CFI checks undermines the protection provided by CFI and will make these sites candidates for people wanting to steal your cookies.

Specifically the ABI changes are so that doing indirect calls without the CFI magic, to a CFI adorned function is not compatible (although it happens to work for some setups, it very much does not for FineIBT).

Rust people tripped over this the other day, since their 'core' happened to have some no_sanitize(kcfi) bits in, which promptly exploded when ran with FineIBT on.

Since this is very much not a supported model -- on purpose, have objtool detect and warn about such constructs.

This effort [1] found all existing [2] non-cfi indirect calls in the kernel.

Notably the KVM fastop emulation stuff -- which is completely rewritten -- the generated code doesn't look horrific, but is slightly more verbose. I'm running on the assumption that instruction emulation is not super performance critical these days of zero VM-exit VMs etc. Paolo noted that pre-Westmere (2010) cares about this.

KVM has another; the VMX interrupt injection stuff calls the IDT handler directly. This is rewritten to to use the FRED dispatch table, which moves it all into C.

HyperV hypercall page stuff, which I've previously suggested use direct calls, and which I've now converted (after getting properly annoyed with that code).

Also available at:

git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git x86/core

Changes since v2:

- renamed COP to EM_ASM
- reworked the KVM-IDT stuff (Sean, Josh)

[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]