Skip to contentSkip to conversation

FAILED: patch "[PATCH] btrfs: relocation: set trans to be NULL after ending" failed to apply to 4.4-stable tree

PATCH [email protected] 1 participant 1 message Dec 3, 2018

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

Quoted 1 line

From 42a657f57628402c73237547f0134e083e2f6764 Mon Sep 17 00:00:00 2001

From: Pan Bian <[email protected]>
Date: Fri, 23 Nov 2018 18:10:15 +0800
Subject: [PATCH] btrfs: relocation: set trans to be NULL after ending
transaction

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")
fs/btrfs/relocation.c +1 -0
index 924116f654a1..a3f75b8926d4 100644
@@ -3959,6 +3959,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;
 		}