Skip to content

Commit 7a63184

Browse files
pa1guptaopsiff
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. [ pawan: Since apply_paravirt() happens before __apply_fineibt() relocates the ENDBR, pv_ops in the example above is not relevant. It is still safer to keep this commit because missing an ENDBR means an oops. ] Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Alexandre Chartre <alexandre.chartre@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 6699bf27a47156baafde7e3f4a732aab2ad9f8cb) Conflicts: arch/x86/kernel/alternative.c
1 parent 37f1148 commit 7a63184

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

arch/x86/kernel/alternative.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <asm/fixmap.h>
3131
#include <asm/paravirt.h>
3232
#include <asm/asm-prototypes.h>
33+
#include <asm/cfi.h>
3334

3435
int __read_mostly alternatives_patched;
3536

@@ -1629,6 +1630,8 @@ static noinline void __init alt_reloc_selftest(void)
16291630

16301631
void __init alternative_instructions(void)
16311632
{
1633+
u64 ibt;
1634+
16321635
int3_selftest();
16331636

16341637
/*
@@ -1669,6 +1672,9 @@ void __init alternative_instructions(void)
16691672
#if defined(CONFIG_NUMA_AWARE_SPINLOCKS)
16701673
cna_configure_spin_lock_slowpath();
16711674
#endif
1675+
1676+
/* Keep CET-IBT disabled until caller/callee are patched */
1677+
ibt = ibt_save(/*disable*/ true);
16721678

16731679
/*
16741680
* First patch paravirt functions, such that we overwrite the indirect
@@ -1703,6 +1709,8 @@ void __init alternative_instructions(void)
17031709
*/
17041710
apply_seal_endbr(__ibt_endbr_seal, __ibt_endbr_seal_end);
17051711

1712+
ibt_restore(ibt);
1713+
17061714
#ifdef CONFIG_SMP
17071715
/* Patch to UP if other cpus not imminent. */
17081716
if (!noreplace_smp && (num_present_cpus() == 1 || setup_max_cpus <= 1)) {

0 commit comments

Comments
 (0)