Skip to content

btrfs: fix an ASSERT() triggered inside prepare_to_merge()

Qu Wenruo linux-btrfs 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest3 patches 5 repliesIn review
  2. v33 patches 1 replySuperseded
  3. v23 patches 4 repliesSuperseded

Changes in v4 from the cover letter

- Remove the remaining commas inside the root key prompt of the 2nd patch

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3btrfs: avoid race with qgroup tree creation and relocationfs/btrfs/disk-io.c+10 -00 replies
2/3btrfs: exit gracefully if reloc roots don't matchfs/btrfs/relocation.c+36 -84 replies
3/3btrfs: reject invalid reloc tree root keys with stack dumpfs/btrfs/disk-io.c fs/btrfs/tree-checker.c+16 -10 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchFilipe Manana[email protected]
1/3R-b Reported-and-tested-by
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/3] btrfs: fix an ASSERT() triggered inside prepare_to_merge()

[CHANGELOG]
v4:
- Remove the remaining commas inside the root key prompt of the 2nd patch

v3:
- Update the comments and commit messages

- Replace the deleted ASSERT(0)s with WARN_ON()s

- Remove a debug dump_stack() in the last patch

v2:
- Add two new patches
One to properly fix the root cause (race between quota tree creation and relocation).
One to reject obviously corrupted reloc trees.

- Remove two ASSERT()s from merge_reloc_roots()

[BUG]
Syzbot reported an ASSERT() triggered inside prepare_to_merge(), which turns out to be a regression caused by commit 85724171b302 ("btrfs: fix the btrfs_get_global_root return value").

[CAUSE]
The race can happen between quota tree creation and relocation, the root cause is btrfs_get_fs_root() can try to read quota tree as one fs tree, thus setting ROOT_SHAREABLE flag.

This leads to relocation code to create a new reloc tree for quota tree, which should not happen.
Furthermore at later relocation stages, we will grab quota root from fs_info->quota_root, which is not the same as the one read by btrfs_get_fs_root(), thus quota_root->reloc_root is NULL.

This triggers the ASSERT() and crash the system.

[FIX]
- Make sure non-subvolume trees are always grabbed from fs_info This changes btrfs_get_root_ref() to a more explicit checks, and would return PTR_ERR(-ENOENT) if a non-subvolume (data reloc tree still counts as a subvolume tree) objectid is provided.

This is the root fix.

- Replace the ASSERT() with a more graceful exit
Still does the extra kernel warning through btrfs_abort_transaction(), but with more useful error messages.

- Reject obviously incorrect reloc trees through tree-checker Just another layer of sanity checks for on-disk data.

Qu Wenruo (3):
btrfs: avoid race with qgroup tree creation and relocation
btrfs: exit gracefully if reloc roots don't match
btrfs: reject invalid reloc tree root keys with stack dump

 fs/btrfs/disk-io.c      | 13 +++++++++++-
 fs/btrfs/relocation.c   | 44 +++++++++++++++++++++++++++++++++--------
 fs/btrfs/tree-checker.c | 14 +++++++++++++
 3 files changed, 62 insertions(+), 9 deletions(-)
Signature · 1 line
2.41.0