summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorPan Bian <bianpan2016@163.com>2018-11-23 18:10:15 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-12-05 19:32:07 +0100
commit590657656bdcf682fa3667dd7c768b3541558619 (patch)
treed9f4dae0aaedc2f40a726f4c1a132158c0be46fd /fs
parent172a94eb2df2006a795af44cb1ffa330ad85572a (diff)
btrfs: relocation: set trans to be NULL after ending transaction
commit 42a657f57628402c73237547f0134e083e2f6764 upstream. The function relocate_block_group calls btrfs_end_transaction to release trans when update_backref_cache returns 1, and then continues the loop body. If btrfs_block_rsv_refill fails this time, it will jump out the loop and the freed trans will be accessed. This may result in a use-after-free bug. The patch assigns NULL to trans after trans is released so that it will not be accessed. Fixes: 0647bf564f1 ("Btrfs: improve forever loop when doing balance relocation") CC: stable@vger.kernel.org # 4.4+ Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Pan Bian <bianpan2016@163.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/relocation.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 60bf8dfe7df4..0526b6c473c7 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3963,6 +3963,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
restart:
if (update_backref_cache(trans, &rc->backref_cache)) {
btrfs_end_transaction(trans);
+ trans = NULL;
continue;
}