From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754266AbdKGR5f (ORCPT ); Tue, 7 Nov 2017 12:57:35 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:38864 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753139AbdKGR5e (ORCPT ); Tue, 7 Nov 2017 12:57:34 -0500 Smtp-Origin-Hostprefix: devbig From: Shaohua Li Smtp-Origin-Hostname: devbig638.prn2.facebook.com To: LKML , Jens Axboe CC: Dmitry Vyukov , Andrew Morton , Ingo Molnar , Tejun Heo Smtp-Origin-Cluster: prn2c22 Subject: [PATCH] kthread: move the cgroup info initialization early Date: Tue, 7 Nov 2017 09:57:03 -0800 Message-ID: <28c1d60a523362bdf7db7a96a6b1ab80c8689141.1510077329.git.shli@fb.com> X-Mailer: git-send-email 2.9.5 X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-07_06:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Fix: 05e3db9(kthread: add a mechanism to store cgroup info) Cc: Andrew Morton Cc: Ingo Molnar Cc: Tejun Heo Signed-off-by: Shaohua Li --- 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