kmemleak: Fix bad memory access with scan stack for amlogic vmap 72/252172/1
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 25 Jan 2021 06:44:20 +0000 (15:44 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 25 Jan 2021 06:49:58 +0000 (15:49 +0900)
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 <sw0312.kim@samsung.com>
mm/kmemleak.c

index d05133b..7eeb84a 100644 (file)
 #include <linux/kmemleak.h>
 #include <linux/memory_hotplug.h>
 
+#ifdef CONFIG_AMLOGIC_VMAP
+#include <linux/amlogic/vmap_stack.h>
+#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);
        }