diff mbox series

[RFC,v3,09/36] kmsan: add KMSAN bits to struct page and struct task_struct

Message ID 20191122112621.204798-10-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
Each struct page now contains pointers to two struct pages holding KMSAN
metadata (shadow and origins) for the original struct page.

Each task_struct contains a struct kmsan_task_state used to track the
metadata of function parameters and return values for that task.

Signed-off-by: Alexander Potapenko <glider@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: linux-mm@kvack.org
---

Change-Id: Ie329527e558dd60307fb88b2da151f7f4db951ac
---
 include/linux/mm_types.h | 9 +++++++++
 include/linux/sched.h    | 5 +++++
 2 files changed, 14 insertions(+)

Comments

Marco Elver Nov. 28, 2019, 1:44 p.m. UTC | #1
On Fri, 22 Nov 2019 at 12:26, <glider@google.com> wrote:
>
> Each struct page now contains pointers to two struct pages holding KMSAN
> metadata (shadow and origins) for the original struct page.
>
> Each task_struct contains a struct kmsan_task_state used to track the
> metadata of function parameters and return values for that task.
>
> Signed-off-by: Alexander Potapenko <glider@google.com>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Vegard Nossum <vegard.nossum@oracle.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: linux-mm@kvack.org
> ---
>
> Change-Id: Ie329527e558dd60307fb88b2da151f7f4db951ac
> ---
>  include/linux/mm_types.h | 9 +++++++++
>  include/linux/sched.h    | 5 +++++
>  2 files changed, 14 insertions(+)
>
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 2222fa795284..c87c5416a802 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -216,6 +216,15 @@ struct page {
>                                            not kmapped, ie. highmem) */
>  #endif /* WANT_PAGE_VIRTUAL */
>
> +#ifdef CONFIG_KMSAN
> +       /*
> +        * Bits in struct page are scarce, so the LSB in *shadow is used to
> +        * indicate whether the page should be ignored by KMSAN or not.
> +        */
> +       struct page *shadow;
> +       struct page *origin;
> +#endif
> +
>  #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
>         int _last_cpupid;
>  #endif
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 72b20f33c56e..ba705f66f78c 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -15,6 +15,7 @@
>  #include <linux/sem.h>
>  #include <linux/shm.h>
>  #include <linux/kcov.h>
> +#include <linux/kmsan.h>

This file does not exist at this point in the series, and the build
would fail for all configs. This can cause problems for 'git bisect'
users etc.

I would just merge this patch with patch 10.

Thanks,
-- Marco


>  #include <linux/mutex.h>
>  #include <linux/plist.h>
>  #include <linux/hrtimer.h>
> @@ -1173,6 +1174,10 @@ struct task_struct {
>         unsigned int                    kasan_depth;
>  #endif
>
> +#ifdef CONFIG_KMSAN
> +       struct kmsan_task_state         kmsan;
> +#endif
> +
>  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
>         /* Index of current stored address in ret_stack: */
>         int                             curr_ret_stack;
> --
> 2.24.0.432.g9d3f5f5b63-goog
>
Alexander Potapenko Nov. 28, 2019, 2:05 p.m. UTC | #2
On Thu, Nov 28, 2019 at 2:44 PM Marco Elver <elver@google.com> wrote:
>
> On Fri, 22 Nov 2019 at 12:26, <glider@google.com> wrote:
> >
> > Each struct page now contains pointers to two struct pages holding KMSAN
> > metadata (shadow and origins) for the original struct page.
> >
> > Each task_struct contains a struct kmsan_task_state used to track the
> > metadata of function parameters and return values for that task.
> >
> > Signed-off-by: Alexander Potapenko <glider@google.com>
> > Cc: Jens Axboe <axboe@kernel.dk>
> > Cc: Andy Lutomirski <luto@kernel.org>
> > Cc: Vegard Nossum <vegard.nossum@oracle.com>
> > Cc: Dmitry Vyukov <dvyukov@google.com>
> > Cc: Christoph Hellwig <hch@lst.de>
> > Cc: linux-mm@kvack.org
> > ---
> >
> > Change-Id: Ie329527e558dd60307fb88b2da151f7f4db951ac
> > ---
> >  include/linux/mm_types.h | 9 +++++++++
> >  include/linux/sched.h    | 5 +++++
> >  2 files changed, 14 insertions(+)
> >
> > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> > index 2222fa795284..c87c5416a802 100644
> > --- a/include/linux/mm_types.h
> > +++ b/include/linux/mm_types.h
> > @@ -216,6 +216,15 @@ struct page {
> >                                            not kmapped, ie. highmem) */
> >  #endif /* WANT_PAGE_VIRTUAL */
> >
> > +#ifdef CONFIG_KMSAN
> > +       /*
> > +        * Bits in struct page are scarce, so the LSB in *shadow is used to
> > +        * indicate whether the page should be ignored by KMSAN or not.
> > +        */
> > +       struct page *shadow;
> > +       struct page *origin;
> > +#endif
> > +
> >  #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
> >         int _last_cpupid;
> >  #endif
> > diff --git a/include/linux/sched.h b/include/linux/sched.h
> > index 72b20f33c56e..ba705f66f78c 100644
> > --- a/include/linux/sched.h
> > +++ b/include/linux/sched.h
> > @@ -15,6 +15,7 @@
> >  #include <linux/sem.h>
> >  #include <linux/shm.h>
> >  #include <linux/kcov.h>
> > +#include <linux/kmsan.h>
>
> This file does not exist at this point in the series, and the build
> would fail for all configs. This can cause problems for 'git bisect'
> users etc.
I thought we can move this patch past the KMSAN runtime then, but then
the runtime won't be able to use the newly added fields.
> I would just merge this patch with patch 10.
Ack.

> Thanks,
> -- Marco
>
>
> >  #include <linux/mutex.h>
> >  #include <linux/plist.h>
> >  #include <linux/hrtimer.h>
> > @@ -1173,6 +1174,10 @@ struct task_struct {
> >         unsigned int                    kasan_depth;
> >  #endif
> >
> > +#ifdef CONFIG_KMSAN
> > +       struct kmsan_task_state         kmsan;
> > +#endif
> > +
> >  #ifdef CONFIG_FUNCTION_GRAPH_TRACER
> >         /* Index of current stored address in ret_stack: */
> >         int                             curr_ret_stack;
> > --
> > 2.24.0.432.g9d3f5f5b63-goog
> >
diff mbox series

Patch

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 2222fa795284..c87c5416a802 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -216,6 +216,15 @@  struct page {
 					   not kmapped, ie. highmem) */
 #endif /* WANT_PAGE_VIRTUAL */
 
+#ifdef CONFIG_KMSAN
+	/*
+	 * Bits in struct page are scarce, so the LSB in *shadow is used to
+	 * indicate whether the page should be ignored by KMSAN or not.
+	 */
+	struct page *shadow;
+	struct page *origin;
+#endif
+
 #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS
 	int _last_cpupid;
 #endif
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 72b20f33c56e..ba705f66f78c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -15,6 +15,7 @@ 
 #include <linux/sem.h>
 #include <linux/shm.h>
 #include <linux/kcov.h>
+#include <linux/kmsan.h>
 #include <linux/mutex.h>
 #include <linux/plist.h>
 #include <linux/hrtimer.h>
@@ -1173,6 +1174,10 @@  struct task_struct {
 	unsigned int			kasan_depth;
 #endif
 
+#ifdef CONFIG_KMSAN
+	struct kmsan_task_state		kmsan;
+#endif
+
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 	/* Index of current stored address in ret_stack: */
 	int				curr_ret_stack;