Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit d6f635b

Browse files
committed
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. Reviewed-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Nathan Chancellor <nathan@kernel.org> Tested-by: Nathan Chancellor <nathan@kernel.org> Link: https://lore.kernel.org/r/20240501000218.work.998-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent 51005a5 commit d6f635b

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

arch/x86/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,15 @@ config STRICT_SIGALTSTACK_SIZE
24272427

24282428
Say 'N' unless you want to really enforce this check.
24292429

2430+
config CFI_AUTO_DEFAULT
2431+
bool "Attempt to use FineIBT by default at boot time"
2432+
depends on FINEIBT
2433+
default y
2434+
help
2435+
Attempt to use FineIBT by default at boot time. If enabled,
2436+
this is the same as booting with "cfi=auto". If disabled,
2437+
this is the same as booting with "cfi=kcfi".
2438+
24302439
source "kernel/livepatch/Kconfig"
24312440

24322441
endmenu

arch/x86/include/asm/cfi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
*
9494
*/
9595
enum cfi_mode {
96-
CFI_DEFAULT, /* FineIBT if hardware has IBT, otherwise kCFI */
96+
CFI_AUTO, /* FineIBT if hardware has IBT, otherwise kCFI */
9797
CFI_OFF, /* Taditional / IBT depending on .config */
9898
CFI_KCFI, /* Optionally CALL_PADDING, IBT, RETPOLINE */
9999
CFI_FINEIBT, /* see arch/x86/kernel/alternative.c */

arch/x86/kernel/alternative.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,8 @@ void __init_or_module apply_seal_endbr(s32 *start, s32 *end) { }
885885

886886
#endif /* CONFIG_X86_KERNEL_IBT */
887887

888-
#ifdef CONFIG_FINEIBT
889-
#define __CFI_DEFAULT CFI_DEFAULT
888+
#ifdef CONFIG_CFI_AUTO_DEFAULT
889+
#define __CFI_DEFAULT CFI_AUTO
890890
#elif defined(CONFIG_CFI_CLANG)
891891
#define __CFI_DEFAULT CFI_KCFI
892892
#else
@@ -994,7 +994,7 @@ static __init int cfi_parse_cmdline(char *str)
994994
}
995995

996996
if (!strcmp(str, "auto")) {
997-
cfi_mode = CFI_DEFAULT;
997+
cfi_mode = CFI_AUTO;
998998
} else if (!strcmp(str, "off")) {
999999
cfi_mode = CFI_OFF;
10001000
cfi_rand = false;
@@ -1254,7 +1254,7 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,
12541254
"FineIBT preamble wrong size: %ld", fineibt_preamble_size))
12551255
return;
12561256

1257-
if (cfi_mode == CFI_DEFAULT) {
1257+
if (cfi_mode == CFI_AUTO) {
12581258
cfi_mode = CFI_KCFI;
12591259
if (HAS_KERNEL_IBT && cpu_feature_enabled(X86_FEATURE_IBT))
12601260
cfi_mode = CFI_FINEIBT;

0 commit comments

Comments
 (0)