summaryrefslogtreecommitdiff
path: root/fs/btrfs/extent-io-tree.c
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2025-04-09 16:17:16 +0100
committerDavid Sterba <dsterba@suse.com>2025-05-15 14:30:50 +0200
commit2187540b6f4d92b4bf7622244dc2cbfa61ff1855 (patch)
tree39bc33a2d58d7a62f7adbc66c9ae23cff27100ab /fs/btrfs/extent-io-tree.c
parentf389e7b982a14421dc6ec935552c39ea23da2f43 (diff)
btrfs: exit after state split error at btrfs_clear_extent_bit_changeset()
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 clear_state_bit() 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>
Diffstat (limited to 'fs/btrfs/extent-io-tree.c')
-rw-r--r--fs/btrfs/extent-io-tree.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/btrfs/extent-io-tree.c b/fs/btrfs/extent-io-tree.c
index 15400a0f899c..b868313e777e 100644
--- a/fs/btrfs/extent-io-tree.c
+++ b/fs/btrfs/extent-io-tree.c
@@ -712,8 +712,11 @@ hit_next:
if (!prealloc)
goto search_again;
err = split_state(tree, state, prealloc, end + 1);
- if (err)
+ if (err) {
extent_io_tree_panic(tree, state, "split", err);
+ prealloc = NULL;
+ goto out;
+ }
if (wake)
wake_up(&state->wq);