Page MenuHomeFreeBSD

D40946.id124683.diff
No OneTemporary

D40946.id124683.diff

diff --git a/sys/sys/kassert.h b/sys/sys/kassert.h
--- a/sys/sys/kassert.h
+++ b/sys/sys/kassert.h
@@ -38,6 +38,36 @@
extern bool panicked;
#define KERNEL_PANICKED() __predict_false(panicked)
+/*
+ * Trap accesses going through a pointer. Moreover if kasan is available trap
+ * reading the pointer itself.
+ *
+ * Sample usage: you have a struct with numerous fields and by API contract
+ * only some of them get populated, even if the implementation temporary writes
+ * to them. You can DEBUG_POISON_POINTER so the consumer which should no be
+ * looking at the field gets caught.
+ *
+ * DEBUG_POISON_POINTER(obj->ptr);
+ * ....
+ * if (obj->ptr != NULL) // traps with kasan, does not trap otherwise
+ * ....
+ * obj->ptr->field // traps with and without kasan
+ */
+#ifdef INVARIANTS
+
+#include <sys/asan.h>
+
+#ifdef DEBUG_POISON_POINTER_VALUE
+#define DEBUG_POISON_POINTER(x) ({ \
+ x = (void *)(DEBUG_POISON_POINTER_VALUE); \
+ kasan_mark(&x, 0, sizeof(x), KASAN_GENERIC_REDZONE); \
+})
+#else
+#define DEBUG_POISON_POINTER(x)
+#endif
+
+#endif
+
#ifdef INVARIANTS /* The option is always available */
#define VNASSERT(exp, vp, msg) do { \
if (__predict_false(!(exp))) { \

File Metadata

Mime Type
text/plain
Expires
Tue, Feb 11, 11:09 PM (16 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16602749
Default Alt Text
D40946.id124683.diff (1 KB)

Event Timeline