Skip to content

Commit 1e2dda2

Browse files
fdmananaSasha Levin
authored andcommitted
btrfs: exit after state split error at set_extent_bit()
[ Upstream commit 41d69d4 ] 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>
1 parent 1b38ef3 commit 1e2dda2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/btrfs/extent-io-tree.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,11 @@ static int __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
12521252
if (!prealloc)
12531253
goto search_again;
12541254
ret = split_state(tree, state, prealloc, end + 1);
1255-
if (ret)
1255+
if (ret) {
12561256
extent_io_tree_panic(tree, state, "split", ret);
1257+
prealloc = NULL;
1258+
goto out;
1259+
}
12571260

12581261
set_state_bits(tree, prealloc, bits, changeset);
12591262
cache_state(prealloc, cached_state);

0 commit comments

Comments
 (0)