Skip to content

Commit 4d3edf7

Browse files
josefbacikgregkh
authored andcommitted
btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root
commit 867ed32 upstream. While testing my error handling patches, I added a error injection site at btrfs_inc_extent_ref, to validate the error handling I added was doing the correct thing. However I hit a pretty ugly corruption while doing this check, with the following error injection stack trace: btrfs_inc_extent_ref btrfs_copy_root create_reloc_root btrfs_init_reloc_root btrfs_record_root_in_trans btrfs_start_transaction btrfs_update_inode btrfs_update_time touch_atime file_accessed btrfs_file_mmap This is because we do not catch the error from btrfs_inc_extent_ref, which in practice would be ENOMEM, which means we lose the extent references for a root that has already been allocated and inserted, which is the problem. Fix this by aborting the transaction if we fail to do the reference modification. CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik <josef@toxicpanda.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>
1 parent a1a5cc2 commit 4d3edf7

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

fs/btrfs/ctree.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,10 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
221221
ret = btrfs_inc_ref(trans, root, cow, 1);
222222
else
223223
ret = btrfs_inc_ref(trans, root, cow, 0);
224-
225-
if (ret)
224+
if (ret) {
225+
btrfs_abort_transaction(trans, ret);
226226
return ret;
227+
}
227228

228229
btrfs_mark_buffer_dirty(cow);
229230
*cow_ret = cow;

0 commit comments

Comments
 (0)