linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm] fix for "kasan, fork: reset pointer tags of vmapped stacks"
@ 2022-02-15 16:52 andrey.konovalov
  2022-02-16  9:59 ` Marco Elver
  0 siblings, 1 reply; 3+ messages in thread
From: andrey.konovalov @ 2022-02-15 16:52 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, linux-mm,
	linux-kernel, Andrey Konovalov

From: Andrey Konovalov <andreyknvl@google.com>

That patch didn't update the case when a stack is retrived from
cached_stacks in alloc_thread_stack_node(). As cached_stacks stores
vm_structs and not stack pointers themselves, the pointer tag needs
to be reset there as well.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 kernel/fork.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index 57d624f05182..5e3ad2e7a756 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -226,15 +226,17 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
 		if (!s)
 			continue;
 
-		/* Mark stack accessible for KASAN. */
+		/* Reset stack metadata. */
 		kasan_unpoison_range(s->addr, THREAD_SIZE);
 
+		stack = kasan_reset_tag(s->addr);
+
 		/* Clear stale pointers from reused stack. */
-		memset(s->addr, 0, THREAD_SIZE);
+		memset(stack, 0, THREAD_SIZE);
 
 		tsk->stack_vm_area = s;
-		tsk->stack = s->addr;
-		return s->addr;
+		tsk->stack = stack;
+		return stack;
 	}
 
 	/*
-- 
2.25.1


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

* Re: [PATCH mm] fix for "kasan, fork: reset pointer tags of vmapped stacks"
  2022-02-15 16:52 [PATCH mm] fix for "kasan, fork: reset pointer tags of vmapped stacks" andrey.konovalov
@ 2022-02-16  9:59 ` Marco Elver
  2022-02-16 15:20   ` Andrey Konovalov
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Elver @ 2022-02-16  9:59 UTC (permalink / raw)
  To: andrey.konovalov
  Cc: Andrew Morton, Andrey Konovalov, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, linux-mm,
	linux-kernel, Andrey Konovalov

On Tue, 15 Feb 2022 at 17:52, <andrey.konovalov@linux.dev> wrote:
>
> From: Andrey Konovalov <andreyknvl@google.com>
>
> That patch didn't update the case when a stack is retrived from
> cached_stacks in alloc_thread_stack_node(). As cached_stacks stores
> vm_structs and not stack pointers themselves, the pointer tag needs
> to be reset there as well.
>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Reviewed-by: Marco Elver <elver@google.com>

Did the test catch this? If not, can this be tested?

> ---
>  kernel/fork.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 57d624f05182..5e3ad2e7a756 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -226,15 +226,17 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
>                 if (!s)
>                         continue;
>
> -               /* Mark stack accessible for KASAN. */
> +               /* Reset stack metadata. */
>                 kasan_unpoison_range(s->addr, THREAD_SIZE);
>
> +               stack = kasan_reset_tag(s->addr);
> +
>                 /* Clear stale pointers from reused stack. */
> -               memset(s->addr, 0, THREAD_SIZE);
> +               memset(stack, 0, THREAD_SIZE);
>
>                 tsk->stack_vm_area = s;
> -               tsk->stack = s->addr;
> -               return s->addr;
> +               tsk->stack = stack;
> +               return stack;
>         }
>
>         /*
> --
> 2.25.1
>

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

* Re: [PATCH mm] fix for "kasan, fork: reset pointer tags of vmapped stacks"
  2022-02-16  9:59 ` Marco Elver
@ 2022-02-16 15:20   ` Andrey Konovalov
  0 siblings, 0 replies; 3+ messages in thread
From: Andrey Konovalov @ 2022-02-16 15:20 UTC (permalink / raw)
  To: Marco Elver
  Cc: andrey.konovalov, Andrew Morton, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev,
	Linux Memory Management List, LKML, Andrey Konovalov

On Wed, Feb 16, 2022 at 10:59 AM Marco Elver <elver@google.com> wrote:
>
> On Tue, 15 Feb 2022 at 17:52, <andrey.konovalov@linux.dev> wrote:
> >
> > From: Andrey Konovalov <andreyknvl@google.com>
> >
> > That patch didn't update the case when a stack is retrived from
> > cached_stacks in alloc_thread_stack_node(). As cached_stacks stores
> > vm_structs and not stack pointers themselves, the pointer tag needs
> > to be reset there as well.
> >
> > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>
> Reviewed-by: Marco Elver <elver@google.com>
>
> Did the test catch this? If not, can this be tested?

Kind of, the kernel crashes on boot. I got KASAN_STACK accidentally
disabled in my SW_TAGS config, so I didn't see the crash until now.

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

end of thread, other threads:[~2022-02-16 15:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 16:52 [PATCH mm] fix for "kasan, fork: reset pointer tags of vmapped stacks" andrey.konovalov
2022-02-16  9:59 ` Marco Elver
2022-02-16 15:20   ` Andrey Konovalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).