Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/amd64/amd64 Rename kasan_shadow_fill, remove one ch...



details:   https://anonhg.NetBSD.org/src/rev/9efd4d51ff53
branches:  trunk
changeset: 445397:9efd4d51ff53
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Oct 27 06:35:54 2018 +0000

description:
Rename kasan_shadow_fill, remove one check in it, and inline it. Remove
the use-after-scope code for now, because our GCC does not support that
and when it does we will want to test the feature for real rather than
letting a potentially broken code compile.

diffstat:

 sys/arch/amd64/amd64/asan.c |  48 ++++++++++++++------------------------------
 1 files changed, 15 insertions(+), 33 deletions(-)

diffs (107 lines):

diff -r a8c3a1219440 -r 9efd4d51ff53 sys/arch/amd64/amd64/asan.c
--- a/sys/arch/amd64/amd64/asan.c       Sat Oct 27 06:06:31 2018 +0000
+++ b/sys/arch/amd64/amd64/asan.c       Sat Oct 27 06:35:54 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: asan.c,v 1.9 2018/10/27 06:06:31 maxv Exp $    */
+/*     $NetBSD: asan.c,v 1.10 2018/10/27 06:35:54 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.9 2018/10/27 06:06:31 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: asan.c,v 1.10 2018/10/27 06:35:54 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -330,13 +330,20 @@
 #define KASAN_STACK_PARTIAL    0xF4
 #define KASAN_USE_AFTER_SCOPE  0xF8
 
-static void
-kasan_shadow_fill(const void *addr, size_t size, uint8_t val)
+static __always_inline void
+kasan_shadow_1byte_markvalid(unsigned long addr)
+{
+       int8_t *byte = kasan_addr_to_shad((void *)addr);
+       int8_t last = (addr & KASAN_SHADOW_MASK) + 1;
+
+       *byte = last;
+}
+
+static __always_inline void
+kasan_shadow_Nbyte_fill(const void *addr, size_t size, uint8_t val)
 {
        void *shad;
 
-       if (__predict_false(!kasan_enabled))
-               return;
        if (__predict_false(size == 0))
                return;
        if (__predict_false(kasan_unsupported((vaddr_t)addr)))
@@ -351,15 +358,6 @@
        __builtin_memset(shad, val, size);
 }
 
-static __always_inline void
-kasan_shadow_1byte_markvalid(unsigned long addr)
-{
-       int8_t *byte = kasan_addr_to_shad((void *)addr);
-       int8_t last = (addr & KASAN_SHADOW_MASK) + 1;
-
-       *byte = last;
-}
-
 void
 kasan_add_redzone(size_t *size)
 {
@@ -380,7 +378,7 @@
                }
        } else {
                KASSERT(size % KASAN_SHADOW_SCALE_SIZE == 0);
-               kasan_shadow_fill(addr, size, KASAN_MEMORY_REDZONE);
+               kasan_shadow_Nbyte_fill(addr, size, KASAN_MEMORY_REDZONE);
        }
 }
 
@@ -389,7 +387,7 @@
 {
        const void *stk = (const void *)uvm_lwp_getuarea(l);
 
-       kasan_shadow_fill(stk, USPACE, 0);
+       kasan_shadow_Nbyte_fill(stk, USPACE, 0);
 }
 
 void
@@ -681,8 +679,6 @@
 void __asan_storeN(unsigned long, size_t);
 void __asan_storeN_noabort(unsigned long, size_t);
 void __asan_handle_no_return(void);
-void __asan_poison_stack_memory(const void *, size_t);
-void __asan_unpoison_stack_memory(const void *, size_t);
 
 void
 __asan_loadN(unsigned long addr, size_t size)
@@ -714,20 +710,6 @@
        /* nothing */
 }
 
-void
-__asan_poison_stack_memory(const void *addr, size_t size)
-{
-       KASSERT((vaddr_t)addr % KASAN_SHADOW_SCALE_SIZE == 0);
-       kasan_shadow_fill(addr, size, KASAN_USE_AFTER_SCOPE);
-}
-
-void
-__asan_unpoison_stack_memory(const void *addr, size_t size)
-{
-       KASSERT((vaddr_t)addr % KASAN_SHADOW_SCALE_SIZE == 0);
-       kasan_shadow_fill(addr, size, 0);
-}
-
 #define ASAN_SET_SHADOW(byte) \
        void __asan_set_shadow_##byte(void *, size_t);                  \
        void __asan_set_shadow_##byte(void *addr, size_t size)          \



Home | Main Index | Thread Index | Old Index