From: Alexander Potapenko glider@google.com
mainline inclusion from mainline-v5.12-rc1 commit d3a61f745e0d089a2484740283a434deb6dd4eb5 category: feature bugzilla: 181005 https://gitee.com/openeuler/kernel/issues/I4EUY7
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
-----------------------------------------------
Make it possible to trace KASAN error reporting. A good usecase is watching for trace events from the userspace to detect and process memory corruption reports from the kernel.
Link: https://lkml.kernel.org/r/20210121131915.1331302-4-glider@google.com Signed-off-by: Alexander Potapenko glider@google.com Suggested-by: Marco Elver elver@google.com Cc: Andrey Konovalov andreyknvl@google.com Cc: Dmitry Vyukov dvyukov@google.com Cc: Ingo Molnar mingo@redhat.com Cc: Petr Mladek pmladek@suse.com Cc: Steven Rostedt rostedt@goodmis.org Cc: Sergey Senozhatsky sergey.senozhatsky@gmail.com Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Cc: Vlastimil Babka vbabka@suse.cz Signed-off-by: Andrew Morton akpm@linux-foundation.org Signed-off-by: Linus Torvalds torvalds@linux-foundation.org Conflicts: mm/kasan/report.c [Peng Liu: dependent on db3de8f759c8(rename print_shadow_for_address to print_memory_metadata), adjust context] Signed-off-by: Peng Liu liupeng256@huawei.com Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com
Signed-off-by: Chen Jun chenjun102@huawei.com --- mm/kasan/report.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 00a53f1355ae..5ebad04b5c3b 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -30,6 +30,7 @@ #include <linux/module.h> #include <linux/sched/task_stack.h> #include <linux/uaccess.h> +#include <trace/events/error_report.h>
#include <asm/sections.h>
@@ -90,8 +91,9 @@ static void start_report(unsigned long *flags) pr_err("==================================================================\n"); }
-static void end_report(unsigned long *flags) +static void end_report(unsigned long *flags, unsigned long addr) { + trace_error_report_end(ERROR_DETECTOR_KASAN, addr); pr_err("==================================================================\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); spin_unlock_irqrestore(&report_lock, *flags); @@ -504,7 +506,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) print_address_description(object, tag); pr_err("\n"); print_shadow_for_address(object); - end_report(&flags); + end_report(&flags, (unsigned long)object); }
static void __kasan_report(unsigned long addr, size_t size, bool is_write, @@ -549,7 +551,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, dump_stack(); }
- end_report(&flags); + end_report(&flags, addr); }
bool kasan_report(unsigned long addr, size_t size, bool is_write,