Re: [PATCHv2] x86/alternatives: Disable KASAN in apply_alternatives()

From: Kirill A. Shutemov
Date: Wed Oct 11 2023 - 09:27:32 EST


On Wed, Oct 11, 2023 at 09:46:16AM +0200, Peter Zijlstra wrote:
> On Wed, Oct 11, 2023 at 09:58:49AM +0300, Kirill A. Shutemov wrote:
> > Fei has reported that KASAN triggers during apply_alternatives() on
> > 5-level paging machine:
> >
>
> Urgh @ KASAN splat, can't we summarize that?

What about this?

BUG: KASAN: out-of-bounds in rcu_is_watching
Read of size 4 at addr ff110003ee6419a0 by task swapper/0/0
...
__asan_load4
rcu_is_watching
? text_poke_early
trace_hardirqs_on
? __asan_load4
text_poke_early
apply_alternatives
...

Is it enough details or I overdid summarization?

> > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> > index 517ee01503be..b4cc4d7c0825 100644
> > --- a/arch/x86/kernel/alternative.c
> > +++ b/arch/x86/kernel/alternative.c
> > @@ -403,6 +403,17 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
> > u8 insn_buff[MAX_PATCH_LEN];
> >
> > DPRINTK(ALT, "alt table %px, -> %px", start, end);
> > +
> > + /*
> > + * In the case CONFIG_X86_5LEVEL=y, KASAN_SHADOW_START is defined using
> > + * cpu_feature_enabled(X86_FEATURE_LA57) and is therefore patched here.
> > + * During the process, KASAN becomes confused and triggers
>
> because of partial LA57 convertion ..
>
> > + * a false-positive out-of-bound report.
> > + *
> > + * Disable KASAN until the patching is complete.
> > + */
> > + kasan_disable_current();
> > +
> > /*

/*
* In the case CONFIG_X86_5LEVEL=y, KASAN_SHADOW_START is defined using
* cpu_feature_enabled(X86_FEATURE_LA57) and is therefore patched here.
* During the process, KASAN becomes confused seeing partial LA57
* conversion and triggers a false-positive out-of-bound report.
*
* Disable KASAN until the patching is complete.
*/

Looks good?

If yes, I will submit v3 with your Ack.

--
Kiryl Shutsemau / Kirill A. Shutemov