Skip to content

Commit 4291e9e

Browse files
xairytorvalds
authored andcommitted
kasan, arm64: print report from tag fault handler
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 <[email protected]> Co-developed-by: Vincenzo Frascino <[email protected]> Signed-off-by: Vincenzo Frascino <[email protected]> Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Alexander Potapenko <[email protected]> Tested-by: Vincenzo Frascino <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Branislav Rankov <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Evgenii Stepanov <[email protected]> Cc: Kevin Brodsky <[email protected]> Cc: Marco Elver <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2e903b9 commit 4291e9e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

arch/arm64/mm/fault.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/mm.h>
1515
#include <linux/hardirq.h>
1616
#include <linux/init.h>
17+
#include <linux/kasan.h>
1718
#include <linux/kprobes.h>
1819
#include <linux/uaccess.h>
1920
#include <linux/page-flags.h>
@@ -297,10 +298,23 @@ static void die_kernel_fault(const char *msg, unsigned long addr,
297298
do_exit(SIGKILL);
298299
}
299300

301+
#ifdef CONFIG_KASAN_HW_TAGS
300302
static void report_tag_fault(unsigned long addr, unsigned int esr,
301303
struct pt_regs *regs)
302304
{
305+
bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0;
306+
307+
/*
308+
* SAS bits aren't set for all faults reported in EL1, so we can't
309+
* find out access size.
310+
*/
311+
kasan_report(addr, 0, is_write, regs->pc);
303312
}
313+
#else
314+
/* Tag faults aren't enabled without CONFIG_KASAN_HW_TAGS. */
315+
static inline void report_tag_fault(unsigned long addr, unsigned int esr,
316+
struct pt_regs *regs) { }
317+
#endif
304318

305319
static void do_tag_recovery(unsigned long addr, unsigned int esr,
306320
struct pt_regs *regs)

mm/kasan/report.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ static void print_error_description(struct kasan_access_info *info)
6262
{
6363
pr_err("BUG: KASAN: %s in %pS\n",
6464
get_bug_type(info), (void *)info->ip);
65-
pr_err("%s of size %zu at addr %px by task %s/%d\n",
66-
info->is_write ? "Write" : "Read", info->access_size,
67-
info->access_addr, current->comm, task_pid_nr(current));
65+
if (info->access_size)
66+
pr_err("%s of size %zu at addr %px by task %s/%d\n",
67+
info->is_write ? "Write" : "Read", info->access_size,
68+
info->access_addr, current->comm, task_pid_nr(current));
69+
else
70+
pr_err("%s at addr %px by task %s/%d\n",
71+
info->is_write ? "Write" : "Read",
72+
info->access_addr, current->comm, task_pid_nr(current));
6873
}
6974

7075
static DEFINE_SPINLOCK(report_lock);

0 commit comments

Comments
 (0)