Re: [PATCH] kthread: move the cgroup info initialization early

From: Andrew Morton
Date: Tue Nov 07 2017 - 13:15:42 EST


On Tue, 7 Nov 2017 09:57:03 -0800 Shaohua Li <shli@xxxxxx> wrote:

> kthread() could bail out early before we initialize blkcg_css (if the
> kthread is killed very soon), which confuses free_kthread_struct. Move
> the blkcg_css initialization early.

Changelog is... minimal. I guess it doesn't matter much.

> Reported-by: syzbot <syzkaller@xxxxxxxxxxxxxxxx>
> Fix: 05e3db9(kthread: add a mechanism to store cgroup info)

That's a bit messed up. Please use

Fixes: 05e3db95ebfc ("kthread: add a mechanism to store cgroup info")

> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -205,6 +205,10 @@ static int kthread(void *_create)
> int ret;
>
> self = kmalloc(sizeof(*self), GFP_KERNEL);
> +#ifdef CONFIG_BLK_CGROUP
> + if (self)
> + self->blkcg_css = NULL;
> +#endif

Using kzalloc() would be much neater. That way we get to delete a bit
more code and it doesn't leave me wondering "under what circumstances
is kthread.cpu uninitialized". At least, not as much as I am wondering
right now.