mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] kthread: move the cgroup info initialization early
@ 2017-11-07 17:57 Shaohua Li
  2017-11-07 18:05 ` Tejun Heo
  2017-11-07 18:15 ` Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: Shaohua Li @ 2017-11-07 17:57 UTC (permalink / raw)
  To: LKML, Jens Axboe; +Cc: Dmitry Vyukov, Andrew Morton, Ingo Molnar, Tejun Heo

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.

Reported-by: syzbot <syzkaller@googlegroups.com>
Fix: 05e3db9(kthread: add a mechanism to store cgroup info)
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Shaohua Li <shli@fb.com>
---
 kernel/kthread.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index f87cd8b4..cf5c113 100644
--- 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
 	set_kthread_struct(self);
 
 	/* If user was SIGKILLed, I release the structure. */
@@ -224,9 +228,6 @@ static int kthread(void *_create)
 	self->data = data;
 	init_completion(&self->exited);
 	init_completion(&self->parked);
-#ifdef CONFIG_BLK_CGROUP
-	self->blkcg_css = NULL;
-#endif
 	current->vfork_done = &self->exited;
 
 	/* OK, tell user we're spawned, wait for stop or wakeup */
-- 
2.9.5

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

* Re: [PATCH] kthread: move the cgroup info initialization early
  2017-11-07 17:57 [PATCH] kthread: move the cgroup info initialization early Shaohua Li
@ 2017-11-07 18:05 ` Tejun Heo
  2017-11-07 18:15 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2017-11-07 18:05 UTC (permalink / raw)
  To: Shaohua Li; +Cc: LKML, Jens Axboe, Dmitry Vyukov, Andrew Morton, Ingo Molnar

On Tue, Nov 07, 2017 at 09:57:03AM -0800, Shaohua Li 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.
> 
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Fix: 05e3db9(kthread: add a mechanism to store cgroup info)
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Tejun Heo <tj@kernel.org>
> Signed-off-by: Shaohua Li <shli@fb.com>
> ---
>  kernel/kthread.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index f87cd8b4..cf5c113 100644
> --- 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

That's not a big struct and I can't imagine that avoiding zeroing it
matters in anyway.  Can't we just use kzalloc() instead and drop the
ugly ifdef?

Thanks.

-- 
tejun

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

* Re: [PATCH] kthread: move the cgroup info initialization early
  2017-11-07 17:57 [PATCH] kthread: move the cgroup info initialization early Shaohua Li
  2017-11-07 18:05 ` Tejun Heo
@ 2017-11-07 18:15 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2017-11-07 18:15 UTC (permalink / raw)
  To: Shaohua Li; +Cc: LKML, Jens Axboe, Dmitry Vyukov, Ingo Molnar, Tejun Heo

On Tue, 7 Nov 2017 09:57:03 -0800 Shaohua Li <shli@fb.com> 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@googlegroups.com>
> 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.

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

end of thread, other threads:[~2017-11-07 18:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-07 17:57 [PATCH] kthread: move the cgroup info initialization early Shaohua Li
2017-11-07 18:05 ` Tejun Heo
2017-11-07 18:15 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®