From: Qu Wenruo <wqu@suse.com>
To: Siddharth Mishra <smish149@asu.edu>, David Sterba <dsterba@suse.com>
Cc: Boris Burkov <boris@bur.io>, Chris Mason <mason@kernel.org>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH 2/2] btrfs: tree-checker: reject extent owner ref without simple quota
Date: Tue, 3 Nov 2026 15:10:30 +1030 [thread overview]
Message-ID: <9b8d9f77-981e-4bcc-9d30-5c53a2c1d1b2@suse.com> (raw)
In-Reply-To: <20261103034932.1790235-3-smish149@asu.edu>
在 2026/11/3 14:19, Siddharth Mishra 写道:
> [BUG]
> An extent item can contain an owner ref. The owner ref is correct only
> when the super block has the SIMPLE_QUOTA bit. If the bit is not set,
> check_extent_item() gives a WARN_ON() and then accepts the leaf :
>
> case BTRFS_EXTENT_OWNER_REF_KEY:
> WARN_ON(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA));
> break;
>
> For all other incorrect inline refs, check_extent_item() returns
> -EUCLEAN. After the tree-checker accepts the leaf, a free of the extent
> calls btrfs_get_extent_inline_ref_type(). This function ASSERT()s the
> SIMPLE_QUOTA bit.
>
> I made a crafted image : an owner ref, no SIMPLE_QUOTA bit, and no quota
> tree. On a kernel with CONFIG_BTRFS_ASSERT=y, I removed the file of the
> extent. At the next commit, btrfs frees the extent and gives :
I don't think this should go into BUG section, but CAUSE.
>
> WARNING: fs/btrfs/tree-checker.c:1782 at __btrfs_check_leaf
> assertion failed: btrfs_fs_incompat(fs_info, SIMPLE_QUOTA),
> in fs/btrfs/extent-tree.c:354
> kernel BUG at fs/btrfs/extent-tree.c:354!
> Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
> RIP: 0010:btrfs_get_extent_inline_ref_type.cold
> (fs/btrfs/extent-tree.c:354)
> Call Trace:
> lookup_inline_extent_backref (fs/btrfs/extent-tree.c:919)
> lookup_extent_backref (fs/btrfs/extent-tree.c:1100)
> __btrfs_free_extent.isra.0 (fs/btrfs/extent-tree.c:3319)
> __btrfs_run_delayed_refs (fs/btrfs/extent-tree.c:2134)
> btrfs_run_delayed_refs (fs/btrfs/extent-tree.c:2246)
> btrfs_commit_transaction (fs/btrfs/transaction.c:2278)
> ksys_sync (fs/sync.c:104)
>
> Without CONFIG_BTRFS_ASSERT, the kernel gives only the WARN_ON(). Then
> btrfs continues to use the owner ref.
>
> [CAUSE]
> For an owner ref without the SIMPLE_QUOTA bit, the tree-checker gives a
> WARN_ON() and keeps the leaf. For all other inline ref types, it
> rejects the leaf. Two sources can put owner refs without the
> SIMPLE_QUOTA bit on a disk : a damaged or crafted image, and a kernel
> without commit f2363e6fcc79 ("btrfs: fix transaction atomicity bug when
> enabling simple quotas").
>
> [FIX]
> Reject the leaf with -EUCLEAN, as for all other incorrect inline refs.
> Then btrfs finds the problem when it reads the leaf, and the ASSERT() is
> not reached.
>
> syzbot reported the WARN_ON() and the ASSERT() in 2024 without a
> reproducer. Both reports were closed for inactivity. At that time, the
> WARN_ON() was noted as something that "should be handled in a better
> way". I found the cause during the analysis of a fuzzing report. An AI
> tool helped. I tested with a crafted image on btrfs for-next
> (d6f76ca0a70d). Without the patch, the kernel gives the WARN_ON(), and
> the BUG above with CONFIG_BTRFS_ASSERT=y. With the patch, the
> tree-checker rejects the leaf ("extent owner ref without simple quota")
> and the mount fails with -EIO. There is no WARN_ON() and no BUG. A
> clean simple quota filesystem still writes data, frees extents and
> mounts again without errors. The fstests group qgroup has no new
> failure (34 passed, 3 not run here). The crafted image and the commands
> are available on request.
Again, remove the last paragraph.
>
> Link: https://syzkaller.appspot.com/bug?extid=d7d1fc7e21835ca19219
> Link: https://syzkaller.appspot.com/bug?extid=4983e68a6d77180bfe33
> Fixes: d9a620f77e33 ("btrfs: new inline ref storing owning subvol of data extents")
Again, I don't think this really counts as a fixes.
Or all hardening would be considered as a fix, which makes no sense.
> Cc: stable@vger.kernel.org # 6.7+
> Signed-off-by: Siddharth Mishra <smish149@asu.edu>
> ---
> fs/btrfs/tree-checker.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
> index 0d75cb537..5c44bed99 100644
> --- a/fs/btrfs/tree-checker.c
> +++ b/fs/btrfs/tree-checker.c
> @@ -1779,7 +1779,11 @@ static int check_extent_item(struct extent_buffer *leaf,
> inline_refs += btrfs_shared_data_ref_count(leaf, sref);
> break;
> case BTRFS_EXTENT_OWNER_REF_KEY:
> - WARN_ON(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA));
> + if (unlikely(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA))) {
> + extent_err(leaf, slot,
> + "extent owner ref without simple quota");
> + return -EUCLEAN;
> + }
> break;
> default:
> extent_err(leaf, slot, "unknown inline ref type: %u",
next prev parent reply other threads:[~2026-11-03 4:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 3:49 [PATCH 0/2] btrfs: tree-checker: reject simple quota metadata without SIMPLE_QUOTA Siddharth Mishra
2026-11-03 3:49 ` [PATCH 1/2] btrfs: tree-checker: validate qgroup status item Siddharth Mishra
2026-11-03 4:36 ` Qu Wenruo
2026-11-03 3:49 ` [PATCH 2/2] btrfs: tree-checker: reject extent owner ref without simple quota Siddharth Mishra
2026-11-03 4:40 ` Qu Wenruo [this message]
2026-11-03 5:15 ` Siddharth Mishra
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=9b8d9f77-981e-4bcc-9d30-5c53a2c1d1b2@suse.com \
--to=wqu@suse.com \
--cc=boris@bur.io \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=smish149@asu.edu \
--cc=stable@vger.kernel.org \
/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®