| From 2e2c39bd5f1a9505a7955bc27451b6bc16225cdd Mon Sep 17 00:00:00 2001 |
| From: "qiankun.wang" <qiankun.wang@amlogic.com> |
| Date: Thu, 1 Dec 2022 15:06:56 +0800 |
| Subject: [PATCH] ARM: stacktrace: don't save non kernel and module calls [2/2] |
| |
| PD#SWPL-101774 |
| |
| Problem: |
| save_stack_trace now record user calls |
| |
| Solution: |
| add kernel_or_module_addr judgement before save stack |
| |
| Verify: |
| t5w 32bit |
| |
| Change-Id: Ie029f6082aa1be33924018ec655267b426054aae |
| Signed-off-by: qiankun.wang <qiankun.wang@amlogic.com> |
| --- |
| arch/arm/kernel/stacktrace.c | 25 +++++++++++++++++++++++++ |
| 1 file changed, 25 insertions(+) |
| |
| diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c |
| index 824774999825..ae8c359abd4f 100644 |
| --- a/arch/arm/kernel/stacktrace.c |
| +++ b/arch/arm/kernel/stacktrace.c |
| @@ -4,6 +4,10 @@ |
| #include <linux/sched/debug.h> |
| #include <linux/stacktrace.h> |
| |
| +#ifdef CONFIG_AMLOGIC_ARM_KASAN |
| +#include <linux/module.h> |
| +#endif |
| + |
| #include <asm/sections.h> |
| #include <asm/stacktrace.h> |
| #include <asm/traps.h> |
| @@ -92,6 +96,17 @@ struct stack_trace_data { |
| unsigned int skip; |
| }; |
| |
| +#ifdef CONFIG_AMLOGIC_ARM_KASAN |
| +static inline bool kernel_or_module_addr(unsigned long addr) |
| +{ |
| + if (addr >= (unsigned long)_stext && addr < (unsigned long)_end) |
| + return true; |
| + if (is_module_address((unsigned long)addr)) |
| + return true; |
| + return false; |
| +} |
| +#endif |
| + |
| static int save_trace(struct stackframe *frame, void *d) |
| { |
| struct stack_trace_data *data = d; |
| @@ -106,7 +121,12 @@ static int save_trace(struct stackframe *frame, void *d) |
| return 0; |
| } |
| |
| +#ifdef CONFIG_AMLOGIC_ARM_KASAN |
| + if (kernel_or_module_addr(addr)) |
| + trace->entries[trace->nr_entries++] = addr; |
| +#else |
| trace->entries[trace->nr_entries++] = addr; |
| +#endif |
| |
| if (trace->nr_entries >= trace->max_entries) |
| return 1; |
| @@ -118,7 +138,12 @@ static int save_trace(struct stackframe *frame, void *d) |
| if ((unsigned long)®s[1] > ALIGN(frame->sp, THREAD_SIZE)) |
| return 0; |
| |
| +#ifdef CONFIG_AMLOGIC_ARM_KASAN |
| + if (kernel_or_module_addr(regs->ARM_pc)) |
| + trace->entries[trace->nr_entries++] = regs->ARM_pc; |
| +#else |
| trace->entries[trace->nr_entries++] = regs->ARM_pc; |
| +#endif |
| |
| return trace->nr_entries >= trace->max_entries; |
| } |
| -- |
| 2.25.1 |
| |