]> git.hungrycats.org Git - linux/commitdiff
btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT
authorCheng Yongkang <teel4res@gmail.com>
Sun, 1 Nov 2026 06:25:39 +0000 (23:25 -0700)
committerQu Wenruo <wqu@suse.com>
Sun, 1 Nov 2026 08:30:23 +0000 (19:00 +1030)
btrfs_ioctl_subvol_sync() assumes that a cached root with zero
references has BTRFS_ROOT_SUBVOL_DEAD set, and asserts that before
waiting for the cleaner. Two states break the assumption:

- A corrupt ROOT_ITEM with zero references and a matching orphan item,
  on a writable filesystem.
- A failed subvolume deletion. btrfs_delete_subvolume() zeroes the
  root references, aborts the transaction, which forces the filesystem
  read-only, and then clears DEAD again. No on-disk metadata is
  corrupted in this case.

With CONFIG_BTRFS_ASSERT=y, both reach a BUG().

Change the ASSERT() into a proper rejection to avoid triggering a BUG().

Fixes: 6c83d153ed86 ("btrfs: add new ioctl to wait for cleaned subvolumes")
Cc: stable@vger.kernel.org
Suggested-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Link: https://lore.kernel.org/linux-btrfs/dd97efe9-91ec-495b-b698-acff1447421c@gmx.com/
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
[ Rework the commit message, drop the ad-hoc RW check. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
fs/btrfs/ioctl.c

index 9857d6a9d45605370bb90de8f64546a0a57d000a..215e3220df7faffa2066d6dc48ee37473e6467d2 100644 (file)
@@ -5166,8 +5166,12 @@ static int btrfs_ioctl_subvol_sync(struct btrfs_fs_info *fs_info, void __user *a
                        return -ENOENT;
 
                wait_for_deletion = true;
-               ASSERT(root_flags & BTRFS_ROOT_SUBVOL_DEAD, "root_flags=0x%llx",
-                      root_flags);
+               if (unlikely(!(root_flags & BTRFS_ROOT_SUBVOL_DEAD))) {
+                       btrfs_err(fs_info,
+                                 "subvol %llu has refs 0 without DEAD flag",
+                                 args.subvolid);
+                       return -EUCLEAN;
+               }
                sched_ret = schedule_timeout_interruptible(HZ);
                /* Early wake up or error. */
                if (sched_ret != 0)