git: 1f6b6cf1774c - main - atomic: Intercept atomic_(load|store)_bool for kernel sanitizers
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 29 Oct 2022 15:11:19 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=1f6b6cf1774c4f173df1cde3e5cff459f340c95f
commit 1f6b6cf1774c4f173df1cde3e5cff459f340c95f
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-10-29 15:02:02 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-10-29 15:10:58 +0000
atomic: Intercept atomic_(load|store)_bool for kernel sanitizers
Fixes: 2bed73739aac ("atomic: Add plain atomic_load/store_bool()")
---
sys/kern/subr_asan.c | 2 ++
sys/kern/subr_csan.c | 3 +++
sys/kern/subr_msan.c | 2 ++
sys/sys/atomic_san.h | 18 ++++++++++++++++--
4 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/sys/kern/subr_asan.c b/sys/kern/subr_asan.c
index e727c1d03dd7..8a70b525648b 100644
--- a/sys/kern/subr_asan.c
+++ b/sys/kern/subr_asan.c
@@ -843,6 +843,7 @@ ASAN_ATOMIC_FUNC_FCMPSET(int, u_int);
ASAN_ATOMIC_FUNC_FCMPSET(long, u_long);
ASAN_ATOMIC_FUNC_FCMPSET(ptr, uintptr_t);
+_ASAN_ATOMIC_FUNC_LOAD(bool, bool);
ASAN_ATOMIC_FUNC_LOAD(8, uint8_t);
ASAN_ATOMIC_FUNC_LOAD(16, uint16_t);
ASAN_ATOMIC_FUNC_LOAD(32, uint32_t);
@@ -853,6 +854,7 @@ ASAN_ATOMIC_FUNC_LOAD(int, u_int);
ASAN_ATOMIC_FUNC_LOAD(long, u_long);
ASAN_ATOMIC_FUNC_LOAD(ptr, uintptr_t);
+_ASAN_ATOMIC_FUNC_STORE(bool, bool);
ASAN_ATOMIC_FUNC_STORE(8, uint8_t);
ASAN_ATOMIC_FUNC_STORE(16, uint16_t);
ASAN_ATOMIC_FUNC_STORE(32, uint32_t);
diff --git a/sys/kern/subr_csan.c b/sys/kern/subr_csan.c
index 1ae8dd614222..8723777ce84b 100644
--- a/sys/kern/subr_csan.c
+++ b/sys/kern/subr_csan.c
@@ -520,6 +520,9 @@ kcsan_copyout(const void *kaddr, void *uaddr, size_t len)
return (atomic_testandset_##name(ptr, val)); \
}
+_CSAN_ATOMIC_FUNC_LOAD(bool, bool)
+_CSAN_ATOMIC_FUNC_STORE(bool, bool)
+
CSAN_ATOMIC_FUNC_ADD(8, uint8_t)
CSAN_ATOMIC_FUNC_CLEAR(8, uint8_t)
CSAN_ATOMIC_FUNC_CMPSET(8, uint8_t)
diff --git a/sys/kern/subr_msan.c b/sys/kern/subr_msan.c
index 816f38fc74cb..236693cfd841 100644
--- a/sys/kern/subr_msan.c
+++ b/sys/kern/subr_msan.c
@@ -1375,6 +1375,7 @@ MSAN_ATOMIC_FUNC_FCMPSET(int, u_int);
MSAN_ATOMIC_FUNC_FCMPSET(long, u_long);
MSAN_ATOMIC_FUNC_FCMPSET(ptr, uintptr_t);
+_MSAN_ATOMIC_FUNC_LOAD(bool, bool);
MSAN_ATOMIC_FUNC_LOAD(8, uint8_t);
MSAN_ATOMIC_FUNC_LOAD(16, uint16_t);
MSAN_ATOMIC_FUNC_LOAD(32, uint32_t);
@@ -1385,6 +1386,7 @@ MSAN_ATOMIC_FUNC_LOAD(int, u_int);
MSAN_ATOMIC_FUNC_LOAD(long, u_long);
MSAN_ATOMIC_FUNC_LOAD(ptr, uintptr_t);
+_MSAN_ATOMIC_FUNC_STORE(bool, bool);
MSAN_ATOMIC_FUNC_STORE(8, uint8_t);
MSAN_ATOMIC_FUNC_STORE(16, uint16_t);
MSAN_ATOMIC_FUNC_STORE(32, uint32_t);
diff --git a/sys/sys/atomic_san.h b/sys/sys/atomic_san.h
index b0790962d8bd..1f7d615ebd11 100644
--- a/sys/sys/atomic_san.h
+++ b/sys/sys/atomic_san.h
@@ -65,11 +65,15 @@
type sp##_atomic_readandclear_##name(volatile type *)
#define ATOMIC_SAN_LOAD(sp, name, type) \
- type sp##_atomic_load_##name(volatile type *); \
+ type sp##_atomic_load_##name(volatile type *)
+
+#define ATOMIC_SAN_LOAD_ACQ(sp, name, type) \
type sp##_atomic_load_acq_##name(volatile type *)
#define ATOMIC_SAN_STORE(sp, name, type) \
- void sp##_atomic_store_##name(volatile type *, type); \
+ void sp##_atomic_store_##name(volatile type *, type)
+
+#define ATOMIC_SAN_STORE_REL(sp, name, type) \
void sp##_atomic_store_rel_##name(volatile type *, type)
#define ATOMIC_SAN_TEST(sp, op, name, type) \
@@ -86,6 +90,10 @@
#define ATOMIC_SAN_THREAD_FENCE(sp) \
_ATOMIC_SAN_THREAD_FENCE(sp)
+#define ATOMIC_SAN_LOAD_STORE(sp, name, type) \
+ ATOMIC_SAN_LOAD(sp, name, type); \
+ ATOMIC_SAN_STORE(sp, name, type)
+
#define _ATOMIC_SAN_FUNCS(sp, name, type) \
ATOMIC_SAN_FUNC_1(sp, add, name, type); \
ATOMIC_SAN_FUNC_1(sp, clear, name, type); \
@@ -93,10 +101,12 @@
ATOMIC_SAN_FCMPSET(sp, name, type); \
ATOMIC_SAN_READ(sp, fetchadd, name, type); \
ATOMIC_SAN_LOAD(sp, name, type); \
+ ATOMIC_SAN_LOAD_ACQ(sp, name, type); \
ATOMIC_SAN_READANDCLEAR(sp, name, type); \
ATOMIC_SAN_FUNC_1(sp, set, name, type); \
ATOMIC_SAN_FUNC_1(sp, subtract, name, type); \
ATOMIC_SAN_STORE(sp, name, type); \
+ ATOMIC_SAN_STORE_REL(sp, name, type); \
ATOMIC_SAN_READ(sp, swap, name, type); \
ATOMIC_SAN_TEST(sp, testandclear, name, type); \
ATOMIC_SAN_TEST(sp, testandset, name, type)
@@ -113,6 +123,7 @@ ATOMIC_SAN_FUNCS(8, uint8_t);
ATOMIC_SAN_FUNCS(16, uint16_t);
ATOMIC_SAN_FUNCS(32, uint32_t);
ATOMIC_SAN_FUNCS(64, uint64_t);
+ATOMIC_SAN_LOAD_STORE(SAN_INTERCEPTOR_PREFIX, bool, bool);
ATOMIC_SAN_THREAD_FENCE(SAN_INTERCEPTOR_PREFIX);
#ifndef SAN_RUNTIME
@@ -125,6 +136,9 @@ ATOMIC_SAN_THREAD_FENCE(SAN_INTERCEPTOR_PREFIX);
#define ATOMIC_SAN(func) \
__CONCAT(SAN_INTERCEPTOR_PREFIX, __CONCAT(_atomic_, func))
+#define atomic_load_bool ATOMIC_SAN(load_bool)
+#define atomic_store_bool ATOMIC_SAN(store_bool)
+
#define atomic_add_char ATOMIC_SAN(add_char)
#define atomic_add_acq_char ATOMIC_SAN(add_acq_char)
#define atomic_add_rel_char ATOMIC_SAN(add_rel_char)