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 X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 168BBC3A5A9 for ; Mon, 4 May 2020 18:03:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDC2C2073E for ; Mon, 4 May 2020 18:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588615428; bh=I+23E1nejXXmqMPCcDs70MvMIzAWPNa9nL34YX8ynx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1pv3BJvH77u9RVoQTihP4t0LZcyp/G2c0abVGlsxkpcGTMllS0XvKRNYc9iZTm4Qq 4HHVIyWKtGUEZ0gXwVhZGMyMp0Lql3PtXJ9ocEWaPx8aFhzbJZgiMLqolnTQv1QQWq qbNTK9T72EAZz30/+a+PVxqVbGo8cAvswjokuMcA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731570AbgEDSDr (ORCPT ); Mon, 4 May 2020 14:03:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:60930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731527AbgEDSDl (ORCPT ); Mon, 4 May 2020 14:03:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5073F205ED; Mon, 4 May 2020 18:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588615420; bh=I+23E1nejXXmqMPCcDs70MvMIzAWPNa9nL34YX8ynx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+Loxc/cB62UPrs8BoF9ayjs1/aiawOUNwuXYGJ11s5vp7mP/ZrOVBWOdMhqf6rBu QAtScmSr93yOd5B6uEtJdkNUz93SrRFoBXDHvclk+2obI89I358/5lify1kSRqpxXT IqUHa6Sq1ILPuL4pMsEszxfEFoktFld9OLjNOAsw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Xiyu Yang , Xin Tan , David Sterba Subject: [PATCH 5.4 08/57] btrfs: fix transaction leak in btrfs_recover_relocation Date: Mon, 4 May 2020 19:57:12 +0200 Message-Id: <20200504165457.244140813@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200504165456.783676004@linuxfoundation.org> References: <20200504165456.783676004@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiyu Yang commit 1402d17dfd9657be0da8458b2079d03c2d61c86a upstream. btrfs_recover_relocation() invokes btrfs_join_transaction(), which joins a btrfs_trans_handle object into transactions and returns a reference of it with increased refcount to "trans". When btrfs_recover_relocation() returns, "trans" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of btrfs_recover_relocation(). When read_fs_root() failed, the refcnt increased by btrfs_join_transaction() is not decreased, causing a refcnt leak. Fix this issue by calling btrfs_end_transaction() on this error path when read_fs_root() failed. Fixes: 79787eaab461 ("btrfs: replace many BUG_ONs with proper error handling") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Filipe Manana Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/relocation.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4605,6 +4605,7 @@ int btrfs_recover_relocation(struct btrf if (IS_ERR(fs_root)) { err = PTR_ERR(fs_root); list_add_tail(&reloc_root->root_list, &reloc_roots); + btrfs_end_transaction(trans); goto out_unset; }