]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
riscv: Fix kernel stack size when KASAN is enabled
authorAlexandre Ghiti <alexghiti@rivosinc.com>
Tue, 17 Sep 2024 15:03:28 +0000 (17:03 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Oct 2024 10:04:00 +0000 (12:04 +0200)
commit cfb10de18538e383dbc4f3ce7f477ce49287ff3d upstream.

We use Kconfig to select the kernel stack size, doubling the default
size if KASAN is enabled.

But that actually only works if KASAN is selected from the beginning,
meaning that if KASAN config is added later (for example using
menuconfig), CONFIG_THREAD_SIZE_ORDER won't be updated, keeping the
default size, which is not enough for KASAN as reported in [1].

So fix this by moving the logic to compute the right kernel stack into a
header.

Fixes: a7555f6b62e7 ("riscv: stack: Add config of thread stack size")
Reported-by: syzbot+ba9eac24453387a9d502@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000eb301906222aadc2@google.com/ [1]
Cc: stable@vger.kernel.org
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20240917150328.59831-1-alexghiti@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/riscv/Kconfig
arch/riscv/include/asm/thread_info.h

index 846c0c4ac4dde3b03876f3fac19e52b12cee9cac..d11c2479d8e17002bd97055e388f204dcc909e12 100644 (file)
@@ -763,8 +763,7 @@ config IRQ_STACKS
 config THREAD_SIZE_ORDER
        int "Kernel stack size (in power-of-two numbers of page size)" if VMAP_STACK && EXPERT
        range 0 4
-       default 1 if 32BIT && !KASAN
-       default 3 if 64BIT && KASAN
+       default 1 if 32BIT
        default 2
        help
          Specify the Pages of thread stack size (from 4KB to 64KB), which also
index fca5c6be2b8112ff6962a51ef0f89794a332f1a4..385b43211a71dc4fcb0c637e59a341129a30c531 100644 (file)
 #include <linux/sizes.h>
 
 /* thread information allocation */
-#define THREAD_SIZE_ORDER      CONFIG_THREAD_SIZE_ORDER
+#ifdef CONFIG_KASAN
+#define KASAN_STACK_ORDER      1
+#else
+#define KASAN_STACK_ORDER      0
+#endif
+#define THREAD_SIZE_ORDER      (CONFIG_THREAD_SIZE_ORDER + KASAN_STACK_ORDER)
 #define THREAD_SIZE            (PAGE_SIZE << THREAD_SIZE_ORDER)
 
 /*