aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2022-10-29 15:02:02 +0000
committerMark Johnston <markj@FreeBSD.org>2022-11-14 19:24:47 +0000
commit54fe9183c8f995b3b6811d1302a166405dce9af2 (patch)
tree80a9988afedd01e6fbfcd0e1555d3f528d94257b
parent1e3927b93b575d648fe69858782794f4a717bacd (diff)
downloadsrc-54fe9183c8f995b3b6811d1302a166405dce9af2.tar.gz
src-54fe9183c8f995b3b6811d1302a166405dce9af2.zip
atomic: Intercept atomic_(load|store)_bool for kernel sanitizers
Fixes: 2bed73739aac ("atomic: Add plain atomic_load/store_bool()") (cherry picked from commit 1f6b6cf1774c4f173df1cde3e5cff459f340c95f)
-rw-r--r--sys/kern/subr_asan.c2
-rw-r--r--sys/kern/subr_csan.c3
-rw-r--r--sys/sys/atomic_san.h18
3 files changed, 21 insertions, 2 deletions
diff --git a/sys/kern/subr_asan.c b/sys/kern/subr_asan.c
index 30b05c54cd16..2f0334cf52be 100644
--- a/sys/kern/subr_asan.c
+++ b/sys/kern/subr_asan.c
@@ -754,6 +754,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);
@@ -764,6 +765,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 7bed25076fa9..3a542207fbfb 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/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)