All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kcsan: Never set up watchpoints on NULL pointers
@ 2020-10-22 11:29 Marco Elver
  2020-10-22 11:47 ` Marco Elver
  0 siblings, 1 reply; 2+ messages in thread
From: Marco Elver @ 2020-10-22 11:29 UTC (permalink / raw)
  To: elver, paulmck; +Cc: mark.rutland, dvyukov, kasan-dev, linux-kernel

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.

Signed-off-by: Marco Elver <elver@google.com>
---
 kernel/kcsan/encoding.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/kcsan/encoding.h b/kernel/kcsan/encoding.h
index f03562aaf2eb..64b3c0f2a685 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
-- 
2.29.0.rc1.297.gfa9743e501-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kcsan: Never set up watchpoints on NULL pointers
  2020-10-22 11:29 [PATCH] kcsan: Never set up watchpoints on NULL pointers Marco Elver
@ 2020-10-22 11:47 ` Marco Elver
  0 siblings, 0 replies; 2+ messages in thread
From: Marco Elver @ 2020-10-22 11:47 UTC (permalink / raw)
  To: Marco Elver, Paul E. McKenney
  Cc: Mark Rutland, Dmitry Vyukov, kasan-dev, LKML

On Thu, 22 Oct 2020 at 13:30, Marco Elver <elver@google.com> wrote:
>
> 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.
>
> Signed-off-by: Marco Elver <elver@google.com>
> ---

Please use the series at:
https://lkml.kernel.org/r/20201022114553.2440135-1-elver@google.com
which includes a prerequisite patch that was missing.

Thanks,
-- Marco

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-22 11:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 11:29 [PATCH] kcsan: Never set up watchpoints on NULL pointers Marco Elver
2020-10-22 11:47 ` Marco Elver

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.