Skip to content

Commit e10237c

Browse files
shligitaxboe
authored andcommitted
kthread: zero the kthread data structure
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: 05e3db9 ("kthread: add a mechanism to store cgroup info") Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Dmitry Vyukov <dvyukov@google.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 18c53e4 commit e10237c

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

‎kernel/kthread.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int kthread(void *_create)
204204
struct kthread *self;
205205
int ret;
206206

207-
self = kmalloc(sizeof(*self), GFP_KERNEL);
207+
self = kzalloc(sizeof(*self), GFP_KERNEL);
208208
set_kthread_struct(self);
209209

210210
/* If user was SIGKILLed, I release the structure. */
@@ -220,13 +220,9 @@ static int kthread(void *_create)
220220
do_exit(-ENOMEM);
221221
}
222222

223-
self->flags = 0;
224223
self->data = data;
225224
init_completion(&self->exited);
226225
init_completion(&self->parked);
227-
#ifdef CONFIG_BLK_CGROUP
228-
self->blkcg_css = NULL;
229-
#endif
230226
current->vfork_done = &self->exited;
231227

232228
/* OK, tell user we're spawned, wait for stop or wakeup */

0 commit comments

Comments
 (0)