Skip to contentSkip to conversation

kcsan: Never set up watchpoints on NULL pointers

PATCH In review Marco Elver 1 participant 2 messages Oct 22, 2020 KCSAN

lore
Share & tools
lore

Marco Elver

author maintainer
#0 lore raw

PATCH 1/1 kcsan: Never set up watchpoints on NULL pointers

Avoid setting up watchpoints on NULL pointers, as otherwise we would crash inside the KCSAN runtime (when checking for value changes) instead of the instrumented code.

Because that may be confusing, skip any address less than PAGE_SIZE.

---
 kernel/kcsan/encoding.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/kcsan/encoding.h +5 -1
index f03562aaf2eb..64b3c0f2a685 100644
@@ -48,7 +48,11 @@
 
 static inline bool check_encodable(unsigned long addr, size_t size)
 {
-	return size <= MAX_ENCODABLE_SIZE;
+	/*
+	 * While we can encode addrs<PAGE_SIZE, avoid crashing with a NULL
+	 * pointer deref inside KCSAN.
+	 */
+	return addr >= PAGE_SIZE && size <= MAX_ENCODABLE_SIZE;
 }
 
 static inline long
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
author maintainer
#1 lore raw
Quoted 9 lines · Marco Elver

Avoid setting up watchpoints on NULL pointers, as otherwise we would crash inside the KCSAN runtime (when checking for value changes) instead of the instrumented code.

Because that may be confusing, skip any address less than PAGE_SIZE.

---

Please use the series at:
https://lkml.kernel.org/r/[email protected]
which includes a prerequisite patch that was missing.

Thanks,
-- Marco