summaryrefslogtreecommitdiff
path: root/kernel/kcsan
diff options
context:
space:
mode:
authorMarco Elver <elver@google.com>2020-10-22 14:45:53 +0300
committerPaul E. McKenney <paulmck@kernel.org>2020-11-03 04:08:51 +0300
commit55a2346c7ac4bbf6ee6972394237bf31e29a1c05 (patch)
tree527ef9158e5a4507ea742638aad9d097546f123f /kernel/kcsan
parent4761612ffe3c1655e58f1ef9cf867c6f67d46fe2 (diff)
downloadlinux-55a2346c7ac4bbf6ee6972394237bf31e29a1c05.tar.xz
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. Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'kernel/kcsan')
-rw-r--r--kernel/kcsan/encoding.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/kernel/kcsan/encoding.h b/kernel/kcsan/encoding.h
index 1a6db2f797ac..4f73db6d1407 100644
--- a/kernel/kcsan/encoding.h
+++ b/kernel/kcsan/encoding.h
@@ -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