Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1223804pxb; Fri, 10 Sep 2021 00:34:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyd/IS176BKxw1WfnmjaLe6ChkXEyKgo0f5Eyy+M14KAWVgkbX33OeWl+8/yl0TOkFNe1it X-Received: by 2002:a17:906:38db:: with SMTP id r27mr7977621ejd.338.1631259291962; Fri, 10 Sep 2021 00:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631259291; cv=none; d=google.com; s=arc-20160816; b=JtWj8C4SvluHwdVxH5OH6d1Ui6pYO7hFqA9hCMWr1WJHC1fwqGW3Zd/dyq93PM6F+p ACSYSz/7nDsvPXlZfYx7luhYGyBo4iSSWtuoxEox9fsE1AswDrANKZmxZbZLZoS7QBfe OL4+zLPRwRVGRjJLeBpMXmm6/eWoa4L4zCUETfB3wn5rR87WyamLkx3fpKX/bzAN9YgP XRHGbNU6n82AoSmd/Q0WKw1XRX4LDaAjrgpQfa7yWxb/7cH5dpD64CEsUK1AonRprLe5 3WYpywA1YjJp+bREoVkpKAvGvZ+yMnudEtMNJ2OAuMbBIJ7CkHWY7k3u2SHXhodgWSTL v0gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=iY92E7FQf1Y1PWOsyoEHgGLNg++/TpHX02rJhqSaWj4=; b=Z4neu7TZ1LxIHZh1hItHvXYKpRKX5r6hLj83P9cu0OLB8AQfgMFNyi5ixXMDaQcg+9 mpiSz3y6BJavFveF8GO/oqR6c4YAnH4Oj+r73f/vUEN8sANqImdLFBH6Wx+uE/d77xP4 ObiE5p6q1UKqgjCPq0zKiVfq6tY7etINHv/I26DaYz+/VueF571XaehJMJwwMx9xU1oD Xh9Tt/4zrPiiA7levTDrPNSKrCh1p7D+SxxyRPv5z5tm7REV3KWAuYvo9T0XgG+Ljk9g /rnTHkMmifhwl8jTwE5R9zjIPxPfBTpjarGPnDHBf05wLPsSpjcJ8p34knTU4bOgfYAK wPEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si3947794ejc.100.2021.09.10.00.34.27; Fri, 10 Sep 2021 00:34:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231290AbhIJHeV (ORCPT + 99 others); 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: linux-kernel@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