[PATCH v6 15/18] khwasan, arm64: add brk handler for inline instrumentation

From
Andrey Konovalov <hidden>
Date
2018-09-17 19:12:04
Also in
linux-doc, linux-kbuild, linux-mm, lkml
Reply to
Dmitry Vyukov, 2018-09-12
On Wed, Sep 12, 2018 at 7:13 PM, Dmitry Vyukov [off-list ref] wrote:
On Wed, Aug 29, 2018 at 1:35 PM, Andrey Konovalov [off-list ref] wrote:
quoted
+static int khwasan_handler(struct pt_regs *regs, unsigned int esr)
+{
+       bool recover = esr & KHWASAN_ESR_RECOVER;
+       bool write = esr & KHWASAN_ESR_WRITE;
+       size_t size = KHWASAN_ESR_SIZE(esr);
+       u64 addr = regs->regs[0];
+       u64 pc = regs->pc;
+
+       if (user_mode(regs))
+               return DBG_HOOK_ERROR;
+
+       kasan_report(addr, size, write, pc);
+
+       /*
+        * The instrumentation allows to control whether we can proceed after
+        * a crash was detected. This is done by passing the -recover flag to
+        * the compiler. Disabling recovery allows to generate more compact
+        * code.
+        *
+        * Unfortunately disabling recovery doesn't work for the kernel right
+        * now. KHWASAN reporting is disabled in some contexts (for example when
+        * the allocator accesses slab object metadata; same is true for KASAN;
+        * this is controlled by current->kasan_depth). All these accesses are
+        * detected by the tool, even though the reports for them are not
+        * printed.

I am not following this part.
Slab accesses metadata. OK.
This is detected as bad access. OK.
Report is not printed. OK.
We skip BRK and resume execution.
What is the problem?
When the kernel is compiled with -fsanitize=kernel-hwaddress without
any additional flags (like it's done now with KASAN_HW) everything
works as you described and there's no problem. However if one were to
recompile the kernel with hwasan recovery disabled, KHWASAN wouldn't
work due to the reasons described in the comment. Should I make it
more clear?

quoted
+        *
+        * This is something that might be fixed at some point in the future.
+        */
+       if (!recover)
+               die("Oops - KHWASAN", regs, 0);
Thread (55 messages) 55 messages, 7 authors, last reply 2018-09-19
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help