Module Name: src
Committed By: maxv
Date: Wed Aug 22 17:04:36 UTC 2018
Modified Files:
src/sys/arch/amd64/amd64: asan.c spl.S
Log Message:
Explicitly unpoison the stack when entering a softint.
Softints are the only place where we "discard" a part of the stack: we may
have left the thread without allowing the asan instrumentation to clear
the poison, and in this case, we can get false positives when we hit a
poisoned area of the stack while executing another handler within the same
softint thread.
(I was actually getting a rare false positive in ip6intr.)
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/amd64/amd64/asan.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/amd64/amd64/spl.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/asan.c
diff -u src/sys/arch/amd64/amd64/asan.c:1.3 src/sys/arch/amd64/amd64/asan.c:1.4
--- src/sys/arch/amd64/amd64/asan.c:1.3 Wed Aug 22 12:07:42 2018
+++ src/sys/arch/amd64/amd64/asan.c Wed Aug 22 17:04:36 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: asan.c,v 1.3 2018/08/22 12:07:42 maxv Exp $ */
+/* $NetBSD: asan.c,v 1.4 2018/08/22 17:04:36 maxv Exp $ */
/*
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: asan.c,v 1.3 2018/08/22 12:07:42 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: asan.c,v 1.4 2018/08/22 17:04:36 maxv Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -59,6 +59,7 @@ __KERNEL_RCSID(0, "$NetBSD: asan.c,v 1.3
#define __RET_ADDR (unsigned long)__builtin_return_address(0)
+void kasan_softint(struct lwp *);
void kasan_shadow_map(void *, size_t);
void kasan_early_init(void);
void kasan_init(void);
@@ -323,6 +324,14 @@ kasan_markmem(const void *addr, size_t s
}
void
+kasan_softint(struct lwp *l)
+{
+ const void *stk = (const void *)uvm_lwp_getuarea(l);
+
+ kasan_shadow_fill(stk, USPACE, 0);
+}
+
+void
kasan_alloc(const void *addr, size_t size, size_t sz_with_redz)
{
kasan_markmem(addr, sz_with_redz, false);
Index: src/sys/arch/amd64/amd64/spl.S
diff -u src/sys/arch/amd64/amd64/spl.S:1.35 src/sys/arch/amd64/amd64/spl.S:1.36
--- src/sys/arch/amd64/amd64/spl.S:1.35 Sat Jul 14 14:29:40 2018
+++ src/sys/arch/amd64/amd64/spl.S Wed Aug 22 17:04:36 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: spl.S,v 1.35 2018/07/14 14:29:40 maxv Exp $ */
+/* $NetBSD: spl.S,v 1.36 2018/08/22 17:04:36 maxv Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -65,6 +65,7 @@
*/
#include "opt_ddb.h"
+#include "opt_kasan.h"
#define ALIGN_TEXT .align 16,0x90
@@ -105,6 +106,17 @@ IDTVEC(softintr)
movq L_PCB(%r15),%rcx
movq %rdi,CPUVAR(CURLWP)
+#ifdef KASAN
+ /* clear the new stack */
+ pushq %rax
+ pushq %rdx
+ pushq %rcx
+ callq _C_LABEL(kasan_softint)
+ popq %rcx
+ popq %rdx
+ popq %rax
+#endif
+
/* save old context */
movq %rsp,PCB_RSP(%rcx)
movq %rbp,PCB_RBP(%rcx)