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 Fix the computation in kasan_shadow_map...



details:   https://anonhg.NetBSD.org/src/rev/9cb0d660b483
branches:  trunk
changeset: 365574:9cb0d660b483
user:      maxv <maxv%NetBSD.org@localhost>
date:      Wed Aug 22 09:11:47 2018 +0000

description:
Fix the computation in kasan_shadow_map, we may need one more page because
of the rounddown.

diffstat:

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

diffs (49 lines):

diff -r e867f335afbb -r 9cb0d660b483 sys/arch/amd64/amd64/asan.c
--- a/sys/arch/amd64/amd64/asan.c       Wed Aug 22 07:47:33 2018 +0000
+++ b/sys/arch/amd64/amd64/asan.c       Wed Aug 22 09:11:47 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: asan.c,v 1.1 2018/08/20 15:04:51 maxv Exp $    */
+/*     $NetBSD: asan.c,v 1.2 2018/08/22 09:11:47 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.1 2018/08/20 15:04:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: asan.c,v 1.2 2018/08/22 09:11:47 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -109,17 +109,24 @@
 kasan_shadow_map(void *addr, size_t size)
 {
        size_t sz, npages, i;
-       vaddr_t va;
+       vaddr_t sva, eva;
 
-       va = (vaddr_t)kasan_addr_to_shad(addr);
+       KASSERT((vaddr_t)addr % KASAN_SHADOW_SCALE_SIZE == 0);
+
        sz = roundup(size, KASAN_SHADOW_SCALE_SIZE) / KASAN_SHADOW_SCALE_SIZE;
-       va = rounddown(va, PAGE_SIZE);
-       npages = roundup(sz, PAGE_SIZE) / PAGE_SIZE;
+
+       sva = (vaddr_t)kasan_addr_to_shad(addr);
+       eva = (vaddr_t)kasan_addr_to_shad(addr) + sz;
 
-       KASSERT(va >= KASAN_SHADOW_START && va < KASAN_SHADOW_END);
+       sva = rounddown(sva, PAGE_SIZE);
+       eva = roundup(eva, PAGE_SIZE);
+
+       npages = (eva - sva) / PAGE_SIZE;
+
+       KASSERT(sva >= KASAN_SHADOW_START && eva < KASAN_SHADOW_END);
 
        for (i = 0; i < npages; i++) {
-               kasan_shadow_map_page(va + i * PAGE_SIZE);
+               kasan_shadow_map_page(sva + i * PAGE_SIZE);
        }
 }
 



Home | Main Index | Thread Index | Old Index