]> git.hungrycats.org Git - linux/commit
btrfs: reject existing chunks that don't match
authorQu Wenruo <wqu@suse.com>
Fri, 16 Oct 2026 00:48:19 +0000 (11:18 +1030)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:16 +0000 (21:36 +0100)
commite794d9ff0bf78daceef1e1dd70342791ec814de6
tree713d68bcde5166938acaeda451dd3e8c97774742
parenta5538a0f1ed2577fe09f582adecf8d6bc6bf48b1
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>
fs/btrfs/volumes.c