aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2025-04-16 16:00:28 +0100
committerDavid Sterba <dsterba@suse.com>2025-05-15 14:30:52 +0200
commit41d69d4d78d8b179bf3bcdfc56d28a12b3a608d2 (patch)
treeb118fdaf690843c594154df1e27a358742b88f24
parentbtrfs: exit after state insertion failure at set_extent_bit() (diff)
downloadlinux-rng-41d69d4d78d8b179bf3bcdfc56d28a12b3a608d2.tar.xz
linux-rng-41d69d4d78d8b179bf3bcdfc56d28a12b3a608d2.zip
btrfs: exit after state split error at set_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.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 29cf3a01294f..36bdf9df7b4c 100644
--- a/fs/btrfs/extent-io-tree.c
+++ b/fs/btrfs/extent-io-tree.c
@@ -1250,8 +1250,11 @@ hit_next:
if (!prealloc)
goto search_again;
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, changeset);
cache_state(prealloc, cached_state);