Skip to contentSkip to conversation

x86/alternatives: fix .init section reference in _apply_alternatives()

PATCH In review Roger Pau Monne 2 participants 3 messages Apr 9, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/alternatives: fix .init section reference in _apply_alternatives()

The code in _apply_alternatives() will unconditionally attempt to read __initdata_cf_clobber_{start,end} when called as part of applying alternatives to a livepatch payload. That leads to a page-fault as __initdata_cf_clobber_{start,end} living in .init section will have been unmapped by the time a livepatch gets loaded.

Fix by adding a check that limits the clobbering of endbr64 instructions to boot time only.

Fixes 37ed5da851b8 ('x86/altcall: Optimise away endbr64 instruction where possible')
---
 xen/arch/x86/alternative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/alternative.c +1 -1
index 21af0e825822..2e7ba6e0b833 100644
@@ -326,7 +326,7 @@ static void init_or_livepatch _apply_alternatives(struct alt_instr *start,
      * Clobber endbr64 instructions now that altcall has finished optimising
      * all indirect branches to direct ones.
      */
-    if ( force && cpu_has_xen_ibt )
+    if ( force && cpu_has_xen_ibt && system_state < SYS_STATE_active )
     {
         void *const *val;
         unsigned int clobbered = 0;
Signature · 1 line
2.44.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Roger Pau Monne

The code in _apply_alternatives() will unconditionally attempt to read __initdata_cf_clobber_{start,end} when called as part of applying alternatives to a livepatch payload.

When CET-IBT is active.

In practice this narrows the impact to ADL/RPL and SPR/EMR.

Quoted 9 lines

That leads to a page-fault as __initdata_cf_clobber_{start,end} living in .init section will have been unmapped by the time a livepatch gets loaded.

Fix by adding a check that limits the clobbering of endbr64 instructions to boot time only.

Fixes 37ed5da851b8 ('x86/altcall: Optimise away endbr64 instruction where possible')

In hindsight I really should have tried livepatching when I was doing the IBT work, but that was also done under an embargo deadline.

I'm happy to tweak the commit message on commit.

#2 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 3 lines · Roger Pau Monne

The code in _apply_alternatives() will unconditionally attempt to read __initdata_cf_clobber_{start,end} when called as part of applying alternatives to a livepatch payload.

When CET-IBT is active.

In practice this narrows the impact to ADL/RPL and SPR/EMR.

Oh, yes, forgot to add that.

Quoted 11 lines
Quoted 10 lines

That leads to a page-fault as __initdata_cf_clobber_{start,end} living in .init section will have been unmapped by the time a livepatch gets loaded.

Fix by adding a check that limits the clobbering of endbr64 instructions to boot time only.

Fixes 37ed5da851b8 ('x86/altcall: Optimise away endbr64 instruction where possible')
Quoted 6 lines

In hindsight I really should have tried livepatching when I was doing the IBT work, but that was also done under an embargo deadline.

I'm happy to tweak the commit message on commit.

Sure, please go ahead.

Thanks, Roger.