* [BUG] xfs: inode buffer verifier reads past a buffer shorter than a block
@ 2026-12-06 12:44 Piyus Kedia
2026-12-06 12:44 ` [PATCH] xfs: count the inodes an inode buffer holds in its verifier Piyus Kedia
0 siblings, 1 reply; 2+ messages in thread
From: Piyus Kedia @ 2026-12-06 12:44 UTC (permalink / raw)
To: Carlos Maiolino, linux-xfs
Cc: Darrick J . Wong, Dave Chinner, linux-kernel, Kapil Vaswani
Hi,
xfs_inode_buf_verify() counts the inodes in an inode buffer by
rounding the buffer's length up to whole filesystem blocks, and checks
that many. Log recovery reads inode buffers at the length a log item
gives, which can be less than a block, and the verifier then reads
inodes past the buffer, inside mount(2). The code is identical in
7.4-rc5, mainline and xfs/for-next, and the line numbers below hold
for all three.
fs/xfs/libxfs/xfs_inode_buf.c:52
ni = XFS_BB_TO_FSB(mp, bp->b_length) * mp->m_sb.sb_inopblock;
An inode buffer read through the inode geometry is whole blocks, but
xlog_recover_inode_ra_pass2() and xlog_recover_inode_commit_pass2()
read one at an inode item's ilf_len, which is not checked. The image
below is one filesystem whose dirty log has a field of its inode items
changed and the record's CRC recomputed; the same log written back
unchanged recovers and mounts on every kernel we ran. With ilf_len 1
on a 1 KiB-block image, readahead verification reads the second inode
of a 512-byte buffer:
BUG: KASAN: slab-out-of-bounds in xfs_inode_buf_verify+0x13c/0x2f0
Read of size 4 at addr ffff888050551660 by task kworker/1:0/26
Workqueue: xfs-buf/loop0 xfs_buf_ioend_work
xfs_inode_buf_verify (fs/xfs/libxfs/xfs_inode_buf.c:59)
xfs_buf_ioend (fs/xfs/xfs_buf.c:1141)
process_one_work (kernel/workqueue.c:3497)
The buggy address is located 96 bytes to the right of
allocated 512-byte region (kmalloc-rcl-512, xfs_buf_alloc() from
xlog_recover_inode_ra_pass2())
af133e8606d3 ("xfs: verify inode buffers as they are read from
disk") brought that count in; the check it replaced in
xfs_imap_to_bp() used BBTOB(imap->im_len) >> sb_inodelog. By the
source, a buffer item replayed as an inode buffer (XFS_BLFT_DINO_BUF)
with a blf_len of less than a block reaches the same verifier; we have
not run that.
Impact - who can trigger it
- A crafted XFS image with a dirty log has to be mounted; all of the
above happens inside mount(2), before the filesystem can be used.
XFS is not FS_USERNS_MOUNT, so mount(2) needs CAP_SYS_ADMIN in the
initial user namespace: root, or a service that mounts on a user's
behalf. We have not tested whether desktop auto-mounting of
removable media mounts such an image. Recovery runs at every mount
of a dirty log but -o norecovery (which has to be read-only); a
read-only mount (MS_RDONLY) replays the log too (we measured that
with a dquot item). The image chooses its own geometry and
contents.
- What is read: the magic, version and di_next_unlinked of the
inodes past the buffer, up to the rest of the block. They decide
only whether the buffer passes the verifier; in our runs it failed
and the mount failed.
This one was not hit by the fuzzer: it came up while we checked the
inode item's ilf_len, which the fuzzer had not changed. On
ksmbd-for-next (d70570cf8003, 2026-12-04), our upstream base, whose
fs/xfs is identical to mainline master (9437ee8b6cf6), with KASAN.
fs/xfs/libxfs/xfs_inode_buf.c is also unchanged in mainline
c3500c5ef648 (2026-12-04) and in xfs-linux for-next (ab1a77ab136c),
where the patch applies as is.
Same config and image before and after, the patch the only change;
one boot per run:
without the patch KASAN report
ilf_len 1 (a 512-byte inode buffer) 2 of 2
with the patch, kasan_multi_shot on: no report, alone in one boot
and together with our other log recovery fixes in two more; the
verifier checks the one inode the buffer holds, which in our image
fails it ("Metadata corruption detected at xfs_inode_buf_verify"),
and the mount fails with EUCLEAN.
control, the same log written back unchanged: both kernels recover
and mount.
A patch follows in reply to this mail. It counts the inodes in the
buffer's own length, as xfs_imap_to_bp() did before af133e8606d3.
xfsprogs shares this file.
We are reporting four related log recovery bugs separately, each with
its own patch: buffer items whose dirty bitmap outruns their regions,
inode items whose fork regions are missing, an unchecked inode
ilf_boffset, and an unchecked dquot qlf_boffset.
This came up in the analysis of crashes found by AI-driven fuzzing
built on top of syzkaller; the analysis was then checked by hand
against the code, and the access above was reproduced. The
reproducer is one program that carries its filesystem image, and we
are happy to send it on request.
Kapil Vaswani
Piyus Kedia
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH] xfs: count the inodes an inode buffer holds in its verifier
2026-12-06 12:44 [BUG] xfs: inode buffer verifier reads past a buffer shorter than a block Piyus Kedia
@ 2026-12-06 12:44 ` Piyus Kedia
0 siblings, 0 replies; 2+ messages in thread
From: Piyus Kedia @ 2026-12-06 12:44 UTC (permalink / raw)
To: Carlos Maiolino, linux-xfs
Cc: Darrick J . Wong, Dave Chinner, linux-kernel, Kapil Vaswani
xfs_inode_buf_verify() checks the magic, version and di_next_unlinked
of every inode in an inode buffer, and counts them by rounding the
buffer's length up to whole filesystem blocks:
ni = XFS_BB_TO_FSB(mp, bp->b_length) * mp->m_sb.sb_inopblock;
An inode buffer read through the inode geometry is whole blocks, but
log recovery reads one at the length a log item gives: an inode item's
ilf_len, in xlog_recover_inode_ra_pass2() and
xlog_recover_inode_commit_pass2(), and a buffer item's blf_len when
xlog_recover_validate_buf_type() gives an inode buffer its ops. An
inode item with ilf_len 1 on a filesystem with 1 KiB blocks has the
readahead verifier read the second inode of a 512-byte buffer when a
crafted image is mounted:
BUG: KASAN: slab-out-of-bounds in xfs_inode_buf_verify+0x13c/0x2f0
Read of size 4 at addr ffff888050551660 by task kworker/1:0/26
Workqueue: xfs-buf/loop0 xfs_buf_ioend_work
xfs_inode_buf_verify (fs/xfs/libxfs/xfs_inode_buf.c:59)
xfs_buf_ioend (fs/xfs/xfs_buf.c:1141)
process_one_work (kernel/workqueue.c:3497)
The buggy address is located 96 bytes to the right of
allocated 512-byte region (kmalloc-rcl-512, xfs_buf_alloc() for
xlog_recover_inode_ra_pass2())
Count the inodes in the buffer's own length, as the check this
verifier replaced did (BBTOB(imap->im_len) >> sb_inodelog in
xfs_imap_to_bp()).
We found this with a syzkaller-based fuzzing harness driven by an AI tool.
Fixes: af133e8606d3 ("xfs: verify inode buffers as they are read from disk")
Closes: https://lore.kernel.org/r/xfs-inode-buf-verify-count.20261206@iiitd.ac.in/
Cc: stable@vger.kernel.org
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
Tested on ksmbd-for-next (d70570cf8003), whose fs/xfs is identical to
mainline master (9437ee8b6cf6) and to xfs/for-next (ab1a77ab136c),
where this applies as is; KASAN, the same config and image
before and after. A dirty log with one field changed and the record
CRC recomputed:
before an inode item with ilf_len 1 on a 1 KiB-block filesystem:
KASAN at xfs_inode_buf.c:59 in 2 of 2 runs
after no report, alone and with our other log recovery fixes; the
verifier checks only the inode the buffer holds, which in
our image failed it, and the mount fails with EUCLEAN
fs/xfs/libxfs/xfs_inode_buf.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
index 8c9d296ebfe9..e0540022824d 100644
--- a/fs/xfs/libxfs/xfs_inode_buf.c
+++ b/fs/xfs/libxfs/xfs_inode_buf.c
@@ -47,9 +47,11 @@ xfs_inode_buf_verify(
int ni;
/*
- * Validate the magic number and version of every inode in the buffer
+ * Validate the magic number and version of every inode in the buffer.
+ * Count the inodes the buffer holds: log recovery reads inode buffers
+ * at whatever length a log item gives, not always whole blocks.
*/
- ni = XFS_BB_TO_FSB(mp, bp->b_length) * mp->m_sb.sb_inopblock;
+ ni = BBTOB(bp->b_length) >> mp->m_sb.sb_inodelog;
for (i = 0; i < ni; i++) {
struct xfs_dinode *dip;
xfs_agino_t unlinked_ino;
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 12:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06 12:44 [BUG] xfs: inode buffer verifier reads past a buffer shorter than a block Piyus Kedia
2026-12-06 12:44 ` [PATCH] xfs: count the inodes an inode buffer holds in its verifier Piyus Kedia
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®