mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jiaxun Yang" <jiaxun.yang@flygoat.com>
To: "Huacai Chen" <chenhuacai@loongson.cn>,
	"Huacai Chen" <chenhuacai@kernel.org>
Cc: loongarch@lists.linux.dev, "Xuefeng Li" <lixuefeng@loongson.cn>,
	"Guo Ren" <guoren@kernel.org>, "Xuerui Wang" <kernel@xen0n.name>,
	linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn
Subject: Re: [PATCH] LoongArch: Disable KASAN if PGDIR_SIZE is too large for cpu_vabits
Date: Wed, 30 Oct 2024 09:05:38 +0000	[thread overview]
Message-ID: <4b6df6db-2f2e-4128-a969-c9dff3345c84@app.fastmail.com> (raw)
In-Reply-To: <20241030081110.3431220-1-chenhuacai@loongson.cn>



在2024年10月30日十月 上午8:11,Huacai Chen写道:
> If PGDIR_SIZE is too large for cpu_vabits, KASAN_SHADOW_END will
> overflow UINTPTR_MAX because KASAN_SHADOW_START/KASAN_SHADOW_END are
> aligned up by PGDIR_SIZE. And then the overflowed KASAN_SHADOW_END looks
> like a user space address.
>
> For example, PGDIR_SIZE of CONFIG_4KB_4LEVEL is 2^39, which is too large
> for Loongson-2K series whose cpu_vabits = 39.
>
> Since CONFIG_4KB_4LEVEL is completely legal for CPUs with cpu_vabits <=
> 39, we just disable KASAN via early return in kasan_init(). Otherwise we
> get a boot failure.
>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>

Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

I was hit by this issue as well.

Thanks
- Jiaxun

> ---
>  arch/loongarch/mm/kasan_init.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/arch/loongarch/mm/kasan_init.c b/arch/loongarch/mm/kasan_init.c
> index 4a0d1880dd71..6bdcc8751d4e 100644
> --- a/arch/loongarch/mm/kasan_init.c
> +++ b/arch/loongarch/mm/kasan_init.c
> @@ -262,6 +262,17 @@ void __init kasan_init(void)
>  	u64 i;
>  	phys_addr_t pa_start, pa_end;
> 
> +	/*
> +	 * If PGDIR_SIZE is too large for cpu_vabits, KASAN_SHADOW_END will
> +	 * overflow UINTPTR_MAX and then looks like a user space address.
> +	 * For example, PGDIR_SIZE of CONFIG_4KB_4LEVEL is 2^39, which is too
> +	 * large for Loongson-2K series whose cpu_vabits = 39.
> +	 */
> +	if (KASAN_SHADOW_END < vm_map_base) {
> +		pr_warn("PGDIR_SIZE too large for cpu_vabits, KernelAddressSanitizer 
> disabled.\n");
> +		return;
> +	}
> +
>  	/*
>  	 * PGD was populated as invalid_pmd_table or invalid_pud_table
>  	 * in pagetable_init() which depends on how many levels of page
> -- 
> 2.43.5

-- 
- Jiaxun

      reply	other threads:[~2024-10-30  9:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30  8:11 Huacai Chen
2024-10-30  9:05 ` Jiaxun Yang [this message]

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=4b6df6db-2f2e-4128-a969-c9dff3345c84@app.fastmail.com \
    --to=jiaxun.yang@flygoat.com \
    --cc=chenhuacai@kernel.org \
    --cc=chenhuacai@loongson.cn \
    --cc=guoren@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lixuefeng@loongson.cn \
    --cc=loongarch@lists.linux.dev \
    --cc=loongson-kernel@lists.loongnix.cn \
    /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

all inboxes | Powered by JetHome®