kcsan: Never set up watchpoints on NULL pointers
authorMarco Elver <elver@google.com>
Thu, 22 Oct 2020 11:45:53 +0000 (13:45 +0200)
committerPaul E. McKenney <paulmck@kernel.org>
Tue, 3 Nov 2020 01:08:51 +0000 (17:08 -0800)
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>
kernel/kcsan/encoding.h

index 1a6db2f797ac4a5ef14c695734327fbf9ee19a7f..4f73db6d1407ded3337b1d4478ace4854de1972a 100644 (file)
 
 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