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 when Xen is using IBT.

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: 37ed5da851 ('x86/altcall: Optimise away endbr64 instruction where possible')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
(cherry picked from commit 4be1fef1e6)
This commit is contained in:
Roger Pau Monné authored and Andrew Cooper committed 2024-04-09 16:48:19 +01:00
1 parent 81ebc5abe7
commit e60fc805d8
1 file changed
+1 -1
+1 -1
View File
@@ -338,7 +338,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;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.