mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 and writes at an unchecked ilf_boffset
Date: Sun,  6 Dec 2026 18:13:05 +0530	[thread overview]
Message-ID: <xfs-log-inode-boffset.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() finds the inode at the
item's ilf_boffset in the buffer it reads for it, without checking the
offset against that buffer.  Our fuzzer found an out-of-bounds read
this way, inside mount(2); with the inode magic placed where the read
lands, the recovered inode is written past the buffer, which we
measured.  The code is identical in 7.4-rc5, mainline and
xfs/for-next, and the line numbers below hold for all three.

  fs/xfs/xfs_inode_item_recover.c:351
	error = xfs_buf_read(mp->m_ddev_targp, in_f->ilf_blkno, in_f->ilf_len,
			0, &bp, &xfs_inode_buf_ops);
	...
	dip = xfs_buf_offset(bp, in_f->ilf_boffset);
	...
	if (XFS_IS_CORRUPT(mp, !xfs_verify_magic16(bp, dip->di_magic))) {

ilf_boffset, an int32_t, is not checked against the buffer, so
di_magic is read wherever it points.  9232301894a0 ("xfs: bound inode
fork length against the fork size during log recovery") bounded the
logged forks by the fork sizes of the inode found there; where the
inode is found is not bounded.  The image below is one filesystem
whose dirty log has fields 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.  An inode item read as a 1 KiB buffer
(ilf_len 2) with ilf_boffset 1024:

  BUG: KASAN: slab-out-of-bounds in xlog_recover_inode_commit_pass2+0x298/0x1720
  Read of size 2 at addr ffff888050380c00 by task poc/9458
   xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:362)
   xlog_recover_items_pass2 (fs/xfs/xfs_log_recover.c:2020)
   xlog_recover_commit_trans (fs/xfs/xfs_log_recover.c:2089)
   ...
   xfs_log_mount (fs/xfs/xfs_log.c:621)
  The buggy address is located 0 bytes to the right of
   allocated 1024-byte region (kmalloc-rcl-1k, the inode buffer)

(The fuzzer's ilf_boffset of 65536 in a 16 KiB buffer reads 48 KiB
past it: KASAN called that use-after-free in both of its runs; in
ours it did so once, and once the read hit memory KASAN did not
object to, the magic check failed and so did the mount.)  If di_magic
matches, the recovered inode is written there: with ilf_boffset 1022
and "IN" in the last two bytes of the 1 KiB buffer, the magic check
passes, :394 reads di_version past the buffer, and
xfs_log_dinode_to_disk() (:177 on) stores the core past it:

  BUG: KASAN: slab-out-of-bounds in xfs_log_dinode_to_disk+0x55/0x6a0
  Write of size 2 at addr ffff8880258cb400 by task poc/9448
   xfs_log_dinode_to_disk (fs/xfs/xfs_inode_item_recover.c:177)
   xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:495)
  The buggy address is located 0 bytes to the right of
   allocated 1024-byte region (kmalloc-rcl-1k, the inode buffer)

followed by stores at 2, 3, 4, 6 and 10 bytes past it and more that
the console dropped; KASAN's stack depot then warned about its own
corrupted metadata (lib/stackdepot.c:506), and the mount failed with
EUCLEAN when the recovered inode was verified.

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: di_magic at dip, anywhere within +-2 GiB of the
    buffer.  If it reads "IN", the recovered inode core (176 bytes),
    its forks and its CRC are stored there.  Measured: stores 0 to 10
    bytes past a 1 KiB buffer and more, from an image that put the
    magic in the buffer's last two bytes.

  - The writes land in whatever follows the buffer, here a 1 KiB
    kmalloc object and its KASAN metadata (the stack depot warned that
    it was corrupted).  We have not looked at what such writes could
    be made to do on a kernel without KASAN.

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
    ilf_boffset 1024 in a 1 KiB buffer                2 of 2
    ilf_boffset 65536 in a 16 KiB buffer              1 of 2
    ilf_boffset 1022, magic planted, multi_shot       the writes above

  with the patch, kasan_multi_shot on: no report, alone in two
  boots that each ran the three 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 one of

    Bad inode log item, ino 8256: offset 1024 in 1024-byte buffer.
    Bad inode log item, ino 8256: offset 65536 in 16384-byte buffer.
    Bad inode log item, ino 8256: offset 1022 in 1024-byte buffer.

  controls, the same logs written back unchanged: both kernels recover
  and mount.

ilf_len is not checked either.  The patch compares ilf_boffset with
the buffer actually read, so it holds whatever ilf_len is; a buffer
shorter than a block reaches the inode buffer verifier first, which
has its own over-read, reported separately.

A patch follows in reply to this mail.  After the buffer is read, it
checks that the whole inode at ilf_boffset lies inside the buffer; 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,
inode items whose fork regions are missing, an unchecked dquot
qlf_boffset, and the inode buffer verifier's inode count.  Our report
on logged fork roots (<xfs-log-fork-root.20261206@iiitd.ac.in>)
changes the same function; the two patches apply in either order.

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

             reply	other threads:[~2026-12-06 12:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 12:43 Piyus Kedia [this message]
2026-12-06 12:43 ` [PATCH] xfs: check the inode log item's buffer offset 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-boffset.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®