x86/alternatives: Make FineIBT mode Kconfig selectable
PATCH 1/1 x86/alternatives: Make FineIBT mode Kconfig selectable
Since FineIBT performs checking at the destination, it is weaker against attacks that can construct arbitrary executable memory contents. As such, some system builders want to run with FineIBT disabled by default. Allow the "cfi=kcfi" boot param mode to be selectable through Kconfig via the newly introduced CONFIG_CFI_AUTO_DEFAULT.
---
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Sami Tolvanen <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
--- arch/x86/Kconfig | 9 +++++++++ arch/x86/include/asm/cfi.h | 2 +- arch/x86/kernel/alternative.c | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-)
arch/x86/Kconfig +9 -0
@@ -2424,6 +2424,15 @@ config STRICT_SIGALTSTACK_SIZE Say 'N' unless you want to really enforce this check. +config CFI_AUTO_DEFAULT + bool "Attempt to use FineIBT by default at boot time" + depends on FINEIBT + default y + help + Attempt to use FineIBT by default at boot time. If enabled, + this is the same as booting with "cfi=auto". If disabled, + this is the same as booting with "cfi=kcfi". + source "kernel/livepatch/Kconfig" endmenu
arch/x86/include/asm/cfi.h +1 -1
@@ -93,7 +93,7 @@* */ enum cfi_mode { -CFI_DEFAULT ,/* FineIBT if hardware has IBT, otherwise kCFI */ +CFI_AUTO ,/* FineIBT if hardware has IBT, otherwise kCFI */ CFI_OFF ,/* Taditional / IBT depending on .config */ CFI_KCFI ,/* Optionally CALL_PADDING, IBT, RETPOLINE */ CFI_FINEIBT ,/* see arch/x86/kernel/alternative.c */
arch/x86/kernel/alternative.c +4 -4
@@ -902,8 +902,8 @@ void __init_or_module apply_seal_endbr(s32 *start, s32 *end) { }#endif /* CONFIG_X86_KERNEL_IBT */ -#ifdef CONFIG_FINEIBT -#define __CFI_DEFAULT CFI_DEFAULT +#ifdef CONFIG_CFI_AUTO_DEFAULT +#define __CFI_DEFAULT CFI_AUTO#elif defined(CONFIG_CFI_CLANG )#define __CFI_DEFAULT CFI_KCFI#else
@@ -1011,7 +1011,7 @@ static __init int cfi_parse_cmdline(char *str) }if (!strcmp (str,"auto" )) { - cfi_mode =CFI_DEFAULT ; + cfi_mode =CFI_AUTO ; }else if (!strcmp (str,"off" )) { cfi_mode =CFI_OFF ; cfi_rand = false;
@@ -1271,7 +1271,7 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline, "FineIBT preamble wrong size: %ld", fineibt_preamble_size))return ; -if (cfi_mode ==CFI_DEFAULT ) { +if (cfi_mode ==CFI_AUTO ) { cfi_mode =CFI_KCFI ;if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT )) cfi_mode =CFI_FINEIBT ;
Signature · 1 line
2.34.1
Quoted 7 lines · Kees Cook
Since FineIBT performs checking at the destination, it is weaker against attacks that can construct arbitrary executable memory contents. As such, some system builders want to run with FineIBT disabled by default. Allow the "cfi=kcfi" boot param mode to be selectable through
Kconfigvia the newly introducedCONFIG_CFI_AUTO_DEFAULT.Signed-off-by Kees Cook <[email protected]>
I verified that flipping the configuration does indeed change the default and that 'cfi=' could still be used to override whatever choice was made at compile time. This patch was a perfect excuse to put my new CET enabled test machine to work.
CFI_DEFAULT_AUTO reads a little bit better to me personally but I am not looking to get into painting today :)
Quoted 87 lines
---
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Sami Tolvanen <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Josh Poimboeuf <[email protected]>--- arch/x86/Kconfig | 9 +++++++++ arch/x86/include/asm/cfi.h | 2 +- arch/x86/kernel/alternative.c | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-)arch/x86/Kconfig +9
-0@@ -2424,6 +2424,15 @@ config STRICT_SIGALTSTACK_SIZE Say 'N' unless you want to really enforce this check. +config CFI_AUTO_DEFAULT + bool "Attempt to use FineIBT by default at boot time" + depends on FINEIBT + default y + help + Attempt to use FineIBT by default at boot time. If enabled, + this is the same as booting with "cfi=auto". If disabled, + this is the same as booting with "cfi=kcfi". + source "kernel/livepatch/Kconfig" endmenuarch/x86/include/asm/cfi.h +1
-1@@ -93,7 +93,7 @@* */ enum cfi_mode { -CFI_DEFAULT ,/* FineIBT if hardware has IBT, otherwise kCFI */ +CFI_AUTO ,/* FineIBT if hardware has IBT, otherwise kCFI */ CFI_OFF ,/* Taditional / IBT depending on .config */ CFI_KCFI ,/* Optionally CALL_PADDING, IBT, RETPOLINE */ CFI_FINEIBT ,/* see arch/x86/kernel/alternative.c */ arch/x86/kernel/alternative.c +4
-4@@ -902,8 +902,8 @@ void __init_or_module apply_seal_endbr(s32 *start, s32 *end) { }#endif /* CONFIG_X86_KERNEL_IBT */ -#ifdef CONFIG_FINEIBT -#define __CFI_DEFAULT CFI_DEFAULT +#ifdef CONFIG_CFI_AUTO_DEFAULT +#define __CFI_DEFAULT CFI_AUTO#elif defined(CONFIG_CFI_CLANG )#define __CFI_DEFAULT CFI_KCFI#else @@ -1011,7 +1011,7 @@ static __init int cfi_parse_cmdline(char *str) }if (!strcmp (str,"auto" )) { - cfi_mode =CFI_DEFAULT ; + cfi_mode =CFI_AUTO ; }else if (!strcmp (str,"off" )) { cfi_mode =CFI_OFF ; cfi_rand = false;@@ -1271,7 +1271,7 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline, "FineIBT preamble wrong size: %ld", fineibt_preamble_size))return ; -if (cfi_mode ==CFI_DEFAULT ) { +if (cfi_mode ==CFI_AUTO ) { cfi_mode =CFI_KCFI ;if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT )) cfi_mode =CFI_FINEIBT ;Signature · 1 line
2.34.1
Quoted 7 lines · Nathan Chancellor
Quoted 6 lines · Kees Cook
Since FineIBT performs checking at the destination, it is weaker against attacks that can construct arbitrary executable memory contents. As such, some system builders want to run with FineIBT disabled by default. Allow the "cfi=kcfi" boot param mode to be selectable through
Kconfigvia the newly introducedCONFIG_CFI_AUTO_DEFAULT.
Quoted 6 lines
Quoted 1 line
Signed-off-by Kees Cook <[email protected]>I verified that flipping the configuration does indeed change the default and that 'cfi=' could still be used to override whatever choice was made at compile time. This patch was a perfect excuse to put my new CET enabled test machine to work.
Heh, yeah. I have my one lonely CET system that is only powered on for this sort of testing too. ;)
Quoted 3 lines
Reviewed-by Nathan Chancellor <[email protected]>Tested-by Nathan Chancellor <[email protected]>
Thanks!
Quoted 2 lines
CFI_DEFAULT_AUTOreads a little bit better to me personally but I am not looking to get into painting today :)
I went with CFI_AUTO_DEFAULT since this seems to be our current pattern for setting these kinds of boot param defaults. A selection of examples:
arch/Kconfig:config RANDOMIZE_KSTACK_OFFSET_DEFAULT lib/Kconfig.debug:config CONSOLE_LOGLEVEL_DEFAULT mm/Kconfig.debug:config DEBUG_PAGEALLOC_ENABLE_DEFAULT
Signature · 1 line
Kees Cook
Quoted 9 lines · Kees Cook
Since FineIBT performs checking at the destination, it is weaker against attacks that can construct arbitrary executable memory contents. As such, some system builders want to run with FineIBT disabled by default. Allow the "cfi=kcfi" boot param mode to be selectable through
Kconfigvia the newly introducedCONFIG_CFI_AUTO_DEFAULT.Signed-off-by Kees Cook <[email protected]>---
Sami
Quoted 5 lines
Since FineIBT performs checking at the destination, it is weaker against attacks that can construct arbitrary executable memory contents. As such, some system builders want to run with FineIBT disabled by default. Allow the "cfi=kcfi" boot param mode to be selectable through
Kconfigvia the newly introducedCONFIG_CFI_AUTO_DEFAULT.
I'm confused as why you think that KCFI is stronger/better than FineIBT. The latter is compatible with execute-only memory, makes use of hardware support, doesn't need LTO, is faster, … moreover, I don't see why an attacker able to "construct arbitrary executable memory contents" wouldn't be able to bypass KCFI as well, since its threat model
(https://github.com/kcfi/docs/blob/master/kCFI_whitepaper.pdf)
explicitly says "We assume an OS that fully implements the W^X policy [56,58,106] preventing direct code injection in kernel space."
Quoted 7 lines · jvoisin
Quoted 5 lines
Since FineIBT performs checking at the destination, it is weaker against attacks that can construct arbitrary executable memory contents. As such, some system builders want to run with FineIBT disabled by default. Allow the "cfi=kcfi" boot param mode to be selectable through
Kconfigvia the newly introducedCONFIG_CFI_AUTO_DEFAULT.I'm confused as why you think that KCFI is stronger/better than FineIBT.
Sure, can I try to explain this more.
Quoted 1 line
The latter is compatible with execute-only memory,
Yes, and since Linux doesn't have kernel execute-only memory (and likely won't for some time), it doesn't make sense to use FineIBT over KCFI for that reason.
Quoted 1 line
makes use of hardware support,
Hm? KCFI does too. IBT is still enabled with KCFI (when the hardware supports it).
Quoted 1 line
doesn't need LTO,
KCFI doesn't need LTO either.
Quoted 1 line
is faster,
What? Measured how? I feel like you're thinking about the old Clang CFI, not the modern KCFI implementation.
Quoted 3 lines
… moreover, I don't see why an
attacker able to "construct arbitrary executable memory contents" wouldn't be able to bypass KCFI as well,
To bypass KCFI, the attacker additionally needs a targeted memory exposure to get the correct function hash that they must include before the malicious function they construct. With FineIBT, no such exposure is needed.
Quoted 4 lines
since its threat model
(https://github.com/kcfi/docs/blob/master/kCFI_whitepaper.pdf)
explicitly says "We assume an OS that fully implements the W^X policy [56,58,106] preventing direct code injection in kernel space."
I mean, a whitepaper's threat model is nice and all, but this just isn't the reality. Linux certainly tries to maintain W^X, but there are bugs and things like BPF, which can be manipulated to gain attacker-controlled executable code injected into the kernel address space. (e.g. BPF will flip a writable region from RW to RX, so W^X is maintained spatially but not temporally.)
So without execute-only memory, some deployments prefer to not weaken the CFI implementation to allow for hash checking bypasses. Once X-O exists, FineIBT is a slam-dunk over KCFI. :)
-Kees
Signature · 1 line
Kees Cook