]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: fix double put of block group with nocow
authorJosef Bacik <josef@toxicpanda.com>
Mon, 6 Jul 2020 13:14:12 +0000 (09:14 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 9 Jul 2020 15:44:26 +0000 (17:44 +0200)
commitcacf00b86c8bc9ae948ad50c6acb28e19d8ea0e0
tree47b355e133fb666a4003e12d3e4da0c21ae9cb1e
parentc8ceb198f11596abe41dc024d76a99d01d76bd44
btrfs: fix double put of block group with nocow

While debugging a patch that I wrote I was hitting use-after-free panics
when accessing block groups on unmount.  This turned out to be because
in the nocow case if we bail out of doing the nocow for whatever reason
we need to call btrfs_dec_nocow_writers() if we called the inc.  This
puts our block group, but a few error cases does

if (nocow) {
    btrfs_dec_nocow_writers();
    goto error;
}

unfortunately, error is

error:
if (nocow)
btrfs_dec_nocow_writers();

so we get a double put on our block group.  Fix this by dropping the
error cases calling of btrfs_dec_nocow_writers(), as it's handled at the
error label now.

Fixes: b5b0ab826db2 ("btrfs: improve error handling in run_delalloc_nocow")
CC: stable@vger.kernel.org # 5.4+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c