]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
powerpc: align stack to 2 * THREAD_SIZE with VMAP_STACK
authorChristophe Leroy <christophe.leroy@c-s.fr>
Sat, 21 Dec 2019 08:32:28 +0000 (08:32 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 26 Jan 2020 11:15:09 +0000 (22:15 +1100)
In order to ease stack overflow detection, align
stack to 2 * THREAD_SIZE when using VMAP_STACK.
This allows overflow detection using a single bit check.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/60e9ae86b7d2cdcf21468787076d345663648f46.1576916812.git.christophe.leroy@c-s.fr
arch/powerpc/include/asm/thread_info.h
arch/powerpc/kernel/setup_32.c
arch/powerpc/kernel/setup_64.c
arch/powerpc/kernel/vmlinux.lds.S

index 488d5c4670ff51b0e68d648b7bd2651994fe41f0..a2270749b282ac4758308911262fc0cce35497bb 100644 (file)
 
 #define THREAD_SIZE            (1 << THREAD_SHIFT)
 
+/*
+ * By aligning VMAP'd stacks to 2 * THREAD_SIZE, we can detect overflow by
+ * checking sp & (1 << THREAD_SHIFT), which we can do cheaply in the entry
+ * assembly.
+ */
+#ifdef CONFIG_VMAP_STACK
+#define THREAD_ALIGN_SHIFT     (THREAD_SHIFT + 1)
+#else
+#define THREAD_ALIGN_SHIFT     THREAD_SHIFT
+#endif
+
+#define THREAD_ALIGN           (1 << THREAD_ALIGN_SHIFT)
+
 #ifndef __ASSEMBLY__
 #include <linux/cache.h>
 #include <asm/processor.h>
index dcffe927f5b93ed9f48edb552509d200206c2651..f014c4f7a3371f8c394e411f701029579840a708 100644 (file)
@@ -140,7 +140,7 @@ arch_initcall(ppc_init);
 
 static void *__init alloc_stack(void)
 {
-       void *ptr = memblock_alloc(THREAD_SIZE, THREAD_SIZE);
+       void *ptr = memblock_alloc(THREAD_SIZE, THREAD_ALIGN);
 
        if (!ptr)
                panic("cannot allocate %d bytes for stack at %pS\n",
index 6104917a282d6cdf984e06873b19cc275b6ad73f..e05e6dd67ae6b95244fba873b2d25a0c779850f0 100644 (file)
@@ -633,7 +633,7 @@ static void *__init alloc_stack(unsigned long limit, int cpu)
 
        BUILD_BUG_ON(STACK_INT_FRAME_SIZE % 16);
 
-       ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_SIZE,
+       ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_ALIGN,
                                     MEMBLOCK_LOW_LIMIT, limit,
                                     early_cpu_to_node(cpu));
        if (!ptr)
index 8834220036a51baaa5bd132fc2fb224e882e0a66..b4c89a1acebb83b75b1151e1a29aae89704f66ed 100644 (file)
@@ -323,7 +323,7 @@ SECTIONS
 #endif
 
        /* The initial task and kernel stack */
-       INIT_TASK_DATA_SECTION(THREAD_SIZE)
+       INIT_TASK_DATA_SECTION(THREAD_ALIGN)
 
        .data..page_aligned : AT(ADDR(.data..page_aligned) - LOAD_OFFSET) {
                PAGE_ALIGNED_DATA(PAGE_SIZE)