btrfs: exit after state split error at btrfs_convert_extent_bit()
authorFilipe Manana <fdmanana@suse.com>
Thu, 10 Apr 2025 16:01:59 +0000 (17:01 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:51 +0000 (14:30 +0200)
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>
fs/btrfs/extent-io-tree.c

index 2c004e0c431d8f2e751bb9aadaa210d5e0cd9c28..0b154f1a3546f107591551147a83998627c7f890 100644 (file)
@@ -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);