Skip to content

Commit 230ed39

Browse files
josefbacikkdave
authored andcommitted
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: 762bf09 ("btrfs: improve error handling in run_delalloc_nocow") CC: [email protected] # 5.4+ Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 04e484c commit 230ed39

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

fs/btrfs/inode.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,12 +1690,8 @@ static noinline int run_delalloc_nocow(struct inode *inode,
16901690
ret = fallback_to_cow(inode, locked_page, cow_start,
16911691
found_key.offset - 1,
16921692
page_started, nr_written);
1693-
if (ret) {
1694-
if (nocow)
1695-
btrfs_dec_nocow_writers(fs_info,
1696-
disk_bytenr);
1693+
if (ret)
16971694
goto error;
1698-
}
16991695
cow_start = (u64)-1;
17001696
}
17011697

@@ -1711,9 +1707,6 @@ static noinline int run_delalloc_nocow(struct inode *inode,
17111707
ram_bytes, BTRFS_COMPRESS_NONE,
17121708
BTRFS_ORDERED_PREALLOC);
17131709
if (IS_ERR(em)) {
1714-
if (nocow)
1715-
btrfs_dec_nocow_writers(fs_info,
1716-
disk_bytenr);
17171710
ret = PTR_ERR(em);
17181711
goto error;
17191712
}

0 commit comments

Comments
 (0)