diff mbox series

[RFC,v3,12/36] kmsan: define READ_ONCE_NOCHECK()

Message ID 20191122112621.204798-13-glider@google.com (mailing list archive)
State New, archived
Headers show
Series Add KernelMemorySanitizer infrastructure | expand

Commit Message

Alexander Potapenko Nov. 22, 2019, 11:25 a.m. UTC
READ_ONCE_NOCHECK() is already used by KASAN to ignore memory accesses
from e.g. stack unwinders.
Define READ_ONCE_NOCHECK() for KMSAN so that it returns initialized
values. This helps defeat false positives from leftover stack contents.

Signed-off-by: Alexander Potapenko <glider@google.com>
To: Alexander Potapenko <glider@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: linux-mm@kvack.org
---
v3:
 - removed unnecessary #ifdef as requested by Mark Rutland

Change-Id: Ib38369ba038ab3b581d8e45b81036c3304fb79cb
---
 include/linux/compiler.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Marco Elver Dec. 2, 2019, 10:03 a.m. UTC | #1
On Fri, 22 Nov 2019 at 12:27, <glider@google.com> wrote:
>
> READ_ONCE_NOCHECK() is already used by KASAN to ignore memory accesses
> from e.g. stack unwinders.
> Define READ_ONCE_NOCHECK() for KMSAN so that it returns initialized
> values. This helps defeat false positives from leftover stack contents.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>
> To: Alexander Potapenko <glider@google.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Vegard Nossum <vegard.nossum@oracle.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: linux-mm@kvack.org
> ---
> v3:
>  - removed unnecessary #ifdef as requested by Mark Rutland
>
> Change-Id: Ib38369ba038ab3b581d8e45b81036c3304fb79cb
> ---
>  include/linux/compiler.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index 5e88e7e33abe..99d40f31a2c3 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -270,9 +270,9 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
>
>  /*
>   * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need
> - * to hide memory access from KASAN.
> + * to hide memory access from KASAN or KMSAN.
>   */
> -#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
> +#define READ_ONCE_NOCHECK(x) KMSAN_INIT_VALUE(__READ_ONCE(x, 0))

I think this needs:
    #include <linux/kmsan-checks.h>
above.

>  static __no_kasan_or_inline
>  unsigned long read_word_at_a_time(const void *addr)
> --
> 2.24.0.432.g9d3f5f5b63-goog
>
Alexander Potapenko Dec. 3, 2019, 12:45 p.m. UTC | #2
On Mon, Dec 2, 2019 at 11:03 AM Marco Elver <elver@google.com> wrote:
>
> On Fri, 22 Nov 2019 at 12:27, <glider@google.com> wrote:
> >
> > READ_ONCE_NOCHECK() is already used by KASAN to ignore memory accesses
> > from e.g. stack unwinders.
> > Define READ_ONCE_NOCHECK() for KMSAN so that it returns initialized
> > values. This helps defeat false positives from leftover stack contents.
> >
> > Signed-off-by: Alexander Potapenko <glider@google.com>
> > To: Alexander Potapenko <glider@google.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: Vegard Nossum <vegard.nossum@oracle.com>
> > Cc: Dmitry Vyukov <dvyukov@google.com>
> > Cc: linux-mm@kvack.org
> > ---
> > v3:
> >  - removed unnecessary #ifdef as requested by Mark Rutland
> >
> > Change-Id: Ib38369ba038ab3b581d8e45b81036c3304fb79cb
> > ---
> >  include/linux/compiler.h | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> > index 5e88e7e33abe..99d40f31a2c3 100644
> > --- a/include/linux/compiler.h
> > +++ b/include/linux/compiler.h
> > @@ -270,9 +270,9 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
> >
> >  /*
> >   * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need
> > - * to hide memory access from KASAN.
> > + * to hide memory access from KASAN or KMSAN.
> >   */
> > -#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
> > +#define READ_ONCE_NOCHECK(x) KMSAN_INIT_VALUE(__READ_ONCE(x, 0))
>
> I think this needs:
>     #include <linux/kmsan-checks.h>
> above.
Ack, will include in v4.
> >  static __no_kasan_or_inline
> >  unsigned long read_word_at_a_time(const void *addr)
> > --
> > 2.24.0.432.g9d3f5f5b63-goog
> >
diff mbox series

Patch

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 5e88e7e33abe..99d40f31a2c3 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -270,9 +270,9 @@  static __always_inline void __write_once_size(volatile void *p, void *res, int s
 
 /*
  * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need
- * to hide memory access from KASAN.
+ * to hide memory access from KASAN or KMSAN.
  */
-#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
+#define READ_ONCE_NOCHECK(x) KMSAN_INIT_VALUE(__READ_ONCE(x, 0))
 
 static __no_kasan_or_inline
 unsigned long read_word_at_a_time(const void *addr)