From: Weiming Shi <bestswngs@gmail.com>
To: Carlos Maiolino <cem@kernel.org>, "Darrick J . Wong" <djwong@kernel.org>
Cc: linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org,
xmei5@asu.edu, Weiming Shi <bestswngs@gmail.com>,
Dave Chinner <dgc@kernel.org>
Subject: [PATCH v2 1/2] xfs: reject log items with missing regions during recovery
Date: Fri, 17 Jul 2026 12:24:07 -0700 [thread overview]
Message-ID: <20260717192408.109168-2-bestswngs@gmail.com> (raw)
In-Reply-To: <20260717192408.109168-1-bestswngs@gmail.com>
Each recovered log item is assembled in xlog_recover_add_to_trans() into
an ri_buf[] of ri_total (= the format's declared region count) slots, and
the regions actually logged are counted in ri_cnt. Nothing checks that
ri_cnt reached ri_total once the transaction is complete, so a crafted or
truncated log can present an item whose format declares more regions than
were logged. The trailing ri_buf[] slots are then NULL, and the reorder,
readahead and replay code dereference them.
For example, an XFS_LI_INODE item declaring two regions but logging only
the format region leaves ri_buf[1] NULL, and mount-time recovery faults
dereferencing it as the log dinode:
KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
RIP: xlog_recover_inode_commit_pass2 (fs/xfs/xfs_inode_item_recover.c:370)
Call Trace:
xlog_recover_items_pass2 (fs/xfs/xfs_log_recover.c:2011)
xlog_recover_commit_trans (fs/xfs/xfs_log_recover.c:2078)
xlog_recovery_process_trans (fs/xfs/xfs_log_recover.c:2328)
xlog_recover_process_data (fs/xfs/xfs_log_recover.c:2502)
xlog_recover (fs/xfs/xfs_log_recover.c:3486)
xfs_log_mount (fs/xfs/xfs_log.c:667)
xfs_mountfs (fs/xfs/xfs_mount.c:1039)
xfs_fs_fill_super (fs/xfs/xfs_super.c:1965)
get_tree_bdev_flags (fs/super.c:1680)
__x64_sys_mount (fs/namespace.c:4433)
Whether an item logged all its declared regions is a generic log format
property, not a per-item-type concern, so reject any item with a missing
region in xlog_recover_commit_trans() before the item ops run.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Xiang Mei <xmei5@asu.edu>
Suggested-by: Dave Chinner <dgc@kernel.org>
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
---
fs/xfs/xfs_log_recover.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 09e6678ca487..5250d512a392 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -2039,6 +2039,17 @@ xlog_recover_commit_trans(
hlist_del_init(&trans->r_list);
+ /*
+ * Reject an item missing a region its format declared; the NULL slot
+ * would be dereferenced by the reorder and replay code.
+ */
+ list_for_each_entry(item, &trans->r_itemq, ri_list) {
+ if (XFS_IS_CORRUPT(log->l_mp,
+ item->ri_total == 0 ||
+ item->ri_cnt != item->ri_total))
+ return -EFSCORRUPTED;
+ }
+
error = xlog_recover_reorder_trans(log, trans, pass);
if (error)
return error;
--
2.43.0
next prev parent reply other threads:[~2026-07-17 19:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 19:24 [PATCH v2 0/2] xfs: add a log item verifier pass to recovery Weiming Shi
2026-07-17 19:24 ` Weiming Shi [this message]
2026-07-17 22:59 ` [PATCH v2 1/2] xfs: reject log items with missing regions during recovery Dave Chinner
2026-07-17 19:24 ` [PATCH v2 2/2] xfs: verify recovered inode log items in pass1 Weiming Shi
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=20260717192408.109168-2-bestswngs@gmail.com \
--to=bestswngs@gmail.com \
--cc=cem@kernel.org \
--cc=dgc@kernel.org \
--cc=djwong@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=xmei5@asu.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.