Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3452023pxb; Mon, 4 Apr 2022 17:25:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMysmRJvGDManAa8bQ1vqTvrW2gyy6zFbL29lh1Qv00Uqz09ScaeCTYJxxcHm7R4AUDkQw X-Received: by 2002:a05:6a00:e14:b0:4fe:3cdb:23f with SMTP id bq20-20020a056a000e1400b004fe3cdb023fmr842728pfb.86.1649118335864; Mon, 04 Apr 2022 17:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649118335; cv=none; d=google.com; s=arc-20160816; b=t8VMKhvxocO6mQKnapDSVzrqI4LhcszRqrJsGKpuWSAu12XFBUsOVK0O0ah8fgZDD8 nCaQwiLd/LbPjcRzkxVA2pr/f7tkIeYDJdfsWvEDKrXWcd5liKBuHW+72ZBRsED7UCVW TQAyvVyjU99DBEiV2pB8xoXW6TfKVurM6SUGRtjbGihpa1D+rHN62VAAZi+5SxBBtb9M LykIyP1L7B4rdYK/Hu9rlsBDe2fxREhbsZiAqhEkrcTUPS8zQVNqHYn5Q/hHhDqFChwW VUlHP1ywhmJlz3f3/FXyujFNYMJ8ZQZNmtsDfEv8MgyeOkj2dSybV3qX3ZxvaxYiW/oq i05Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gmLDa7FLWPOooq4LsQovS1FxUVQrseyPVEZzkXV/cNw=; b=KREstFrQ1aJxiLuab2oW4IArr4gYE8/dJLY7x9r0pgIX39svfiOa7e2svbcdOxm2el JfnWeuIdccgoOCiVEK+klRuO3yKXPthhsGV2Uo5iw6MPEmz0NePLXSoXDPy49Y2trdZ/ c7zBqATtlSf8h1kxVmZYSV9voDjT3AoGY8IIMNnEMxnHzHFK6CsnwHbuvsGwZGDvb7hR AHGnPKmfB2gWdv1nD8symXbNC3vwrH2bmP0JK6CZHEVrLu+FHPKHlTFNfRpWsxALDWKy GsDJ2lL2pbhsKh/myYrOLQvOkwjtGCc6JK3eNtz7ZwvPM+aZfQgSsQqR4+I9xnqAoaUc 82YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=giRe+288; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u14-20020a170903124e00b00153fae68065si13065213plh.538.2022.04.04.17.25.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 17:25:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=giRe+288; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E39F77E094; Mon, 4 Apr 2022 16:48:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348392AbiDAOnO (ORCPT + 99 others); Fri, 1 Apr 2022 10:43:14 -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 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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