From: Peter Zijlstra <peterz@infradead.org>
To: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
Fei Yang <fei.yang@intel.com>,
stable@vger.kernel.org
Subject: Re: [PATCHv2] x86/alternatives: Disable KASAN in apply_alternatives()
Date: Wed, 11 Oct 2023 09:46:16 +0200 [thread overview]
Message-ID: <20231011074616.GL14330@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20231011065849.19075-1-kirill.shutemov@linux.intel.com>
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?
>
> On machines with 5-level paging, cpu_feature_enabled(X86_FEATURE_LA57)
> got patched. It includes KASAN code, where KASAN_SHADOW_START depends on
> __VIRTUAL_MASK_SHIFT, which is defined with the cpu_feature_enabled().
>
> KASAN gets confused when apply_alternatives() patches the
> KASAN_SHADOW_START users. A test patch that makes KASAN_SHADOW_START
> static, by replacing __VIRTUAL_MASK_SHIFT with 56, fixes the issue.
>
> Disable KASAN while kernel patches alternatives.
>
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Reported-by: Fei Yang <fei.yang@intel.com>
> Fixes: 6657fca06e3f ("x86/mm: Allow to boot without LA57 if CONFIG_X86_5LEVEL=y")
> Cc: stable@vger.kernel.org
> ---
>
> v2:
> - Move kasan_disable/_enable_current() to cover whole loop, not only
> text_poke_early();
> - Adjust commit message.
>
> ---
> arch/x86/kernel/alternative.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> 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();
> +
> /*
> * The scan order should be from start to end. A later scanned
> * alternative code can overwrite previously scanned alternative code.
> @@ -452,6 +463,8 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,
>
> text_poke_early(instr, insn_buff, insn_buff_sz);
> }
> +
> + kasan_enable_current();
> }
Other than that, ACK.
next prev parent reply other threads:[~2023-10-11 7:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 6:58 [PATCHv2] x86/alternatives: Disable KASAN in apply_alternatives() Kirill A. Shutemov
2023-10-11 7:46 ` Peter Zijlstra [this message]
2023-10-11 8:11 ` Ingo Molnar
2023-10-11 9:37 ` Peter Zijlstra
2023-10-11 13:27 ` Kirill A. Shutemov
2023-10-11 20:45 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231011074616.GL14330@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=andreyknvl@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dvyukov@google.com \
--cc=fei.yang@intel.com \
--cc=glider@google.com \
--cc=hpa@zytor.com \
--cc=kasan-dev@googlegroups.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=ryabinin.a.a@gmail.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox