Skip to content

Commit 64f64f4

Browse files
adam900710kdave
authored andcommitted
btrfs: Exit gracefully when chunk map cannot be inserted to the tree
It's entirely possible that a crafted btrfs image contains overlapping chunks. Although we can't detect such problem by tree-checker, it's not a catastrophic problem, current extent map can already detect such problem and return -EEXIST. We just only need to exit gracefully and fail the mount. Reported-by: Xu Wen <wen.xu@gatech.edu> Link: https://bugzilla.kernel.org/show_bug.cgi?id=200409 Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent cf90d88 commit 64f64f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fs/btrfs/volumes.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6489,10 +6489,14 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
64896489
write_lock(&map_tree->map_tree.lock);
64906490
ret = add_extent_mapping(&map_tree->map_tree, em, 0);
64916491
write_unlock(&map_tree->map_tree.lock);
6492-
BUG_ON(ret); /* Tree corruption */
6492+
if (ret < 0) {
6493+
btrfs_err(fs_info,
6494+
"failed to add chunk map, start=%llu len=%llu: %d",
6495+
em->start, em->len, ret);
6496+
}
64936497
free_extent_map(em);
64946498

6495-
return 0;
6499+
return ret;
64966500
}
64976501

64986502
static void fill_device_from_item(struct extent_buffer *leaf,

0 commit comments

Comments
 (0)