Skip to content

Commit 9502e83

Browse files
pa1guptagregkh
authored andcommitted
x86/ibt: Keep IBT disabled during alternative patching
commit ebebe30794d38c51f71fe4951ba6af4159d9837d 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 <[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 e6da4a8 commit 9502e83

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
@@ -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

@@ -1006,6 +1007,8 @@ static noinline void __init int3_selftest(void)
10061007

10071008
void __init alternative_instructions(void)
10081009
{
1010+
u64 ibt;
1011+
10091012
int3_selftest();
10101013

10111014
/*
@@ -1043,6 +1046,9 @@ void __init alternative_instructions(void)
10431046
*/
10441047
paravirt_set_cap();
10451048

1049+
/* Keep CET-IBT disabled until caller/callee are patched */
1050+
ibt = ibt_save();
1051+
10461052
/*
10471053
* First patch paravirt functions, such that we overwrite the indirect
10481054
* call with the direct call.
@@ -1064,6 +1070,8 @@ void __init alternative_instructions(void)
10641070

10651071
apply_ibt_endbr(__ibt_endbr_seal, __ibt_endbr_seal_end);
10661072

1073+
ibt_restore(ibt);
1074+
10671075
#ifdef CONFIG_SMP
10681076
/* Patch to UP if other cpus not imminent. */
10691077
if (!noreplace_smp && (num_present_cpus() == 1 || setup_max_cpus <= 1)) {

0 commit comments

Comments
 (0)