From 60021b40cb179630c2c7aae90a2a9882a7b18192 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Mon, 25 Jan 2021 15:44:20 +0900 Subject: [PATCH] kmemleak: Fix bad memory access with scan stack for amlogic vmap When AMLOGIC_VMAP is enabled, try_get_task_stack() returns address of stasck instead of page address. This causes bad memory access during kmemleak scan stack. Fix the bad memory access by using aml_task_stack(). Note: Maybe, get_task_stack() needs to call aml_task_stack() is required, but aml_task_stack() has no consideration for kmalloced task stack, so just fix from kmemleak. Change-Id: I58a2e324cb92cd692d2260c675e81d7d0715e96c Fixes: commit 4d6ae4359385 ("mm: optimize thread stack usage on arm64 [1/1]") Signed-off-by: Seung-Woo Kim --- mm/kmemleak.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index d05133b..7eeb84a 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -112,6 +112,10 @@ #include #include +#ifdef CONFIG_AMLOGIC_VMAP +#include +#endif + /* * Kmemleak configuration and common defines. */ @@ -1456,11 +1460,17 @@ static void kmemleak_scan(void) read_lock(&tasklist_lock); do_each_thread(g, p) { +#ifdef CONFIG_AMLOGIC_VMAP + void *stack = aml_task_stack(p); + if (stack) + scan_block(stack, stack + THREAD_SIZE, NULL); +#else void *stack = try_get_task_stack(p); if (stack) { scan_block(stack, stack + THREAD_SIZE, NULL); put_task_stack(p); } +#endif } while_each_thread(g, p); read_unlock(&tasklist_lock); } -- 2.7.4