From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D85ABC433EF for ; Fri, 10 Sep 2021 07:33:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCC0361153 for ; Fri, 10 Sep 2021 07:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231340AbhIJHeV (ORCPT ); Fri, 10 Sep 2021 03:34:21 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:19022 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231494AbhIJHeR (ORCPT ); Fri, 10 Sep 2021 03:34:17 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4H5SDG4b8tzbmKM; Fri, 10 Sep 2021 15:29:02 +0800 (CST) Received: from dggpemm500004.china.huawei.com (7.185.36.219) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Fri, 10 Sep 2021 15:33:04 +0800 Received: from huawei.com (10.174.28.241) by dggpemm500004.china.huawei.com (7.185.36.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Fri, 10 Sep 2021 15:33:04 +0800 From: Bixuan Cui To: , CC: , , Subject: [PATCH -next v2] io-wq: Fix memory leak in create_io_worker Date: Fri, 10 Sep 2021 15:29:10 +0800 Message-ID: <20210910072910.43319-1-cuibixuan@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.28.241] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500004.china.huawei.com (7.185.36.219) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Kmemleak tool detected a memory leak. ==================== unreferenced object 0xffff888126fcd6c0 (size 192): comm "syz-executor.1", pid 11934, jiffies 4294983026 (age 15.690s) hex dump (first 32 bytes): 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmalloc_node include/linux/slab.h:609 [inline] [] kzalloc_node include/linux/slab.h:732 [inline] [] create_io_worker+0x41/0x1e0 fs/io-wq.c:739 [] io_wqe_create_worker fs/io-wq.c:267 [inline] [] io_wqe_enqueue+0x1fe/0x330 fs/io-wq.c:866 [] io_queue_async_work+0xc4/0x200 fs/io_uring.c:1473 [] __io_queue_sqe+0x34c/0x510 fs/io_uring.c:6933 [] io_req_task_submit+0x4b/0xa0 fs/io_uring.c:2233 [] io_async_task_func+0x108/0x1c0 fs/io_uring.c:5462 [] tctx_task_work+0x1b3/0x3a0 fs/io_uring.c:2158 [] task_work_run+0x73/0xb0 kernel/task_work.c:164 [] tracehook_notify_signal include/linux/tracehook.h:212 [inline] [] handle_signal_work kernel/entry/common.c:146 [inline] [] exit_to_user_mode_loop kernel/entry/common.c:172 [inline] [] exit_to_user_mode_prepare+0x151/0x180 kernel/entry/common.c:209 [] __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline] [] syscall_exit_to_user_mode+0x1d/0x40 kernel/entry/common.c:302 [] do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86 [] entry_SYSCALL_64_after_hwframe+0x44/0xae ==================== If io_should_retry_thread is false in create_io_worker() and io_queue_worker_create is false in io_workqueue_create(), free the worker. Fixes: 3146cba99aa2 ("io-wq: make worker creation resilient against signals") Reported-by: syzbot+65454c239241d3d647da@syzkaller.appspotmail.com Signed-off-by: Bixuan Cui --- Changes in v2: * Add free worker if io_queue_worker_create is false in io_workqueue_create(); * Add kmemleak calltrace in commit message; fs/io-wq.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/io-wq.c b/fs/io-wq.c index d80e4a735677..c24f79cf2b97 100644 --- a/fs/io-wq.c +++ b/fs/io-wq.c @@ -725,6 +725,7 @@ static void io_workqueue_create(struct work_struct *work) if (!io_queue_worker_create(worker, acct, create_worker_cont)) { clear_bit_unlock(0, &worker->create_state); io_worker_release(worker); + kfree(worker); } } @@ -759,6 +760,7 @@ static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index) if (!IS_ERR(tsk)) { io_init_new_worker(wqe, worker, tsk); } else if (!io_should_retry_thread(PTR_ERR(tsk))) { + kfree(worker); goto fail; } else { INIT_WORK(&worker->work, io_workqueue_create); -- 2.17.1