x86/kcfi: Require FRED for FineIBT
PATCH 1/1 x86/kcfi: Require FRED for FineIBT
With what appears to be an unavoidable pivot gadget always present in the kernel (the entry code), FineIBT's lack of caller-side CFI hash validation leaves it critically flawed[1]. Require FRED for FineIBT[2] (and probably should also require eXecute-Only memory too), and default to kCFI when CFI is built in.
---
Cc: Peter Zijlstra <[email protected]>
Cc: Jennifer Miller <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Sami Tolvanen <[email protected]>
Cc: Jann Horn <[email protected]>
Cc: Nathan Chancellor <[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: Josh Poimboeuf <[email protected]>
Cc: "Mike Rapoport (Microsoft)" <[email protected]>
--- arch/x86/Kconfig | 9 +++++---- arch/x86/include/asm/cfi.h | 2 +- arch/x86/kernel/alternative.c | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/Kconfig +5 -4
@@ -2432,12 +2432,13 @@ config STRICT_SIGALTSTACK_SIZE config CFI_AUTO_DEFAULT bool "Attempt to use FineIBT by default at boot time" - depends on FINEIBT + depends on FINEIBT && X86_FRED 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". + Attempt to use FineIBT by default at boot time if supported + and sensible for the hardware. 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"
arch/x86/include/asm/cfi.h +1 -1
@@ -93,7 +93,7 @@* */ enum cfi_mode { -CFI_AUTO ,/* FineIBT if hardware has IBT, otherwise kCFI */ +CFI_AUTO ,/* FineIBT if hardware has IBT, FRED, and XOM */ 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 +3 -1
@@ -1323,7 +1323,9 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,if (cfi_mode ==CFI_AUTO ) { cfi_mode =CFI_KCFI ; -if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT )) +/* FineIBT requires IBT and will only be safe with FRED */ +if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT ) && +cpu_feature_enabled (X86_FEATURE_FRED )) cfi_mode =CFI_FINEIBT ; }
Signature · 1 line
2.34.1
arch/x86/include/asm/cfi.h line 96
Quoted 10 lines · Kees Cook
arch/x86/include/asm/cfi.h +1
-1@@ -93,7 +93,7 @@* */ enum cfi_mode { -CFI_AUTO ,/* FineIBT if hardware has IBT, otherwise kCFI */ +CFI_AUTO ,/* FineIBT if hardware has IBT, FRED, and XOM */
You discuss XOM in the commit message, but there's no check ...
Quoted 8 lines
arch/x86/include/asm/cfi.h +0
-0CFI_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 +0
-0
arch/x86/kernel/alternative.c static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline, · line 1328
Quoted 7 lines
arch/x86/kernel/alternative.c +3
-1@@ -1323,7 +1323,9 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,if (cfi_mode ==CFI_AUTO ) { cfi_mode =CFI_KCFI ; -if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT )) +/* FineIBT requires IBT and will only be safe with FRED */ +if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT ) && +cpu_feature_enabled (X86_FEATURE_FRED ))
... here.
Is this meant to be "/* TODO: wire up XOM */" or is that accounted for somewhere else?
Also, while I hate to come back and contradict myself from earlier...
Architecturally, FineIBT without FRED seems to be no improvement over simple IBT. (I'd love to find some way of hardening the entrypoints, but I can't see a robust way of doing so.)
However, micro-architecturally, FineIBT is still far better than simple IBT for speculation issue, seeing as Intel keep on staunchly refusing to turn off the indirect predictors by default like AMD do.
A security conscious user ought to be using FineIBT for this, given a choice, even if it's not perfect in other regards.
~Andrew
Quoted 32 lines · Andrew Cooper
arch/x86/include/asm/cfi.h line 96
Quoted 10 lines · Kees Cook
arch/x86/include/asm/cfi.h +1
-1@@ -93,7 +93,7 @@* */ enum cfi_mode { -CFI_AUTO ,/* FineIBT if hardware has IBT, otherwise kCFI */ +CFI_AUTO ,/* FineIBT if hardware has IBT, FRED, and XOM */ You discuss XOM in the commit message, but there's no check ...
Quoted 8 lines
arch/x86/include/asm/cfi.h +0
-0CFI_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 +0
-0arch/x86/kernel/alternative.c static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline, · line 1328
Quoted 7 lines
arch/x86/kernel/alternative.c +3
-1@@ -1323,7 +1323,9 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,if (cfi_mode ==CFI_AUTO ) { cfi_mode =CFI_KCFI ; -if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT )) +/* FineIBT requires IBT and will only be safe with FRED */ +if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT ) && +cpu_feature_enabled (X86_FEATURE_FRED ))... here.
Quoted 2 lines
Is this meant to be "/* TODO: wire up XOM */" or is that accounted for somewhere else?
Yeah, I wasn't sure how to best capture that in here. XOM doesn't exist yet for x86... I could add a TODO like that?
Quoted 5 lines
Also, while I hate to come back and contradict myself from earlier...
Architecturally, FineIBT without FRED seems to be no improvement over simple IBT. (I'd love to find some way of hardening the entrypoints, but I can't see a robust way of doing so.)
If you're just looking at IBT, yes. But kCFI (with or without IBT, but without FineIBT) will do hash checking at the call site, which should make it impossible to reach the entrypoints from an indirect call in the first place, as they have no hash preceding them.
Quoted 6 lines
However, micro-architecturally, FineIBT is still far better than simple IBT for speculation issue, seeing as Intel keep on staunchly refusing to turn off the indirect predictors by default like AMD do.
A security conscious user ought to be using FineIBT for this, given a choice, even if it's not perfect in other regards.
A security conscious user should use kCFI without FineIBT. :) But I think we might be thinking about different elements of security. I am focusing on control flow, and I think you're considering speculation?
-Kees
Signature · 1 line
Kees Cook
Quoted 31 lines · Kees Cook
Quoted 30 lines · Andrew Cooper
arch/x86/include/asm/cfi.h line 96
Quoted 10 lines · Kees Cook
arch/x86/include/asm/cfi.h +1
-1@@ -93,7 +93,7 @@* */ enum cfi_mode { -CFI_AUTO ,/* FineIBT if hardware has IBT, otherwise kCFI */ +CFI_AUTO ,/* FineIBT if hardware has IBT, FRED, and XOM */ You discuss XOM in the commit message, but there's no check ...
Quoted 8 lines
arch/x86/include/asm/cfi.h +0
-0CFI_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 +0
-0arch/x86/kernel/alternative.c static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline, · line 1328
Quoted 7 lines
arch/x86/kernel/alternative.c +3
-1@@ -1323,7 +1323,9 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,if (cfi_mode ==CFI_AUTO ) { cfi_mode =CFI_KCFI ; -if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT )) +/* FineIBT requires IBT and will only be safe with FRED */ +if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT ) && +cpu_feature_enabled (X86_FEATURE_FRED ))... here.
Quoted 4 lines
Quoted 2 lines
Is this meant to be "/* TODO: wire up XOM */" or is that accounted for somewhere else?
Yeah, I wasn't sure how to best capture that in here. XOM doesn't exist yet for x86... I could add a TODO like that?
I get the feeling that the PKS series would have an easier time starting with XOM (even if it hard-codes pkey1=xom and avoids the allocator in the short term, seeing as Linux does have a good grasp of where it's executable pages are, and how they're accessed) rather than trying to do general page hiding. The capability is in 3 generations of Intel CPU now.
Quoted 15 lines
Quoted 6 lines
Also, while I hate to come back and contradict myself from earlier...
Architecturally, FineIBT without FRED seems to be no improvement over simple IBT. (I'd love to find some way of hardening the entrypoints, but I can't see a robust way of doing so.)
If you're just looking at IBT, yes. But kCFI (with or without IBT, but without FineIBT) will do hash checking at the call site, which should make it impossible to reach the entrypoints from an indirect call in the first place, as they have no hash preceding them.
Quoted 4 lines
However, micro-architecturally, FineIBT is still far better than simple IBT for speculation issue, seeing as Intel keep on staunchly refusing to turn off the indirect predictors by default like AMD do.
Quoted 5 lines
Quoted 2 lines
A security conscious user ought to be using FineIBT for this, given a choice, even if it's not perfect in other regards.
A security conscious user should use kCFI without FineIBT. :) But I think we might be thinking about different elements of security. I am focusing on control flow, and I think you're considering speculation?
True. The security realist knows they're dammed either way, and gets a stiff drink instead.
~Andrew
Quoted 14 lines · Andrew Cooper
Quoted 13 lines · Kees Cook
Quoted 3 lines · Andrew Cooper
Architecturally, FineIBT without FRED seems to be no improvement over simple IBT. (I'd love to find some way of hardening the entrypoints, but I can't see a robust way of doing so.)
If you're just looking at IBT, yes. But kCFI (with or without IBT, but without FineIBT) will do hash checking at the call site, which should make it impossible to reach the entrypoints from an indirect call in the first place, as they have no hash preceding them.
Quoted 4 lines
However, micro-architecturally, FineIBT is still far better than simple IBT for speculation issue, seeing as Intel keep on staunchly refusing to turn off the indirect predictors by default like AMD do.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
A security conscious user ought to be using FineIBT for this, given a choice, even if it's not perfect in other regards.
A security conscious user should use kCFI without FineIBT. :) But I think we might be thinking about different elements of security. I am focusing on control flow, and I think you're considering speculation?
True. The security realist knows they're dammed either way, and gets a stiff drink instead.
I don't know how any of our livers survive. :)
Signature · 1 line
Kees Cook
The following commit has been merged into the x86/cpu branch of tip:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f12315780faf1cbfe00991077a1e8c8e4c201f3b Gitweb: https://git.kernel.org/tip/f12315780faf1cbfe00991077a1e8c8e4c201f3b Author: Kees Cook <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:22:21 -08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 15:38:11 +01:00
x86/kcfi: Require FRED for FineIBT
With what appears to be an unavoidable pivot gadget always present in the kernel (the entry code), FineIBT's lack of caller-side CFI hash validation leaves it critically flawed:
https://lore.kernel.org/linux-hardening/Z60NwR4w%2F28Z7XUa@ubun/ [1]
Require FRED for FineIBT:
https://lore.kernel.org/linux-hardening/[email protected]/
(and probably should also require eXecute-Only memory too), and default to kCFI when CFI is built in.
--- arch/x86/Kconfig | 9 +++++---- arch/x86/include/asm/cfi.h | 2 +- arch/x86/kernel/alternative.c | 4 +++- 3 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/Kconfig +5 -4
@@ -2427,12 +2427,13 @@ config STRICT_SIGALTSTACK_SIZE config CFI_AUTO_DEFAULT bool "Attempt to use FineIBT by default at boot time" - depends on FINEIBT + depends on FINEIBT && X86_FRED 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". + Attempt to use FineIBT by default at boot time if supported + and sensible for the hardware. 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"
arch/x86/include/asm/cfi.h +1 -1
@@ -93,7 +93,7 @@* */ enum cfi_mode { -CFI_AUTO ,/* FineIBT if hardware has IBT, otherwise kCFI */ +CFI_AUTO ,/* FineIBT if hardware has IBT, FRED, and XOM */ 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 +3 -1
@@ -1302,7 +1302,9 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,if (cfi_mode ==CFI_AUTO ) { cfi_mode =CFI_KCFI ; -if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT )) +/* FineIBT requires IBT and will only be safe with FRED */ +if (HAS_KERNEL_IBT &&cpu_feature_enabled (X86_FEATURE_IBT ) && +cpu_feature_enabled (X86_FEATURE_FRED )) cfi_mode =CFI_FINEIBT ; }
Quoted 8 lines · On Fri, Feb 21, 2025 at 03:08:05PM -0000, tip-bot2 for Kees Cook wrote:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f12315780faf1cbfe00991077a1e8c8e4c201f3b Gitweb: https://git.kernel.org/tip/f12315780faf1cbfe00991077a1e8c8e4c201f3b Author: Kees Cook <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:22:21 -08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 15:38:11 +01:00
Ingo, seriously NO!
Quoted 11 lines · Peter Zijlstra
Quoted 8 lines · On Fri, Feb 21, 2025 at 03:08:05PM -0000, tip-bot2 for Kees Cook wrote:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f12315780faf1cbfe00991077a1e8c8e4c201f3b Gitweb: https://git.kernel.org/tip/f12315780faf1cbfe00991077a1e8c8e4c201f3b Author: Kees Cook <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:22:21 -08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 15:38:11 +01:00Ingo, seriously NO!
I've zapped the commit.
Quoted 11 lines · Peter Zijlstra
Quoted 10 lines · Peter Zijlstra
Quoted 8 lines · On Fri, Feb 21, 2025 at 03:08:05PM -0000, tip-bot2 for Kees Cook wrote:
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f12315780faf1cbfe00991077a1e8c8e4c201f3b Gitweb: https://git.kernel.org/tip/f12315780faf1cbfe00991077a1e8c8e4c201f3b Author: Kees Cook <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:22:21 -08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 15:38:11 +01:00
Quoted 3 lines
Quoted 1 line
Ingo, seriously NO!
I've zapped the commit.
I've also re-integrated tip:master to make sure it doesn't go out to -next. Sorry about that ...
Thanks,
Ingo