diff options
author | Filipe Manana <fdmanana@suse.com> | 2025-04-10 17:01:59 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2025-05-15 14:30:51 +0200 |
commit | 2a72dd999610f9a8e2ddc0eaaf054cd66e45cde7 (patch) | |
tree | 7a7abb47c2126ec0818438d5628e365694ef1329 | |
parent | 5f9c554a6c1219dee1a3484db2e19881d35a0788 (diff) |
btrfs: exit after state split error at btrfs_convert_extent_bit()
If split_state() returned an error we call extent_io_tree_panic() which
will trigger a BUG() call. However if CONFIG_BUG is disabled, which is an
uncommon and exotic scenario, then we fallthrough and hit a use after free
when calling set_state_bits() since the extent state record which the
local variable 'prealloc' points to was freed by split_state().
So jump to the label 'out' after calling extent_io_tree_panic() and set
the 'prealloc' pointer to NULL since split_state() has already freed it
when it hit an error.
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/extent-io-tree.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c index 2c004e0c431d..0b154f1a3546 100644 --- a/fs/btrfs/extent-io-tree.c +++ b/fs/btrfs/extent-io-tree.c @@ -1460,8 +1460,11 @@ hit_next: } ret = split_state(tree, state, prealloc, end + 1); - if (ret) + if (ret) { extent_io_tree_panic(tree, state, "split", ret); + prealloc = NULL; + goto out; + } set_state_bits(tree, prealloc, bits, NULL); cache_state(prealloc, cached_state); |