]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: fix transaction leak in btrfs_recover_relocation
authorXiyu Yang <xiyuyang19@fudan.edu.cn>
Mon, 20 Apr 2020 05:39:39 +0000 (13:39 +0800)
committerDavid Sterba <dsterba@suse.com>
Thu, 23 Apr 2020 15:24:56 +0000 (17:24 +0200)
commit932d264a1fa91e69e72277a25dce0fc20e373a9b
tree6b7e86fd65a27538cdfac75edbb640c39bcb08eb
parent920dc9ec328ec9c6515f44ee71755ac16f67beef
btrfs: fix transaction leak in btrfs_recover_relocation

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: 99175604eacb ("btrfs: replace many BUG_ONs with proper error handling")
CC: stable@vger.kernel.org # 4.4+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/relocation.c