mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V2] kthread: zero the kthread data structure
@ 2017-11-07 19:09 Shaohua Li
  2017-11-07 19:32 ` Tejun Heo
  2017-11-07 19:45 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Shaohua Li @ 2017-11-07 19:09 UTC (permalink / raw)
  To: LKML, Jens Axboe; +Cc: Andrew Morton, Ingo Molnar, Tejun Heo, Dmitry Vyukov

kthread() could bail out early before we initialize blkcg_css (if the
kthread is killed very early. Please see xchg() statement in kthread()),
which confuses free_kthread_struct. Instead of moving the blkcg_css
initialization early, we simply zero the whole 'self' data structure,
which doesn't sound much overhead.

Reported-by: syzbot <syzkaller@googlegroups.com>
Fixes: 05e3db95ebfc ("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>
Cc: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Shaohua Li <shli@fb.com>
---
 kernel/kthread.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index f87cd8b4..8dbe245 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -204,7 +204,7 @@ static int kthread(void *_create)
 	struct kthread *self;
 	int ret;
 
-	self = kmalloc(sizeof(*self), GFP_KERNEL);
+	self = kzalloc(sizeof(*self), GFP_KERNEL);
 	set_kthread_struct(self);
 
 	/* If user was SIGKILLed, I release the structure. */
@@ -220,13 +220,9 @@ static int kthread(void *_create)
 		do_exit(-ENOMEM);
 	}
 
-	self->flags = 0;
 	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 V2] kthread: zero the kthread data structure
  2017-11-07 19:09 [PATCH V2] kthread: zero the kthread data structure Shaohua Li
@ 2017-11-07 19:32 ` Tejun Heo
  2017-11-07 19:45 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2017-11-07 19:32 UTC (permalink / raw)
  To: Shaohua Li; +Cc: LKML, Jens Axboe, Andrew Morton, Ingo Molnar, Dmitry Vyukov

On Tue, Nov 07, 2017 at 11:09:50AM -0800, Shaohua Li wrote:
> kthread() could bail out early before we initialize blkcg_css (if the
> kthread is killed very early. Please see xchg() statement in kthread()),
> which confuses free_kthread_struct. Instead of moving the blkcg_css
> initialization early, we simply zero the whole 'self' data structure,
> which doesn't sound much overhead.
> 
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Fixes: 05e3db95ebfc ("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>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Shaohua Li <shli@fb.com>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

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

* Re: [PATCH V2] kthread: zero the kthread data structure
  2017-11-07 19:09 [PATCH V2] kthread: zero the kthread data structure Shaohua Li
  2017-11-07 19:32 ` Tejun Heo
@ 2017-11-07 19:45 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2017-11-07 19:45 UTC (permalink / raw)
  To: Shaohua Li, LKML; +Cc: Andrew Morton, Ingo Molnar, Tejun Heo, Dmitry Vyukov

On 11/07/2017 12:09 PM, Shaohua Li wrote:
> kthread() could bail out early before we initialize blkcg_css (if the
> kthread is killed very early. Please see xchg() statement in kthread()),
> which confuses free_kthread_struct. Instead of moving the blkcg_css
> initialization early, we simply zero the whole 'self' data structure,
> which doesn't sound much overhead.

Applied, thanks Shaohua.

-- 
Jens Axboe

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-07 19:09 [PATCH V2] kthread: zero the kthread data structure Shaohua Li
2017-11-07 19:32 ` Tejun Heo
2017-11-07 19:45 ` Jens Axboe

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®