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 B572CC433EF for ; Fri, 1 Apr 2022 14:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348407AbiDAOnQ (ORCPT ); Fri, 1 Apr 2022 10:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348471AbiDAOea (ORCPT ); Fri, 1 Apr 2022 10:34:30 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3639BC7; Fri, 1 Apr 2022 07:32:41 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 3EA9861CA5; Fri, 1 Apr 2022 14:32:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDA71C340F2; Fri, 1 Apr 2022 14:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648823560; bh=sE4+EECy/LIgdSLc+FT42yrSgLpqf3BDjDtRJM+SOLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=giRe+288fo4xO4dHMGZNCN/U8H6qKbYQflRsF5b/Pihu50X4G2l8PXQxtXwQbBA41 6dc/5L2rz6uO7thYTEXNOUZd+tTLYiKjOPL282xCtskdecN22o6JgucmEHZh8YuSJI LRGKsOVmasgjTWmGFJuB2IfgaZF8C9hVfvkIuXtOLMR/3nfXCi/NcGfyjOOvpU89ie VoYoOyAvZsgIFNt7CKt8T448v97MhKovAnWvNTVHu4m/C68o7Asb6gtmrGG/fIdvl+ wULLdqoWyiwCne4dqv3fuWoJeWO4n/Bd2VGS6KKLEBYvU33r55REVCNwVzDB6gsN4S r65xCoSGEGZOQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiubo Li , Jeff Layton , Ilya Dryomov , Sasha Levin , ceph-devel@vger.kernel.org Subject: [PATCH AUTOSEL 5.17 145/149] ceph: fix inode reference leakage in ceph_get_snapdir() Date: Fri, 1 Apr 2022 10:25:32 -0400 Message-Id: <20220401142536.1948161-145-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401142536.1948161-1-sashal@kernel.org> References: <20220401142536.1948161-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiubo Li [ Upstream commit 322794d3355c33adcc4feace0045d85a8e4ed813 ] The ceph_get_inode() will search for or insert a new inode into the hash for the given vino, and return a reference to it. If new is non-NULL, its reference is consumed. We should release the reference when in error handing cases. Signed-off-by: Xiubo Li Reviewed-by: Jeff Layton Signed-off-by: Ilya Dryomov Signed-off-by: Sasha Levin --- fs/ceph/inode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index ef4a980a7bf3..c092dce0485c 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -87,13 +87,13 @@ struct inode *ceph_get_snapdir(struct inode *parent) if (!S_ISDIR(parent->i_mode)) { pr_warn_once("bad snapdir parent type (mode=0%o)\n", parent->i_mode); - return ERR_PTR(-ENOTDIR); + goto err; } if (!(inode->i_state & I_NEW) && !S_ISDIR(inode->i_mode)) { pr_warn_once("bad snapdir inode type (mode=0%o)\n", inode->i_mode); - return ERR_PTR(-ENOTDIR); + goto err; } inode->i_mode = parent->i_mode; @@ -113,6 +113,12 @@ struct inode *ceph_get_snapdir(struct inode *parent) } return inode; +err: + if ((inode->i_state & I_NEW)) + discard_new_inode(inode); + else + iput(inode); + return ERR_PTR(-ENOTDIR); } const struct inode_operations ceph_file_iops = { -- 2.34.1