* [PATCH] x86/alternatives: fix .init section reference in _apply_alternatives()
@ 2024-04-09 12:50 Roger Pau Monne
2024-04-09 12:56 ` Andrew Cooper
0 siblings, 1 reply; 3+ messages in thread
From: Roger Pau Monne @ 2024-04-09 12:50 UTC (permalink / raw)
To: xen-devel; +Cc: Roger Pau Monne, Jan Beulich, Andrew Cooper
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')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
xen/arch/x86/alternative.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c
index 21af0e825822..2e7ba6e0b833 100644
--- a/xen/arch/x86/alternative.c
+++ b/xen/arch/x86/alternative.c
@@ -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;
--
2.44.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] x86/alternatives: fix .init section reference in _apply_alternatives()
2024-04-09 12:50 [PATCH] x86/alternatives: fix .init section reference in _apply_alternatives() Roger Pau Monne
@ 2024-04-09 12:56 ` Andrew Cooper
2024-04-09 13:00 ` Roger Pau Monné
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cooper @ 2024-04-09 12:56 UTC (permalink / raw)
To: Roger Pau Monne, xen-devel; +Cc: Jan Beulich
On 09/04/2024 1:50 pm, Roger Pau Monne wrote:
> 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.
> 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')
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
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.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] x86/alternatives: fix .init section reference in _apply_alternatives()
2024-04-09 12:56 ` Andrew Cooper
@ 2024-04-09 13:00 ` Roger Pau Monné
0 siblings, 0 replies; 3+ messages in thread
From: Roger Pau Monné @ 2024-04-09 13:00 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, Jan Beulich
On Tue, Apr 09, 2024 at 01:56:16PM +0100, Andrew Cooper wrote:
> On 09/04/2024 1:50 pm, Roger Pau Monne wrote:
> > 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.
>
> > 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')
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
>
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-09 13:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09 12:50 [PATCH] x86/alternatives: fix .init section reference in _apply_alternatives() Roger Pau Monne
2024-04-09 12:56 ` Andrew Cooper
2024-04-09 13:00 ` Roger Pau Monné
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.