diff mbox series

x86/boot: Disable jump tables in PIC code

Message ID 20250422210510.600354-2-ardb+git@google.com
State New
Headers show
Series x86/boot: Disable jump tables in PIC code | expand

Commit Message

Ard Biesheuvel April 22, 2025, 9:05 p.m. UTC
From: Ard Biesheuvel <ardb@kernel.org>

objtool already struggles to identify jump tables correctly in non-PIC
code, where the idiom is something like

  jmpq  *table(,%idx,8)

and the table is a list of absolute addresses of jump targets.

When using -fPIC, both the table reference as well as the jump targets
are emitted in a RIP-relative manner, resulting in something like

  leaq    table(%rip), %tbl
  movslq  (%tbl,%idx,4), %offset
  addq    %offset, %tbl
  jmpq    *%tbl

and the table is a list of offsets of the jump targets relative to the
start of the entire table.

Considering that this sequence of instructions can be interleaved with
other instructions that have nothing to do with the jump table in
question, it is extremely difficult to infer the control flow by
deriving the jump targets from the indirect jump, the location of the
table and the relative offsets it contains.

So let's not bother and disable jump tables for code built with -fPIC
under arch/x86/boot/startup.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/boot/startup/Makefile | 1 +
 1 file changed, 1 insertion(+)


base-commit: ff4c0560ab020d34baf0aa6434f66333d25ae524

Comments

Josh Poimboeuf April 23, 2025, 4:41 p.m. UTC | #1
On Wed, Apr 23, 2025 at 05:01:42PM +0200, Ard Biesheuvel wrote:
> > > So let's not bother and disable jump tables for code built with -fPIC
> > > under arch/x86/boot/startup.
> >
> > Hm, does objtool even run on boot code?
> >
> 
> This is about startup code, not boot code. This is code that is part
> of vmlinux, but runs from a different mapping of memory than the one
> the linker assumes, and so it needs to be built with -fPIC to
> discourage the compiler and linker from inserting symbol references
> via the kernel virtual mapping, which may not be up yet when this code
> runs.

Maybe objtool should ignore .head.text.  It doesn't need ORC, static
calls, uaccess validation, retpolines, etc.
diff mbox series

Patch

diff --git a/arch/x86/boot/startup/Makefile b/arch/x86/boot/startup/Makefile
index e5f77e65c083..4062582144f6 100644
--- a/arch/x86/boot/startup/Makefile
+++ b/arch/x86/boot/startup/Makefile
@@ -5,6 +5,7 @@  KBUILD_CFLAGS		+= -D__DISABLE_EXPORTS -mcmodel=small -fPIC \
 			   -Os -DDISABLE_BRANCH_PROFILING \
 			   $(DISABLE_STACKLEAK_PLUGIN) \
 			   -fno-stack-protector -D__NO_FORTIFY \
+			   -fno-jump-tables \
 			   -include $(srctree)/include/linux/hidden.h
 
 # disable ftrace hooks and LTO