* [BUG] xfs: inode log item recovery reads fork regions the item does not have
@ 2026-12-06 12:42 Piyus Kedia
2026-12-06 12:42 ` [PATCH] xfs: check the inode log item's region count in recovery Piyus Kedia
0 siblings, 1 reply; 2+ messages in thread
From: Piyus Kedia @ 2026-12-06 12:42 UTC (permalink / raw)
To: Carlos Maiolino, linux-xfs
Cc: Darrick J . Wong, Aldo Ariel Panzardo, linux-kernel, Kapil Vaswani
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
^ permalink raw reply [flat|nested] 2+ messages in thread* [PATCH] xfs: check the inode log item's region count in recovery
2026-12-06 12:42 [BUG] xfs: inode log item recovery reads fork regions the item does not have Piyus Kedia
@ 2026-12-06 12:42 ` Piyus Kedia
0 siblings, 0 replies; 2+ messages in thread
From: Piyus Kedia @ 2026-12-06 12:42 UTC (permalink / raw)
To: Carlos Maiolino, linux-xfs
Cc: Darrick J . Wong, Aldo Ariel Panzardo, linux-kernel, Kapil Vaswani
xlog_recover_inode_commit_pass2() takes the inode core from ri_buf[1]
and the data and attr fork regions from ri_buf[2] and from ri_buf[2] or
ri_buf[3], as ilf_fields says. ri_buf[] has as many entries as
ilf_size asked for, the item may have been committed with fewer, and
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 is read from
ri_buf[3], one entry past the array: first by the bound that
commit 9232301894a0 ("xfs: bound inode fork length against the fork
size during log recovery") added, then, as since before git, for the
copy itself (:560, :561):
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, xlog_recover_add_to_trans())
With ilf_size 1 the core itself is read from past the array.
Before reading the buffer, check that the item has the core and one
region for each fork ilf_fields names.
We found this with a syzkaller-based fuzzing harness driven by an AI tool.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Closes: https://lore.kernel.org/r/xfs-log-inode-regions.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 ilf_size 3 with data and attr fork flags: KASAN at :523 in
3 of 3 runs; ilf_size 1: at :369 and a fault, 1 of 1
after no report; the mount fails with EUCLEAN and the message
added
control the same logs written back unchanged: both kernels recover
and mount
This touches xlog_recover_inode_commit_pass2() as our patches "xfs:
bound logged inode fork roots and the fork offset in log recovery" and
"xfs: check the inode log item's buffer offset in recovery" do; the
three apply in any order, and the check of a logged root the first one
adds reads the ri_buf[] entry this one makes sure exists.
fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/fs/xfs/xfs_inode_item_recover.c b/fs/xfs/xfs_inode_item_recover.c
index 8da95131ab55..fd86715f9ec3 100644
--- a/fs/xfs/xfs_inode_item_recover.c
+++ b/fs/xfs/xfs_inode_item_recover.c
@@ -320,6 +320,7 @@ xlog_recover_inode_commit_pass2(
char *dest;
int error;
int attr_index;
+ int nregions;
uint fields;
struct xfs_log_dinode *ldip;
uint isize;
@@ -348,6 +349,25 @@ xlog_recover_inode_commit_pass2(
}
trace_xfs_log_recover_inode_recover(log, in_f);
+ /*
+ * ilf_size sized the item's regions, but nothing ties it to
+ * ilf_fields: after the format come the inode core and one region for
+ * each fork that ilf_fields says was logged. Make sure they are all
+ * there before they are indexed below.
+ */
+ nregions = 2;
+ if (in_f->ilf_fields & XFS_ILOG_DFORK)
+ nregions++;
+ if (in_f->ilf_fields & XFS_ILOG_AFORK)
+ nregions++;
+ if (XFS_IS_CORRUPT(mp, item->ri_cnt < nregions)) {
+ xfs_alert(mp,
+ "Bad inode log item, ino %lld: %d regions, fields 0x%x need %d.",
+ in_f->ilf_ino, item->ri_cnt, in_f->ilf_fields, nregions);
+ error = -EFSCORRUPTED;
+ goto error;
+ }
+
error = xfs_buf_read(mp->m_ddev_targp, in_f->ilf_blkno, in_f->ilf_len,
0, &bp, &xfs_inode_buf_ops);
if (error)
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 12:42 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:42 [BUG] xfs: inode log item recovery reads fork regions the item does not have Piyus Kedia
2026-12-06 12:42 ` [PATCH] xfs: check the inode log item's region count in recovery 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®