From: Siddharth Mishra <smish149@asu.edu>
To: David Sterba <dsterba@suse.com>
Cc: Qu Wenruo <wqu@suse.com>, Chris Mason <mason@kernel.org>,
linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
Siddharth Mishra <brightprogrammer@asu.edu>,
stable@vger.kernel.org
Subject: [PATCH] btrfs: do not check support for an invalid sectorsize
Date: Mon, 2 Nov 2026 16:30:41 -0700 [thread overview]
Message-ID: <20261102233041.310900-1-smish149@asu.edu> (raw)
From: Siddharth Mishra <brightprogrammer@asu.edu>
[BUG]
Mounting an image whose super block has an invalid sectorsize (for
example 4097) on a kernel with CONFIG_BTRFS_ASSERT=y triggers a BUG:
BTRFS error (device loop0): invalid sectorsize 4097
assertion failed: is_power_of_2(blocksize) &&
blocksize >= BTRFS_MIN_BLOCKSIZE && blocksize <= BTRFS_MAX_BLOCKSIZE,
in fs/btrfs/fs.c:137
kernel BUG at fs/btrfs/fs.c:137!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:btrfs_supported_blocksize.cold (fs/btrfs/fs.c:137)
Call Trace:
btrfs_validate_super (fs/btrfs/disk-io.c:2525)
open_ctree (fs/btrfs/disk-io.c:3507)
btrfs_get_tree.cold (fs/btrfs/super.c:2133)
vfs_get_tree (fs/super.c:1943)
fc_mount (fs/namespace.c:1282)
path_mount (fs/namespace.c:4337)
__x64_sys_mount (fs/namespace.c:4542)
[CAUSE]
btrfs_validate_super() rejects the sectorsize because it is not a power
of 2, but it does not stop there: it goes on to report all invalid
fields. The next check passes the same sectorsize to
btrfs_supported_blocksize(), which requires a validated value and
asserts it since commit d728f2e5f8a0 ("btrfs: simplify support block
size check").
[FIX]
Only check whether a sectorsize is supported after it passed the
validity check. An invalid sectorsize is still rejected with -EINVAL,
and the misleading second message "sectorsize 4097 not yet supported"
is no longer printed.
This bug was found by fuzzing. The cause was analysed and the fix was
written with the help of an AI tool. Tested on btrfs for-next
(d6f76ca0a70d) and on v7.4-rc1, with KASAN and CONFIG_BTRFS_ASSERT=y:
without the fix, mounting the image hits the BUG above; with the fix,
the mount fails with -EINVAL and only "invalid sectorsize 4097" is
printed.
A crafted image (22 KiB, xz) and a C reproducer are available on request.
Fixes: d728f2e5f8a0 ("btrfs: simplify support block size check")
Cc: stable@vger.kernel.org # 6.18+
Signed-off-by: Siddharth Mishra <brightprogrammer@asu.edu>
---
fs/btrfs/disk-io.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8e8fb942d..b348591f8 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2520,9 +2520,7 @@ int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
sectorsize > BTRFS_MAX_METADATA_BLOCKSIZE)) {
btrfs_err(fs_info, "invalid sectorsize %u", sectorsize);
ret = -EINVAL;
- }
-
- if (unlikely(!btrfs_supported_blocksize(sectorsize))) {
+ } else if (unlikely(!btrfs_supported_blocksize(sectorsize))) {
btrfs_err(fs_info,
"sectorsize %u not yet supported for page size %lu",
sectorsize, PAGE_SIZE);
base-commit: d6f76ca0a70d0c814731394a625ff0dc1feb390e
--
2.54.0
next reply other threads:[~2026-11-02 23:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 23:30 Siddharth Mishra [this message]
2026-11-02 23:42 ` Qu Wenruo
2026-11-03 0:06 ` Siddharth Mishra
2026-11-03 0:08 ` Qu Wenruo
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=20261102233041.310900-1-smish149@asu.edu \
--to=smish149@asu.edu \
--cc=brightprogrammer@asu.edu \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mason@kernel.org \
--cc=stable@vger.kernel.org \
--cc=wqu@suse.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®