From b081609ec2de1cc4d306831ad0b9d4bfa5545d4e Mon Sep 17 00:00:00 2001 From: maxv Date: Fri, 8 Nov 2019 12:36:10 +0000 Subject: [PATCH] Exclude the PTE space from KCSAN, since there the same VA can point to different PAs. --- sys/arch/amd64/include/csan.h | 11 ++++++++++- sys/kern/subr_csan.c | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/sys/arch/amd64/include/csan.h b/sys/arch/amd64/include/csan.h index 4ab99ee2d17e..1817bc8fc7cd 100644 --- a/sys/arch/amd64/include/csan.h +++ b/sys/arch/amd64/include/csan.h @@ -1,4 +1,4 @@ -/* $NetBSD: csan.h,v 1.2 2019/11/06 06:57:22 maxv Exp $ */ +/* $NetBSD: csan.h,v 1.3 2019/11/08 12:36:11 maxv Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -30,8 +30,17 @@ */ #include +#include +#include #include +static inline bool +kcsan_md_unsupported(vaddr_t addr) +{ + return (addr >= (vaddr_t)PTE_BASE && + addr < ((vaddr_t)PTE_BASE + NBPD_L4)); +} + static inline bool kcsan_md_is_avail(void) { diff --git a/sys/kern/subr_csan.c b/sys/kern/subr_csan.c index e9814f3c8b06..a869469e221f 100644 --- a/sys/kern/subr_csan.c +++ b/sys/kern/subr_csan.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_csan.c,v 1.2 2019/11/06 06:57:22 maxv Exp $ */ +/* $NetBSD: subr_csan.c,v 1.3 2019/11/08 12:36:10 maxv Exp $ */ /* * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_csan.c,v 1.2 2019/11/06 06:57:22 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_csan.c,v 1.3 2019/11/08 12:36:10 maxv Exp $"); #include "opt_kcsan.h" @@ -136,6 +136,8 @@ kcsan_access(uintptr_t addr, size_t size, bool write, bool atomic, uintptr_t pc) if (__predict_false(!kcsan_enabled)) return; + if (__predict_false(kcsan_md_unsupported((vaddr_t)addr))) + return; new.addr = addr; new.size = size;