From patchwork Fri Dec 9 09:29:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: shaozhengchao X-Patchwork-Id: 31695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp674148wrr; Fri, 9 Dec 2022 01:41:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7chiIehhiHVj4VeaAXsUkYBHFrqXnSPZezRwWqsY9lH//eyfgx2emUpbvuV6lqt0brh9cq X-Received: by 2002:a05:6402:248e:b0:464:1b51:f85c with SMTP id q14-20020a056402248e00b004641b51f85cmr3100309eda.25.1670578909917; Fri, 09 Dec 2022 01:41:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670578909; cv=none; d=google.com; s=arc-20160816; b=tc4w3+Sv1U86qjrwUcyedsP+7h1shfV2Cr6OHHg/f6ukctEw49V6zdGD7z1GcXvl43 JfxDNpDpvj0T3s+Oilxu7KikpZDFOU92jRCUouQdk0ub1RaqW+OUIcsBJqtWrf4+bCw9 vYMq74gN2uEVnUFMpyrxgcaeqCqH5ohsD3mpg+v1oUvh7aOZCcxB4gvsi9dE3KzxqwFN 8xTxFLpRBP0aqVP/mq7E2kFCV9X40d5EbvN97+mAYCe3G2rTntVE6BBv0dL4WYhDI/nL tpvD2/wASdhgGJGBM+MrLBNzh1pCNDe1/YEjSDrus+xJiw/msY46z3hnmXmyyl81FdeB byug== 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; bh=a0Lol3uxNnYPeUxiV17corQBxbG8dw6l/bA1I8y3I20=; b=D+nBLw4t7xde/+qU9Rw1sktmA5aL2T0kiN3Wjuh3E9K6CwgwTVqo91KIDqX+NRiEp7 QcEa089esoDWR5KGaZs//pvxPTX1HHsctuotifL2pcHlKNDQfy+QwQZuxdYdNZ3oy20A w5t/fdRmXwp8b9fAd4bKDjb07JH4N+AWmXqmcw4a/JChZ1lFbM7QmgT2n5ErOTmDkEJX +JmELO9k9nJNvnnG7wl/G+CygTohtwxJk9viMgH0Wl2wxDje1TTF1uaaNGZCkOOqubro Tx6P8MDVlZHdSDs6ZL3F/NSUQvMRT9mevcprrVjP+nFBt8xEGl3Yxwyq7+36W1Ey152Y 91Dw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a05640242c900b0046b0205ab58si1177294edc.580.2022.12.09.01.41.26; Fri, 09 Dec 2022 01:41:49 -0800 (PST) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbiLIJVH (ORCPT + 99 others); Fri, 9 Dec 2022 04:21:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230014AbiLIJVC (ORCPT ); Fri, 9 Dec 2022 04:21:02 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2919E5802F for ; Fri, 9 Dec 2022 01:21:02 -0800 (PST) Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NT58S0rDHzmWXZ; Fri, 9 Dec 2022 17:20:08 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpeml500026.china.huawei.com (7.185.36.106) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 9 Dec 2022 17:20:49 +0800 From: Zhengchao Shao To: , , , CC: , , , , , , , Subject: [PATCH] ipc: fix memory leak in init_mqueue_fs() Date: Fri, 9 Dec 2022 17:29:29 +0800 Message-ID: <20221209092929.1978875-1-shaozhengchao@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500026.china.huawei.com (7.185.36.106) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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?1751728951067694710?= X-GMAIL-MSGID: =?utf-8?q?1751728951067694710?= When setup_mq_sysctls() failed in init_mqueue_fs(), mqueue_inode_cachep is not released. In order to fix this issue, the release path is reordered. Fixes: dc55e35f9e81 ("ipc: Store mqueue sysctls in the ipc namespace") Signed-off-by: Zhengchao Shao --- ipc/mqueue.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 467a194b8a2e..d09aa1c1e3e6 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c @@ -1726,7 +1726,8 @@ static int __init init_mqueue_fs(void) if (!setup_mq_sysctls(&init_ipc_ns)) { pr_warn("sysctl registration failed\n"); - return -ENOMEM; + error = -ENOMEM; + goto out_kmem; } error = register_filesystem(&mqueue_fs_type); @@ -1744,8 +1745,9 @@ static int __init init_mqueue_fs(void) out_filesystem: unregister_filesystem(&mqueue_fs_type); out_sysctl: - kmem_cache_destroy(mqueue_inode_cachep); retire_mq_sysctls(&init_ipc_ns); +out_kmem: + kmem_cache_destroy(mqueue_inode_cachep); return error; }