mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Cheng Yongkang <teel4res@gmail.com>, David Sterba <dsterba@suse.com>
Cc: Chris Mason <mason@kernel.org>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT
Date: Mon, 26 Oct 2026 11:43:49 +1030	[thread overview]
Message-ID: <dd97efe9-91ec-495b-b698-acff1447421c@gmx.com> (raw)
In-Reply-To: <20261025180258.349175-1-teel4res@gmail.com>



在 2026/10/26 04:32, Cheng Yongkang 写道:
> A crafted image can leave a tree-root ROOT_ITEM with refs==0 and without
> BTRFS_ROOT_SUBVOL_DEAD, plus a matching orphan item.  Mount accepts it,
> and btrfs_ioctl_subvol_sync() then reaches
> 
>    ASSERT(root_flags & BTRFS_ROOT_SUBVOL_DEAD, ...)
> 
> which is BUG() on CONFIG_BTRFS_ASSERT=y.
> 
> Return -EUCLEAN instead of asserting, and log the inconsistent state.
> 
> The ioctl BUG was reproduced in 2/4 baseline boots (the other two lost
> a race to the same image's unrelated cleaner WARN).  With this change
> the ioctl returns -EUCLEAN and no BUG; a normal btrfs mount/write/
> readback/check regression passes.
> 
> Assisted-by: LLM
> Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
> ---
>   fs/btrfs/ioctl.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 576cd76..00eab0b 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -5149,8 +5149,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 (!(root_flags & BTRFS_ROOT_SUBVOL_DEAD)) {

Use unlikely().


Secondly it's still possible to hit a subvolume without DEAD flag at 
runtime.

btrfs_ioctl_snap_destroy()
|- btrfs_delete_subvolume()
    |- btrfs_set_root_flags( | SUBVOL_DEAD)
    |- Some error hit, goto out_end_trans or out_undead tag
    |- btrfs_set_root_flags( & ~SUBVOL_DEAD)

Although in that case, the transaction is already aborted, so no on-disk 
metadata is corrupted.

Then someone can still call the ioctl on the subvolume and trigger the 
warning.

Although this is not a regression, but a pre-existing problem, I'd 
suggest to do some writeable checks for the SYNC_WAIT ioctl.
> +			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)


      reply	other threads:[~2026-10-26  1:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25 18:02 Cheng Yongkang
2026-10-26  1:13 ` Qu Wenruo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dd97efe9-91ec-495b-b698-acff1447421c@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mason@kernel.org \
    --cc=teel4res@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®