From owner-dev-commits-src-all@freebsd.org Fri Jul 30 01:14:53 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 53E1B65D090; Fri, 30 Jul 2021 01:14:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GbTvx1dhYz3FbX; Fri, 30 Jul 2021 01:14:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 184011BCC3; Fri, 30 Jul 2021 01:14:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 16U1ErcU097404; Fri, 30 Jul 2021 01:14:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16U1EqPT097403; Fri, 30 Jul 2021 01:14:52 GMT (envelope-from git) Date: Fri, 30 Jul 2021 01:14:52 GMT Message-Id: <202107300114.16U1EqPT097403@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 6f179693c5c4 - main - Add interceptors for atomic operations on userspace memory MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6f179693c5c4509a10eb76732dc98a7d01b0582f Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jul 2021 01:14:53 -0000 The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=6f179693c5c4509a10eb76732dc98a7d01b0582f commit 6f179693c5c4509a10eb76732dc98a7d01b0582f Author: Mark Johnston AuthorDate: 2021-07-30 01:05:03 +0000 Commit: Mark Johnston CommitDate: 2021-07-30 01:14:36 +0000 Add interceptors for atomic operations on userspace memory Implement them for KASAN. KCSAN interceptors are left unimplemented for now. MFC after: 2 weeks Sponsored by: The FreeBSD Foundation --- sys/kern/subr_asan.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sys/sys/systm.h | 31 ++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/sys/kern/subr_asan.c b/sys/kern/subr_asan.c index 7083a8e64540..5441d7be39a1 100644 --- a/sys/kern/subr_asan.c +++ b/sys/kern/subr_asan.c @@ -522,6 +522,89 @@ kasan_copyout(const void *kaddr, void *uaddr, size_t len) /* -------------------------------------------------------------------------- */ +int +kasan_fubyte(volatile const void *base) +{ + return (fubyte(base)); +} + +int +kasan_fuword16(volatile const void *base) +{ + return (fuword16(base)); +} + +int +kasan_fueword(volatile const void *base, long *val) +{ + kasan_shadow_check((unsigned long)val, sizeof(*val), true, __RET_ADDR); + return (fueword(base, val)); +} + +int +kasan_fueword32(volatile const void *base, int32_t *val) +{ + kasan_shadow_check((unsigned long)val, sizeof(*val), true, __RET_ADDR); + return (fueword32(base, val)); +} + +int +kasan_fueword64(volatile const void *base, int64_t *val) +{ + kasan_shadow_check((unsigned long)val, sizeof(*val), true, __RET_ADDR); + return (fueword64(base, val)); +} + +int +kasan_subyte(volatile void *base, int byte) +{ + return (subyte(base, byte)); +} + +int +kasan_suword(volatile void *base, long word) +{ + return (suword(base, word)); +} + +int +kasan_suword16(volatile void *base, int word) +{ + return (suword16(base, word)); +} + +int +kasan_suword32(volatile void *base, int32_t word) +{ + return (suword32(base, word)); +} + +int +kasan_suword64(volatile void *base, int64_t word) +{ + return (suword64(base, word)); +} + +int +kasan_casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp, + uint32_t newval) +{ + kasan_shadow_check((unsigned long)oldvalp, sizeof(*oldvalp), true, + __RET_ADDR); + return (casueword32(base, oldval, oldvalp, newval)); +} + +int +kasan_casueword(volatile u_long *base, u_long oldval, u_long *oldvalp, + u_long newval) +{ + kasan_shadow_check((unsigned long)oldvalp, sizeof(*oldvalp), true, + __RET_ADDR); + return (casueword(base, oldval, oldvalp, newval)); +} + +/* -------------------------------------------------------------------------- */ + #include #include diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 671b5c2b8d38..da20492966cd 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -437,6 +437,37 @@ int casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp, int casueword(volatile u_long *p, u_long oldval, u_long *oldvalp, u_long newval); +#if defined(SAN_NEEDS_INTERCEPTORS) && !defined(KCSAN) +int SAN_INTERCEPTOR(fubyte)(volatile const void *base); +int SAN_INTERCEPTOR(fuword16)(volatile const void *base); +int SAN_INTERCEPTOR(fueword)(volatile const void *base, long *val); +int SAN_INTERCEPTOR(fueword32)(volatile const void *base, int32_t *val); +int SAN_INTERCEPTOR(fueword64)(volatile const void *base, int64_t *val); +int SAN_INTERCEPTOR(subyte)(volatile void *base, int byte); +int SAN_INTERCEPTOR(suword)(volatile void *base, long word); +int SAN_INTERCEPTOR(suword16)(volatile void *base, int word); +int SAN_INTERCEPTOR(suword32)(volatile void *base, int32_t word); +int SAN_INTERCEPTOR(suword64)(volatile void *base, int64_t word); +int SAN_INTERCEPTOR(casueword32)(volatile uint32_t *base, uint32_t oldval, + uint32_t *oldvalp, uint32_t newval); +int SAN_INTERCEPTOR(casueword)(volatile u_long *p, u_long oldval, + u_long *oldvalp, u_long newval); +#ifndef SAN_RUNTIME +#define fubyte(b) SAN_INTERCEPTOR(fubyte)((b)) +#define fuword16(b) SAN_INTERCEPTOR(fuword16)((b)) +#define fueword(b, v) SAN_INTERCEPTOR(fueword)((b), (v)) +#define fueword32(b, v) SAN_INTERCEPTOR(fueword32)((b), (v)) +#define fueword64(b, v) SAN_INTERCEPTOR(fueword64)((b), (v)) +#define subyte(b, w) SAN_INTERCEPTOR(subyte)((b), (w)) +#define suword(b, w) SAN_INTERCEPTOR(suword)((b), (w)) +#define suword16(b, w) SAN_INTERCEPTOR(suword16)((b), (w)) +#define suword32(b, w) SAN_INTERCEPTOR(suword32)((b), (w)) +#define suword64(b, w) SAN_INTERCEPTOR(suword64)((b), (w)) +#define casueword32(b, o, p, n) SAN_INTERCEPTOR(casueword32)((b), (o), (p), (n)) +#define casueword(b, o, p, n) SAN_INTERCEPTOR(casueword)((b), (o), (p), (n)) +#endif /* !SAN_RUNTIME */ +#endif /* SAN_NEEDS_INTERCEPTORS && !KCSAN */ + void realitexpire(void *); int sysbeep(int hertz, int period);