]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
task_stack: Fix end_of_stack() for architectures with upwards-growing stack
authorHelge Deller <deller@gmx.de>
Mon, 4 Oct 2021 22:05:43 +0000 (00:05 +0200)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Thu, 13 Jan 2022 17:42:15 +0000 (18:42 +0100)
BugLink: https://bugs.launchpad.net/bugs/1953387
[ Upstream commit 9cc2fa4f4a92ccc6760d764e7341be46ee8aaaa1 ]

The function end_of_stack() returns a pointer to the last entry of a
stack. For architectures like parisc where the stack grows upwards
return the pointer to the highest address in the stack.

Without this change I faced a crash on parisc, because the stackleak
functionality wrote STACKLEAK_POISON to the lowest address and thus
overwrote the first 4 bytes of the task_struct which included the
TIF_FLAGS.

Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
include/linux/sched/task_stack.h

index 2413427e439c7a4cde1eb8d786837c94f6cefe4b..d10150587d8192f28250dacaa6c08195c8a0333f 100644 (file)
@@ -25,7 +25,11 @@ static inline void *task_stack_page(const struct task_struct *task)
 
 static inline unsigned long *end_of_stack(const struct task_struct *task)
 {
+#ifdef CONFIG_STACK_GROWSUP
+       return (unsigned long *)((unsigned long)task->stack + THREAD_SIZE) - 1;
+#else
        return task->stack;
+#endif
 }
 
 #elif !defined(__HAVE_THREAD_FUNCTIONS)