]>
git.hungrycats.org Git - linux/commit
btrfs: reject existing chunks that don't match
During read_one_chunk() we can hit an existing chunk map.
There are several situations that this can happen:
- System chunk maps
This is the most common case, where the system chunks are added from
super block during bootstrap.
But in that case, the system chunks in the super block should match
the one in the chunk tree, if not there is definitely something wrong.
- Overlapping chunk maps
This is rare, but potentially malicious.
Crafted images or even some bitflips in the chunk tree can lead to
this.
In that case we should reject such cases.
To detect and reject those cases:
- Introduce a new helper, is_same_chunk_map()
This checks most important members, so we can detect such problem
without fully checking the stripes.
If the helper returns false, then we output an error message and
reject the mount.
- Use the full chunk map range for btrfs_find_chunk_map()
The current search range is [@logical, @logical], which is only one
bytenr in length.
If we have the following case, btrfs_find_chunk_map() returns NULL but
we still have an overlapping chunk map:
Logical
|<--- New chunk map --->|
|<--- Existing chunk map --->|
Using the full range to do the search would return the existing chunk
map and get the new one rejected.
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>