x86/boot: Disable jump tables in PIC code
PATCH 1/1 x86/boot: Disable jump tables in PIC code
From: Ard Biesheuvel <[email protected]>
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.
--- arch/x86/boot/startup/Makefile | 1 + 1 file changed, 1 insertion(+)
arch/x86/boot/startup/Makefile +1 -0
@@ -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
base-commit: ff4c0560ab020d34baf0aa6434f66333d25ae524
Signature · 1 line
2.49.0.805.g082f7c87e0-goog
The following commit has been merged into the x86/boot branch of tip:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 121c335b36e02d6aefb72501186e060474fdf33c Gitweb: https://git.kernel.org/tip/121c335b36e02d6aefb72501186e060474fdf33c Author: Ard Biesheuvel <[email protected]> AuthorDate: Tue, 22 Apr 2025 23:05:11 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 23 Apr 2025 09:30:57 +02:00
x86/boot: Disable jump tables in PIC code
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.
--- arch/x86/boot/startup/Makefile | 1 + 1 file changed, 1 insertion(+)
arch/x86/boot/startup/Makefile +1 -0
@@ -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
Quoted 29 lines · On Wed, Apr 23, 2025 at 07:48:01AM +0000, tip-bot2 for Ard Biesheuvel wrote:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 121c335b36e02d6aefb72501186e060474fdf33c Gitweb: https://git.kernel.org/tip/121c335b36e02d6aefb72501186e060474fdf33c Author: Ard Biesheuvel <[email protected]> AuthorDate: Tue, 22 Apr 2025 23:05:11 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 23 Apr 2025 09:30:57 +02:00x86/boot: Disable jump tables in PIC code
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 *%tbland the table is a list of offsets of the jump targets relative to the start of the entire table.
Quoted 8 lines
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.
Hm, does objtool even run on boot code?
Signature · 1 line
Josh
Ard Biesheuvel
maintainerQuoted 37 lines · Josh Poimboeuf
Quoted 35 lines · On Wed, Apr 23, 2025 at 07:48:01AM +0000, tip-bot2 for Ard Biesheuvel wrote:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 121c335b36e02d6aefb72501186e060474fdf33c Gitweb: https://git.kernel.org/tip/121c335b36e02d6aefb72501186e060474fdf33c Author: Ard Biesheuvel <[email protected]> AuthorDate: Tue, 22 Apr 2025 23:05:11 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 23 Apr 2025 09:30:57 +02:00x86/boot: Disable jump tables in PIC code
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 *%tbland 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.
Quoted 5 lines
Quoted 2 lines
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.
Quoted 6 lines · Ard Biesheuvel
Quoted 5 lines
Quoted 2 lines
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?
Quoted 6 lines
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.
Signature · 1 line
Josh
Ard Biesheuvel
maintainerQuoted 15 lines · Josh Poimboeuf
Quoted 6 lines · Ard Biesheuvel
Quoted 5 lines
Quoted 2 lines
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?
Quoted 6 lines
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.
Quoted 3 lines
Maybe objtool should ignore .head.text. It doesn't need ORC, static calls, uaccess validation, retpolines, etc.
I am trying to get rid of .head.text.
But some of the startup code may still be in use later, so I don't think we should disable objtool validation entirely unless we really have to.