From: Piyus Kedia <piyus@iiitd.ac.in>
To: Carlos Maiolino <cem@kernel.org>, linux-xfs@vger.kernel.org
Cc: "Darrick J . Wong" <djwong@kernel.org>,
Aldo Ariel Panzardo <qwe.aldo@gmail.com>,
linux-kernel@vger.kernel.org,
Kapil Vaswani <kapil@presceralabs.ai>
Subject: [BUG] xfs: inode log item recovery reads fork regions the item does not have
Date: Sun, 6 Dec 2026 18:12:20 +0530 [thread overview]
Message-ID: <xfs-log-inode-regions.20261206@iiitd.ac.in> (raw)
Hi,
Mounting an XFS image whose log is dirty replays the inode items in
the log, and xlog_recover_inode_commit_pass2() takes the inode core
and the fork regions from item->ri_buf[] by what ilf_fields says was
logged, without checking that the item has that many regions. Our
fuzzer found an out-of-bounds read this way, 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.
xlog_recover_add_to_trans() sizes item->ri_buf[] by the 16-bit size
field of the item's first region, here ilf_size
(xfs_log_recover.c:2235), and the item is committed with however many
regions arrived, ri_cnt <= ri_total; 2094dab19d45 ("xfs: fail
recovery on a committed log item with no regions") rejects only
ri_cnt == 0. 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.
xlog_recover_inode_commit_pass2() takes the inode core from ri_buf[1]
(:369) and the fork regions from ri_buf[2] and ri_buf[2] or [3], as
ilf_fields says (:503, :560); ilf_size and ilf_fields are compared only
by ASSERTs. With ilf_size 3 and both a data and an attr fork flag the
attr fork region is ri_buf[3], first read by the bound that
9232301894a0 ("xfs: bound inode fork length against the fork size
during log recovery") added:
fs/xfs/xfs_inode_item_recover.c:522
if ((fields & (XFS_ILOG_ADATA | XFS_ILOG_AEXT)) &&
item->ri_buf[(fields & XFS_ILOG_DFORK) ? 3 : 2].iov_len >
XFS_DFORK_ASIZE(dip, mp)) {
BUG: KASAN: slab-out-of-bounds in xlog_recover_inode_commit_pass2+0xb47/0x1720
Read of size 8 at addr ffff88804956c638 by task poc/9458
xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:523)
xlog_recover_items_pass2 (fs/xfs/xfs_log_recover.c:2020)
...
xfs_log_mount (fs/xfs/xfs_log.c:621)
The buggy address is located 8 bytes to the right of
allocated 48-byte region (kmalloc-64: ri_buf[] of three entries)
and then by the attr fork copy at :560 and :561 (reported next with
kasan_multi_shot), which has read it since before git; 9232301894a0
added a read before it rather than the bug. With ilf_size 1 the core
pointer itself is read past a one-entry array, at :369, and in our run
the pointer read there faulted.
Our separate report on logged fork roots in the same function
(xfs_bmbt_to_bmdr(), <xfs-log-fork-root.20261206@iiitd.ac.in>) is
related: the check its patch adds reads ri_buf[2 or 3] as well, and
the patch for this report makes sure that entry exists first.
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 struct kvec at ri_buf[3], 16 bytes past a
48-byte array. Its length is compared with the attr fork size and
then sizes the attr fork copy, from its pointer. Those bytes are
the unused tail of a 64-byte kmalloc object, which our kernel
zeroes on allocation (init_on_alloc), so the length read was 0,
nothing was copied, and the mount succeeded, in our runs and the
fuzzer's. Where the tail is not zeroed, those 16 bytes give the
length and the source of the copy into the inode's attr fork (by
the source); we have not tested that. With ilf_size 1 the array
is a 16-byte object and ri_buf[1], the core pointer, is read from
past it: a general protection fault in our run.
Seen on 7.4.0-rc5 (twice) and REPRODUCED ON UPSTREAM: on
ksmbd-for-next (d70570cf8003, 2026-12-04), our upstream base, whose
fs/xfs is identical to mainline master (9437ee8b6cf6), with KASAN.
fs/xfs/xfs_inode_item_recover.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, the fuzzer's own program included where it had one:
without the patch KASAN report
ri_buf[3] (ilf_size 3, data and attr fork) 3 of 3
ri_buf[1] (ilf_size 1) 1 of 1, + fault
with the patch, kasan_multi_shot on: no report, alone in two
boots that each ran both triggers, and together with our other log
recovery fixes in three more (one of them the fuzzer's own
programs). Each mount fails with EUCLEAN after an XFS_IS_CORRUPT()
report and
Bad inode log item, ino 8256: 3 regions, fields 0x83 need 4.
Bad inode log item, ino 8262: 1 regions, fields 0x1 need 2.
controls, the same logs written back unchanged: both kernels recover
and mount.
We looked at every other item type's recovery. EFI/EFD, RUI/RUD,
CUI/CUD, BUI/BUD, XMI/XMD and ATTRI/ATTRD read only ri_buf[0], after
checking its length against the size their format computes, and ATTRI
checks the region count per opcode (ad206ae50eca, d72f2084e309);
ICREATE range-checks every field. Not covered by this patch, by the
source and not run: format regions shorter than the struct read from
them (ICREATE reads 28 bytes with no length check, QUOTAOFF its
qf_flags), and the inode core region, bounded only from above (:475),
which xfs_log_dinode_to_disk() reads to the size its logged di_version
implies. We can send patches for those.
A patch follows in reply to this mail. Before the buffer is read, it
checks that the item has the core and one region for each fork
ilf_fields names; the mount then fails with EUCLEAN and the corruption
report.
We are reporting four related log recovery bugs separately, each with
its own patch: buffer items whose dirty bitmap outruns their regions,
an unchecked inode ilf_boffset, an unchecked dquot qlf_boffset, and
the inode buffer verifier's inode count.
This was found by AI-driven fuzzing built on top of syzkaller; its
analysis was then checked by hand against the code, and every 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
next reply other threads:[~2026-12-06 12:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 12:42 Piyus Kedia [this message]
2026-12-06 12:42 ` [PATCH] xfs: check the inode log item's region count in recovery Piyus Kedia
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=xfs-log-inode-regions.20261206@iiitd.ac.in \
--to=piyus@iiitd.ac.in \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=kapil@presceralabs.ai \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=qwe.aldo@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®