summaryrefslogtreecommitdiff
path: root/fs/btrfs
diff options
context:
space:
mode:
authorPan Bian <bianpan2016@163.com>2018-11-23 13:10:15 +0300
committerBen Hutchings <ben@decadent.org.uk>2019-02-11 20:54:10 +0300
commit225ef25362d19fc1fb3870deca0b3110303e99eb (patch)
tree1613a0653e2fc79ec934e0dd4d10a4aad3fc39d9 /fs/btrfs
parent3d03e8e5472800f11294d4e1843fead13cc40535 (diff)
downloadlinux-225ef25362d19fc1fb3870deca0b3110303e99eb.tar.xz
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") 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> [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'fs/btrfs')
-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 e0029f1a0da8..9cba36820c72 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3955,6 +3955,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, rc->extent_root);
+ trans = NULL;
continue;
}