]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: exit after state split error at set_extent_bit()
authorFilipe Manana <fdmanana@suse.com>
Wed, 16 Apr 2025 15:00:28 +0000 (16:00 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Jun 2025 13:32:32 +0000 (15:32 +0200)
commit3c04fafeb3ee233617c185b6bc6c3fe96e03b602
tree394a6a6c69c43150ad741317c0f28eef647efee4
parent7b4bf4d8968384b9b61a610f3494e245d68cd3c7
btrfs: exit after state split error at set_extent_bit()

[ Upstream commit 41d69d4d78d8b179bf3bcdfc56d28a12b3a608d2 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/extent-io-tree.c