Skip to content

Commit 1533511

Browse files
pa1guptagregkh
authored andcommitted
x86/ibt: Keep IBT disabled during alternative patching
commit ebebe30 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent bd57853 commit 1533511

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

@@ -1719,6 +1720,8 @@ static noinline void __init alt_reloc_selftest(void)
17191720

17201721
void __init alternative_instructions(void)
17211722
{
1723+
u64 ibt;
1724+
17221725
int3_selftest();
17231726

17241727
/*
@@ -1745,6 +1748,9 @@ void __init alternative_instructions(void)
17451748
*/
17461749
paravirt_set_cap();
17471750

1751+
/* Keep CET-IBT disabled until caller/callee are patched */
1752+
ibt = ibt_save(/*disable*/ true);
1753+
17481754
__apply_fineibt(__retpoline_sites, __retpoline_sites_end,
17491755
__cfi_sites, __cfi_sites_end, true);
17501756

@@ -1768,6 +1774,8 @@ void __init alternative_instructions(void)
17681774
*/
17691775
apply_seal_endbr(__ibt_endbr_seal, __ibt_endbr_seal_end);
17701776

1777+
ibt_restore(ibt);
1778+
17711779
#ifdef CONFIG_SMP
17721780
/* Patch to UP if other cpus not imminent. */
17731781
if (!noreplace_smp && (num_present_cpus() == 1 || setup_max_cpus <= 1)) {

0 commit comments

Comments
 (0)