Skip to content

Commit ebebe30

Browse files
pa1guptahansendc
authored andcommitted
x86/ibt: Keep IBT disabled during alternative patching
cfi_rewrite_callers() updates the fineIBT hash matching at the caller side, but except for paranoid-mode it relies on apply_retpoline() and friends for any ENDBR relocation. This could temporarily cause an indirect branch to land on a poisoned ENDBR. For instance, with para-virtualization enabled, a simple wrmsrl() could have an indirect branch pointing to native_write_msr() who's ENDBR has been relocated due to fineIBT: <wrmsrl>: push %rbp mov %rsp,%rbp mov %esi,%eax mov %rsi,%rdx shr $0x20,%rdx mov %edi,%edi mov %rax,%rsi call *0x21e65d0(%rip) # <pv_ops+0xb8> ^^^^^^^^^^^^^^^^^^^^^^^ Such an indirect call during the alternative patching could #CP if the caller is not *yet* adjusted for the new target ENDBR. To prevent a false #CP, keep CET-IBT disabled until all callers are patched. Patching during the module load does not need to be guarded by IBT-disable because the module code is not executed until the patching is complete. Signed-off-by: Pawan Gupta <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Alexandre Chartre <[email protected]>
1 parent d6d1e3e commit ebebe30

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/x86/kernel/alternative.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <asm/paravirt.h>
3232
#include <asm/asm-prototypes.h>
3333
#include <asm/cfi.h>
34+
#include <asm/ibt.h>
3435

3536
int __read_mostly alternatives_patched;
3637

@@ -2085,6 +2086,8 @@ static noinline void __init alt_reloc_selftest(void)
20852086

20862087
void __init alternative_instructions(void)
20872088
{
2089+
u64 ibt;
2090+
20882091
int3_selftest();
20892092

20902093
/*
@@ -2111,6 +2114,9 @@ void __init alternative_instructions(void)
21112114
*/
21122115
paravirt_set_cap();
21132116

2117+
/* Keep CET-IBT disabled until caller/callee are patched */
2118+
ibt = ibt_save(/*disable*/ true);
2119+
21142120
__apply_fineibt(__retpoline_sites, __retpoline_sites_end,
21152121
__cfi_sites, __cfi_sites_end, true);
21162122

@@ -2134,6 +2140,8 @@ void __init alternative_instructions(void)
21342140
*/
21352141
apply_seal_endbr(__ibt_endbr_seal, __ibt_endbr_seal_end);
21362142

2143+
ibt_restore(ibt);
2144+
21372145
#ifdef CONFIG_SMP
21382146
/* Patch to UP if other cpus not imminent. */
21392147
if (!noreplace_smp && (num_present_cpus() == 1 || setup_max_cpus <= 1)) {

0 commit comments

Comments
 (0)