Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109871996
D40946.id130646.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D40946.id130646.diff
View Options
diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -159,6 +159,9 @@
}
caddr_t __read_mostly unmapped_buf;
+#ifdef INVARIANTS
+caddr_t poisoned_buf = (void *)-1;
+#endif
/* Used below and for softdep flushing threads in ufs/ffs/ffs_softdep.c */
struct proc *bufdaemonproc;
@@ -1211,6 +1214,9 @@
mtx_init(&bdirtylock, "dirty buf lock", NULL, MTX_DEF);
unmapped_buf = (caddr_t)kva_alloc(maxphys);
+#ifdef INVARIANTS
+ poisoned_buf = unmapped_buf;
+#endif
/* finally, initialize each buffer header and stick on empty q */
for (i = 0; i < nbuf; i++) {
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,37 @@
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>
+
+extern caddr_t poisoned_buf;
+#define DEBUG_POISON_POINTER_VALUE poisoned_buf
+
+#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
+
#ifdef INVARIANTS /* The option is always available */
#define VNASSERT(exp, vp, msg) do { \
if (__predict_false(!(exp))) { \
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Feb 11, 2:34 PM (7 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16596392
Default Alt Text
D40946.id130646.diff (1 KB)
Attached To
Mode
D40946: Add DEBUG_POISON_POINTER
Attached
Detach File
Event Timeline
Log In to Comment