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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92B17C4167B for ; Wed, 28 Dec 2022 15:17:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233205AbiL1PRq (ORCPT ); Wed, 28 Dec 2022 10:17:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233191AbiL1PRn (ORCPT ); Wed, 28 Dec 2022 10:17:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E62C13F1F for ; Wed, 28 Dec 2022 07:17:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5D8EEB8171C for ; Wed, 28 Dec 2022 15:17:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A610FC433EF; Wed, 28 Dec 2022 15:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672240660; bh=QEpW8Zqy4OW62L1PqM7FyKRgRMFmmip1U2fQd8wi8MY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IaM6mBbZD+gsmglPoPDZ+rsswcerITxoTDYJu4hbawFPho4tQKipNtH0Knp7YWima b+6UA4lDS93fTWHdPNV7wBOz+atWENBzvqkoGtvkBaK7VfwKsdk/zgpVEVSPP78/Hp Y7iHIJljINyKuVSn6dklmJrI2a+DIfHhxqfhX1Og= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhengchao Shao , Alexey Gladkov , "Eric W. Biederman" , Jingyu Wang , Muchun Song , Roman Gushchin , Waiman Long , Wei Yongjun , YueHaibing , Yu Zhe , Manfred Spraul , Davidlohr Bueso , Andrew Morton , Sasha Levin Subject: [PATCH 6.0 0186/1073] ipc: fix memory leak in init_mqueue_fs() Date: Wed, 28 Dec 2022 15:29:34 +0100 Message-Id: <20221228144333.063534094@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221228144328.162723588@linuxfoundation.org> References: <20221228144328.162723588@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zhengchao Shao [ Upstream commit 12b677f2c697d61e5ddbcb6c1650050a39392f54 ] 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. Link: https://lkml.kernel.org/r/20221209092929.1978875-1-shaozhengchao@huawei.com Fixes: dc55e35f9e81 ("ipc: Store mqueue sysctls in the ipc namespace") Signed-off-by: Zhengchao Shao Cc: Alexey Gladkov Cc: "Eric W. Biederman" Cc: Jingyu Wang Cc: Muchun Song Cc: Roman Gushchin Cc: Waiman Long Cc: Wei Yongjun Cc: YueHaibing Cc: Yu Zhe Cc: Manfred Spraul Cc: Davidlohr Bueso Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- ipc/mqueue.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 9cf314b3f079..b258f2455553 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c @@ -1727,7 +1727,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); @@ -1745,8 +1746,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; } -- 2.35.1