All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE
@ 2020-10-22 11:45 Marco Elver
  2020-10-22 11:45 ` [PATCH v2 2/2] kcsan: Never set up watchpoints on NULL pointers Marco Elver
  2020-10-22 15:01 ` [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE Dmitry Vyukov
  0 siblings, 2 replies; 4+ messages in thread
From: Marco Elver @ 2020-10-22 11:45 UTC (permalink / raw)
  To: elver, paulmck; +Cc: mark.rutland, dvyukov, kasan-dev, linux-kernel

In preparation of supporting only addresses not within the NULL page,
change the selftest to never use addresses that are less than PAGE_SIZE.

Signed-off-by: Marco Elver <elver@google.com>
---
v2:
* Introduce patch to series.
---
 kernel/kcsan/selftest.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/kcsan/selftest.c b/kernel/kcsan/selftest.c
index d98bc208d06d..9014a3a82cf9 100644
--- a/kernel/kcsan/selftest.c
+++ b/kernel/kcsan/selftest.c
@@ -33,6 +33,9 @@ static bool test_encode_decode(void)
 		unsigned long addr;
 
 		prandom_bytes(&addr, sizeof(addr));
+		if (addr < PAGE_SIZE)
+			addr = PAGE_SIZE;
+
 		if (WARN_ON(!check_encodable(addr, size)))
 			return false;
 
-- 
2.29.0.rc1.297.gfa9743e501-goog


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

* [PATCH v2 2/2] kcsan: Never set up watchpoints on NULL pointers
  2020-10-22 11:45 [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE Marco Elver
@ 2020-10-22 11:45 ` Marco Elver
  2020-10-22 15:02   ` Dmitry Vyukov
  2020-10-22 15:01 ` [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE Dmitry Vyukov
  1 sibling, 1 reply; 4+ messages in thread
From: Marco Elver @ 2020-10-22 11:45 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] 4+ messages in thread

* Re: [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE
  2020-10-22 11:45 [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE Marco Elver
  2020-10-22 11:45 ` [PATCH v2 2/2] kcsan: Never set up watchpoints on NULL pointers Marco Elver
@ 2020-10-22 15:01 ` Dmitry Vyukov
  1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Vyukov @ 2020-10-22 15:01 UTC (permalink / raw)
  To: Marco Elver; +Cc: Paul E. McKenney, Mark Rutland, kasan-dev, LKML

On Thu, Oct 22, 2020 at 1:45 PM Marco Elver <elver@google.com> wrote:
>
> In preparation of supporting only addresses not within the NULL page,
> change the selftest to never use addresses that are less than PAGE_SIZE.
>
> Signed-off-by: Marco Elver <elver@google.com>

Reviewed-by: Dmitry Vyukov <dvyukov@google.com>

> ---
> v2:
> * Introduce patch to series.
> ---
>  kernel/kcsan/selftest.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/kernel/kcsan/selftest.c b/kernel/kcsan/selftest.c
> index d98bc208d06d..9014a3a82cf9 100644
> --- a/kernel/kcsan/selftest.c
> +++ b/kernel/kcsan/selftest.c
> @@ -33,6 +33,9 @@ static bool test_encode_decode(void)
>                 unsigned long addr;
>
>                 prandom_bytes(&addr, sizeof(addr));
> +               if (addr < PAGE_SIZE)
> +                       addr = PAGE_SIZE;
> +
>                 if (WARN_ON(!check_encodable(addr, size)))
>                         return false;
>
> --
> 2.29.0.rc1.297.gfa9743e501-goog
>

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

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

On Thu, Oct 22, 2020 at 1:45 PM 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>

Reviewed-by: Dmitry Vyukov <dvyukov@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	[flat|nested] 4+ messages in thread

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 11:45 [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE Marco Elver
2020-10-22 11:45 ` [PATCH v2 2/2] kcsan: Never set up watchpoints on NULL pointers Marco Elver
2020-10-22 15:02   ` Dmitry Vyukov
2020-10-22 15:01 ` [PATCH v2 1/2] kcsan: selftest: Ensure that address is at least PAGE_SIZE Dmitry Vyukov

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.