kasan, arm64: print report from tag fault handler
authorAndrey Konovalov <andreyknvl@google.com>
Tue, 22 Dec 2020 20:02:13 +0000 (12:02 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 22 Dec 2020 20:55:08 +0000 (12:55 -0800)
Add error reporting for hardware tag-based KASAN.  When
CONFIG_KASAN_HW_TAGS is enabled, print KASAN report from the arm64 tag
fault handler.

SAS bits aren't set in ESR for all faults reported in EL1, so it's
impossible to find out the size of the access the caused the fault.  Adapt
KASAN reporting code to handle this case.

Link: https://lkml.kernel.org/r/b559c82b6a969afedf53b4694b475f0234067a1a.1606161801.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Co-developed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Tested-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Branislav Rankov <Branislav.Rankov@arm.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Marco Elver <elver@google.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/arm64/mm/fault.c
mm/kasan/report.c

index 46ac15249eca89e1223c16938630b5f5aaec1ce8..3c40da479899dbb667f427ce8206c52d35e0c16e 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/mm.h>
 #include <linux/hardirq.h>
 #include <linux/init.h>
+#include <linux/kasan.h>
 #include <linux/kprobes.h>
 #include <linux/uaccess.h>
 #include <linux/page-flags.h>
@@ -297,10 +298,23 @@ static void die_kernel_fault(const char *msg, unsigned long addr,
        do_exit(SIGKILL);
 }
 
+#ifdef CONFIG_KASAN_HW_TAGS
 static void report_tag_fault(unsigned long addr, unsigned int esr,
                             struct pt_regs *regs)
 {
+       bool is_write  = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0;
+
+       /*
+        * SAS bits aren't set for all faults reported in EL1, so we can't
+        * find out access size.
+        */
+       kasan_report(addr, 0, is_write, regs->pc);
 }
+#else
+/* Tag faults aren't enabled without CONFIG_KASAN_HW_TAGS. */
+static inline void report_tag_fault(unsigned long addr, unsigned int esr,
+                                   struct pt_regs *regs) { }
+#endif
 
 static void do_tag_recovery(unsigned long addr, unsigned int esr,
                           struct pt_regs *regs)
index 9a6569a57ca28c559ca939a652a27a251b998699..929fcb2a02046d6af725b632f92a977eba3f00b9 100644 (file)
@@ -62,9 +62,14 @@ static void print_error_description(struct kasan_access_info *info)
 {
        pr_err("BUG: KASAN: %s in %pS\n",
                get_bug_type(info), (void *)info->ip);
-       pr_err("%s of size %zu at addr %px by task %s/%d\n",
-               info->is_write ? "Write" : "Read", info->access_size,
-               info->access_addr, current->comm, task_pid_nr(current));
+       if (info->access_size)
+               pr_err("%s of size %zu at addr %px by task %s/%d\n",
+                       info->is_write ? "Write" : "Read", info->access_size,
+                       info->access_addr, current->comm, task_pid_nr(current));
+       else
+               pr_err("%s at addr %px by task %s/%d\n",
+                       info->is_write ? "Write" : "Read",
+                       info->access_addr, current->comm, task_pid_nr(current));
 }
 
 static DEFINE_SPINLOCK(report_lock);