* [PATCH] powerpc/kasan: Force thread size increase with KASAN
@ 2022-06-01 14:31 Michael Ellerman
2022-06-01 15:54 ` Christophe Leroy
2022-06-09 14:44 ` Michael Ellerman
0 siblings, 2 replies; 3+ messages in thread
From: Michael Ellerman @ 2022-06-01 14:31 UTC (permalink / raw)
To: linuxppc-dev
KASAN causes increased stack usage, which can lead to stack overflows.
The logic in Kconfig to suggest a larger default doesn't work if a user
has CONFIG_EXPERT enabled and has an existing .config with a smaller
value.
Follow the lead of x86 and arm64, and force the thread size to be
increased when KASAN is enabled.
That also has the effect of enlarging the stack for 64-bit KASAN builds,
which is also desirable.
Fixes: edbadaf06710 ("powerpc/kasan: Fix stack overflow by increasing THREAD_SHIFT")
Reported-by: Erhard Furtner <erhard_f@mailbox.org>
Reported-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/Kconfig | 1 -
arch/powerpc/include/asm/thread_info.h | 9 +++++++--
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 54dbbb1d4b36..b1760d615bb7 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -790,7 +790,6 @@ config THREAD_SHIFT
range 13 15
default "15" if PPC_256K_PAGES
default "14" if PPC64
- default "14" if KASAN
default "13"
help
Used to define the stack size. The default is almost always what you
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index 125328d1b980..c9735f93f8e6 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -14,12 +14,17 @@
#ifdef __KERNEL__
-#if defined(CONFIG_VMAP_STACK) && CONFIG_THREAD_SHIFT < PAGE_SHIFT
-#define THREAD_SHIFT PAGE_SHIFT
+#ifdef CONFIG_KASAN
+#define THREAD_SHIFT (CONFIG_THREAD_SHIFT + 1)
#else
#define THREAD_SHIFT CONFIG_THREAD_SHIFT
#endif
+#if defined(CONFIG_VMAP_STACK) && THREAD_SHIFT < PAGE_SHIFT
+#undef THREAD_SHIFT
+#define THREAD_SHIFT PAGE_SHIFT
+#endif
+
#define THREAD_SIZE (1 << THREAD_SHIFT)
/*
--
2.35.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/kasan: Force thread size increase with KASAN
2022-06-01 14:31 [PATCH] powerpc/kasan: Force thread size increase with KASAN Michael Ellerman
@ 2022-06-01 15:54 ` Christophe Leroy
2022-06-09 14:44 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Christophe Leroy @ 2022-06-01 15:54 UTC (permalink / raw)
To: Michael Ellerman, linuxppc-dev
Le 01/06/2022 à 16:31, Michael Ellerman a écrit :
> KASAN causes increased stack usage, which can lead to stack overflows.
>
> The logic in Kconfig to suggest a larger default doesn't work if a user
> has CONFIG_EXPERT enabled and has an existing .config with a smaller
> value.
>
> Follow the lead of x86 and arm64, and force the thread size to be
> increased when KASAN is enabled.
>
> That also has the effect of enlarging the stack for 64-bit KASAN builds,
> which is also desirable.
>
> Fixes: edbadaf06710 ("powerpc/kasan: Fix stack overflow by increasing THREAD_SHIFT")
> Reported-by: Erhard Furtner <erhard_f@mailbox.org>
> Reported-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
> arch/powerpc/Kconfig | 1 -
> arch/powerpc/include/asm/thread_info.h | 9 +++++++--
> 2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 54dbbb1d4b36..b1760d615bb7 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -790,7 +790,6 @@ config THREAD_SHIFT
> range 13 15
> default "15" if PPC_256K_PAGES
> default "14" if PPC64
> - default "14" if KASAN
> default "13"
> help
> Used to define the stack size. The default is almost always what you
> diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
> index 125328d1b980..c9735f93f8e6 100644
> --- a/arch/powerpc/include/asm/thread_info.h
> +++ b/arch/powerpc/include/asm/thread_info.h
> @@ -14,12 +14,17 @@
>
> #ifdef __KERNEL__
>
> -#if defined(CONFIG_VMAP_STACK) && CONFIG_THREAD_SHIFT < PAGE_SHIFT
> -#define THREAD_SHIFT PAGE_SHIFT
> +#ifdef CONFIG_KASAN
> +#define THREAD_SHIFT (CONFIG_THREAD_SHIFT + 1)
> #else
> #define THREAD_SHIFT CONFIG_THREAD_SHIFT
> #endif
>
> +#if defined(CONFIG_VMAP_STACK) && THREAD_SHIFT < PAGE_SHIFT
> +#undef THREAD_SHIFT
I dislike this undef.
I would was done
#ifdef CONFIG_KASAN
#define MIN_THREAD_SHIFT (CONFIG_THREAD_SHIFT + 1)
#else
#define MIN_THREAD_SHIFT CONFIG_THREAD_SHIFT
#endif
#if defined(CONFIG_VMAP_STACK) && MIN_THREAD_SHIFT < PAGE_SHIFT
#define THREAD_SHIFT PAGE_SHIFT
#else
#define THREAD_SHIFT MIN_THREAD_SHIFT
#endif
> +#define THREAD_SHIFT PAGE_SHIFT
> +#endif
> +
> #define THREAD_SIZE (1 << THREAD_SHIFT)
>
> /*
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] powerpc/kasan: Force thread size increase with KASAN
2022-06-01 14:31 [PATCH] powerpc/kasan: Force thread size increase with KASAN Michael Ellerman
2022-06-01 15:54 ` Christophe Leroy
@ 2022-06-09 14:44 ` Michael Ellerman
1 sibling, 0 replies; 3+ messages in thread
From: Michael Ellerman @ 2022-06-09 14:44 UTC (permalink / raw)
To: linuxppc-dev, Michael Ellerman
On Thu, 2 Jun 2022 00:31:14 +1000, Michael Ellerman wrote:
> KASAN causes increased stack usage, which can lead to stack overflows.
>
> The logic in Kconfig to suggest a larger default doesn't work if a user
> has CONFIG_EXPERT enabled and has an existing .config with a smaller
> value.
>
> Follow the lead of x86 and arm64, and force the thread size to be
> increased when KASAN is enabled.
>
> [...]
Applied to powerpc/fixes.
[1/1] powerpc/kasan: Force thread size increase with KASAN
https://git.kernel.org/powerpc/c/3e8635fb2e072672cbc650989ffedf8300ad67fb
cheers
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-09 14:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01 14:31 [PATCH] powerpc/kasan: Force thread size increase with KASAN Michael Ellerman
2022-06-01 15:54 ` Christophe Leroy
2022-06-09 14:44 ` Michael Ellerman
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.