]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root
authorJosef Bacik <josef@toxicpanda.com>
Thu, 14 Jan 2021 19:02:46 +0000 (14:02 -0500)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 15 Mar 2021 14:09:42 +0000 (15:09 +0100)
commit376250c627d4ae7406655e7070f8f409c29ed923
tree0abab4689b90203c3b788c03aeb5f6533b88e5bb
parent4e2dbca9511a005e041f02d2d5c77d205f86cfec
btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root

commit 867ed321f90d06aaba84e2c91de51cd3038825ef 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>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
fs/btrfs/ctree.c