]> www.infradead.org Git - nvme.git/commit
btrfs: tree-checker: validate dref root and objectid
authorQu Wenruo <wqu@suse.com>
Mon, 15 Jul 2024 06:37:07 +0000 (16:07 +0930)
committerDavid Sterba <dsterba@suse.com>
Thu, 25 Jul 2024 21:54:06 +0000 (23:54 +0200)
commitf333a3c7e8323499aa65038e77fe8f3199d4e283
tree4f0c972b1192d04891ba1664f7f149f650f07cf8
parentc3ece6b7ffb4a7c00e8d53cbf4026a32b6127914
btrfs: tree-checker: validate dref root and objectid

[CORRUPTION]
There is a bug report that btrfs flips RO due to a corruption in the
extent tree, the involved dumps looks like this:

  item 188 key (402811572224 168 4096) itemoff 14598 itemsize 79
  extent refs 3 gen 3678544 flags 1
  ref#0: extent data backref root 13835058055282163977 objectid 281473384125923 offset 81432576 count 1
  ref#1: shared data backref parent 1947073626112 count 1
  ref#2: shared data backref parent 1156030103552 count 1
 BTRFS critical (device vdc1: state EA): unable to find ref byte nr 402811572224 parent 0 root 265 owner 28703026 offset 81432576 slot 189
 BTRFS error (device vdc1: state EA): failed to run delayed ref for logical 402811572224 num_bytes 4096 type 178 action 2 ref_mod 1: -2

[CAUSE]
The corrupted entry is ref#0 of item 188.
The root number 13835058055282163977 is beyond the upper limit for root
items (the current limit is 1 << 48), and the objectid also looks
suspicious.

Only the offset and count is correct.

[ENHANCEMENT]
Although it's still unknown why we have such many bytes corrupted
randomly, we can still enhance the tree-checker for data backrefs by:

- Validate the root value
  For now there should only be 3 types of roots can have data backref:
  * subvolume trees
  * data reloc trees
  * root tree
    Only for v1 space cache

- validate the objectid value
  The objectid should be a valid inode number.

Hopefully we can catch such problem in the future with the new checkers.

Reported-by: Kai Krakow <hurikhan77@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/CAMthOuPjg5RDT-G_LXeBBUUtzt3cq=JywF+D1_h+JYxe=WKp-Q@mail.gmail.com/#t
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/tree-checker.c