Skip to content

Commit

Permalink
kthread: zero the kthread data structure
Browse files Browse the repository at this point in the history
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 <[email protected]>
Fixes: 05e3db9 ("kthread: add a mechanism to store cgroup info")
Cc: Andrew Morton <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Signed-off-by: Shaohua Li <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
shligit authored and axboe committed Nov 11, 2017
1 parent 18c53e4 commit e10237c
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions kernel/kthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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 */
Expand Down

0 comments on commit e10237c

Please sign in to comment.