btrfs: relocation: set trans to be NULL after free
PATCH 1/1 btrfs: relocation: set trans to be NULL after free
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.
relocation")
--- fs/btrfs/relocation.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/relocation.c +1 -0
@@ -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 ; }
Signature · 1 line
2.7.4
Quoted 11 lines · Pan Bian
The function
relocate_block_groupcallsbtrfs_end_transactionto release trans whenupdate_backref_cachereturns 1, and then continues the loop body. Ifbtrfs_block_rsv_refillfails 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 balancerelocation")
Signed-off-by Pan Bian <[email protected]>
Thanks,
Qu
Quoted 17 lines
--- fs/btrfs/relocation.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/relocation.c +1
-0@@ -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 ; }
Quoted 11 lines · Pan Bian
The function
relocate_block_groupcallsbtrfs_end_transactionto release trans whenupdate_backref_cachereturns 1, and then continues the loop body. Ifbtrfs_block_rsv_refillfails 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 balancerelocation")
Signed-off-by Pan Bian <[email protected]>
Good catch, thanks.