From patchwork Thu Oct 20 01:47:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Mendonca X-Patchwork-Id: 5954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp11102wrs; Wed, 19 Oct 2022 18:48:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6KPKd+oxNgboujPzDvCfvdhtCvpQBBlJBrW2qWpXSsuVnCRIuSGF5UqRD9STmIJlOdxZCF X-Received: by 2002:a17:906:8a51:b0:78d:acdc:b7d3 with SMTP id gx17-20020a1709068a5100b0078dacdcb7d3mr8964518ejc.214.1666230537954; Wed, 19 Oct 2022 18:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666230537; cv=none; d=google.com; s=arc-20160816; b=QvVfLgxr1g96c2ow6I47tTA0etXuem1+hBwWXx7etj7EDqqe6PZAaNbMtnaqxgWzNj hYJYV3p7ckVZiP9wiBEoQIG314hoMT7Dj56BFGNZVrTKSOT0aJ0AtFqwo15zzXtiGqgX SWYyCbbAe7HIOURxn87jgVSSmdIsseHcor42QfO6cAIOq3sJozoay/g436JOQQRDkfqY J7YC4UgoYgetkXf2uF+QwChPoW/oaCiSrmczFrk9Z3TmgEwlRr3YuGNnShu4NmGdgypV MfwQ5189H/4ieyFxe1LQ3g0v5XvlBxVyOQ6NNxNJOZdd1ex69z9meFpzvO1sF4Bte+kn FtWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9vUhRSZJCY7KpJC4RI1IvvNhYQ/fmK2CLSJSd1FaYiA=; b=FnjEfX+4E6pPGd9bhhMqgUA9qDeG1/dtGtyziQ3ZBv5M5p8fX5FoatvMX4ig0KzuSq apX2Z1YT8v8s+iFv1x/wAJLKp1iq29qEK3DHtvi35Sa/UUXJXcQ0ljYS0jNxkGCRhDHB C7WdNlvLTfXtL3BvcqgDCHWLoCxqV+4bTza/1Z5ys4YbJ2OOsHYZMexc0UOt48ucZzGl FJmIAHKb+rMcpS9fOCGHSk1ipg37Cz5Kr2OfVbWJjH4J/J9j98w7TUQo5QZWbYDfUaem lxtzEdsbd209l7IyajIJfOK/g+KRszVOoHNtkwcdJaROA2vjsEzlX3vOCDOqKNNc7TaE 69JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cavVnV1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020a056402358e00b00456d3fc12d4si16752343edc.222.2022.10.19.18.48.33; Wed, 19 Oct 2022 18:48:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cavVnV1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231492AbiJTBrl (ORCPT + 99 others); Wed, 19 Oct 2022 21:47:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231171AbiJTBri (ORCPT ); Wed, 19 Oct 2022 21:47:38 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D487B1D1017; Wed, 19 Oct 2022 18:47:36 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id w196so21297374oiw.8; Wed, 19 Oct 2022 18:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9vUhRSZJCY7KpJC4RI1IvvNhYQ/fmK2CLSJSd1FaYiA=; b=cavVnV1m3N5NzP2tWUyolKWTQYTngRg094gtT/25DeHzYd3cgOWjrVH8E2jFKHLk51 7nM4JDL6aJY9FpUkYq0AOl9/Nj8I2KPsCNhMYGpJyiaHvJyWEH36gMyl2F0bsVYstF2G HZLRxTqfQbFBaLai7tB4X0a8m78LCMDJ0LwWWzL1Mn0kzmzeEwUld6mMVhv0mVGaGS+j +/ymesLIVt92rAXvCMBttH2YU8rukbqCynenjijaD83UcgBInFC3EqkvZneoFXeRA7Xr Zj9nrObRMe8//Yr+8fCT78UJrJdMFzB2cdywEWX9ohFisY9DcNfybz/PCqkzyETz7/Z7 sx1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9vUhRSZJCY7KpJC4RI1IvvNhYQ/fmK2CLSJSd1FaYiA=; b=2+y8xlEiZUVInjotwsFwPau1VM3QDAPluEZ5s57GHt8IO6emxqQaFmj8FFPCLaP3bD 4s6a161BW7lSN35htKvrMQwqr5Cr39RwzEqkI0ZOvytcbzpSpkoSf39TPb3Z8/1OVxZq ecK0gc68IAYwQ57MECzxAeJKwc7g8THdOuwTih9Uxa/DogNWZMe256bUD3Ola3r3Epq4 uIWD4My7vmB8P351zc/44He3jJ4fKQOyeYu3P+LenYfYwvoVodlqFBh4rH9L+NaJnB3z bYF7Cnmok1ZYw9raub4rmUYxsEcfO+lDd45fGj8mgPSBjHM7PQ2ErmDlex7DElHSyRft rYkg== X-Gm-Message-State: ACrzQf2zeOWBFLe9Rv0qj6xZC4Pwr11DV7aN0mwKcrXzJHZJY3WAv1WD ABmE7G+gHfRVEjLU245yBh9P/KWmZ5I= X-Received: by 2002:a05:6871:5d3:b0:131:feaf:b826 with SMTP id v19-20020a05687105d300b00131feafb826mr7528563oan.129.1666230445909; Wed, 19 Oct 2022 18:47:25 -0700 (PDT) Received: from macondo.. ([2804:431:e7cc:1855:8393:57eb:548f:5125]) by smtp.gmail.com with ESMTPSA id f10-20020a056830204a00b00661b019accbsm7659796otp.3.2022.10.19.18.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 18:47:25 -0700 (PDT) From: Rafael Mendonca To: Jens Axboe , Pavel Begunkov Cc: Rafael Mendonca , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] io-wq: Fix memory leak in worker creation Date: Wed, 19 Oct 2022 22:47:09 -0300 Message-Id: <20221020014710.902201-1-rafaelmendsr@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747169352347556632?= X-GMAIL-MSGID: =?utf-8?q?1747169352347556632?= If the CPU mask allocation for a node fails, then the memory allocated for the 'io_wqe' struct of the current node doesn't get freed on the error handling path, since it has not yet been added to the 'wqes' array. This was spotted when fuzzing v6.1-rc1 with Syzkaller: BUG: memory leak unreferenced object 0xffff8880093d5000 (size 1024): comm "syz-executor.2", pid 7701, jiffies 4295048595 (age 13.900s) hex dump (first 32 bytes): 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 00 ................ backtrace: [<00000000cb463369>] __kmem_cache_alloc_node+0x18e/0x720 [<00000000147a3f9c>] kmalloc_node_trace+0x2a/0x130 [<000000004e107011>] io_wq_create+0x7b9/0xdc0 [<00000000c38b2018>] io_uring_alloc_task_context+0x31e/0x59d [<00000000867399da>] __io_uring_add_tctx_node.cold+0x19/0x1ba [<000000007e0e7a79>] io_uring_setup.cold+0x1b80/0x1dce [<00000000b545e9f6>] __x64_sys_io_uring_setup+0x5d/0x80 [<000000008a8a7508>] do_syscall_64+0x5d/0x90 [<000000004ac08bec>] entry_SYSCALL_64_after_hwframe+0x63/0xcd Fixes: 0e03496d1967 ("io-wq: use private CPU mask") Signed-off-by: Rafael Mendonca --- io_uring/io-wq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c index c6536d4b2da0..6f1d0e5df23a 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -1164,10 +1164,10 @@ struct io_wq *io_wq_create(unsigned bounded, struct io_wq_data *data) wqe = kzalloc_node(sizeof(struct io_wqe), GFP_KERNEL, alloc_node); if (!wqe) goto err; + wq->wqes[node] = wqe; if (!alloc_cpumask_var(&wqe->cpu_mask, GFP_KERNEL)) goto err; cpumask_copy(wqe->cpu_mask, cpumask_of_node(node)); - wq->wqes[node] = wqe; wqe->node = alloc_node; wqe->acct[IO_WQ_ACCT_BOUND].max_workers = bounded; wqe->acct[IO_WQ_ACCT_UNBOUND].max_workers =