Re: [PATCH 2/2] kasan: unpoison stack of idle task on cpu online

From: Mark Rutland
Date: Wed Mar 02 2016 - 10:44:13 EST


On Wed, Mar 02, 2016 at 06:27:49PM +0300, Andrey Ryabinin wrote:
> On 03/02/2016 05:50 PM, Mark Rutland wrote:
> > On Wed, Mar 02, 2016 at 04:51:59PM +0300, Andrey Ryabinin wrote:

[...]

> > Is all the above necessary?
> >
> > Surely we can just include <linux/smpboot.h> in mm/kasan/kasan.c?
>
> It is necessary. kernel/smpboot.h != include/linux/smpboot.h

Ah, I'd misread the patch. Sorry for the noise!

[...]

> >> + struct task_struct *tidle = idle_thread_get(cpu);
> >> + kasan_unpoison_shadow(task_stack_page(tidle), THREAD_SIZE);
> >
> > We never expect the stack to hit the end of the thread_info, so we can
> > start at task_stack_page(tidle) + 1, and avoid the shadow for
> > sizeof(struct thread_info).
> >
>
> I wouldn't bother, it's simpler to unpoison all. Size of struct thread_info is 32-bytes. That's 4-bytes of shadow.
> I don't think it matters whether you do memset of 2048 or 2044 bytes.
>
> > Do we do any poisoning of the thread_info structure in the thread_union?
>
> No, why would we poison it? It's absolutely valid memory and available for access.

For some reason I thought ASAN might poison gaps between struct
elements, or at least held open the option to. I guess inserting padding
would be an ABI issue, so it probably doesn't.

In the absence of that, I agree that always starting at
task_stack_page(t), and clearing the shadow for THREAD_SIZE bytes of
stack makes sense).

Thanks,
Mark.