Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] xfs: validate intended file sizes in recovered exchange intents
@ 2026-12-03 16:40 Kyuwon Cho
  2026-12-03 21:18 ` Dave Chinner
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 16:40 UTC (permalink / raw)
  To: Carlos Maiolino, Darrick J. Wong; +Cc: linux-xfs

Recovery validates that the intended file sizes in an XMI log item are
nonnegative, but it does not check them against the exchange offsets.  A
corrupted item can therefore describe an exchange starting inside both
files while setting both intended sizes to zero.

Recovery applies those sizes after exchanging the mappings, leaving
mapped blocks beyond EOF.  A later size change encounters the resulting
folio and warns:

  WARNING: fs/iomap/buffered-io.c:1710 at iomap_zero_range
  RIP: iomap_zero_range (fs/iomap/buffered-io.c:1710)
  Call Trace:
   xfs_zero_range (fs/xfs/xfs_iomap.c:2393)
   xfs_vn_setattr_size (fs/xfs/xfs_iops.c:1011)
   xfs_vn_setattr (fs/xfs/xfs_iops.c:1171)
   notify_change (fs/attr.c:556)
   do_truncate (fs/open.c:68)

When an intent sets file sizes, reject it unless each exchange start
offset is at or before the corresponding intended EOF block.

Fixes: b71ae66863e4 ("xfs: actually recover intended file sizes in xfs_xmi_item_recover_intent")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype.  The reproducer creates and logs an
exchange intent on a fresh XFS image, shuts the filesystem down after
the log write, changes both intended sizes in the XMI item to zero and
repairs the log checksums, then mounts the image to replay the item.
Recovery leaves mappings beyond EOF, and a later truncate warns in
iomap_zero_range().  With the patch recovery rejects the malformed
intent and the warning does not occur.

Found and tested on mainline fe6ff8d5d675 (v7.4-rc5); the patch is
against the XFS for-next tree at 1ebd141a13ae.

 fs/xfs/xfs_exchmaps_item.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/xfs/xfs_exchmaps_item.c b/fs/xfs/xfs_exchmaps_item.c
index 23381cb264c4..5b39085d5371 100644
--- a/fs/xfs/xfs_exchmaps_item.c
+++ b/fs/xfs/xfs_exchmaps_item.c
@@ -352,6 +352,10 @@ xfs_xmi_validate(
 			return false;
 		if ((int64_t)xlf->xmi_isize2 < 0)
 			return false;
+		if (xlf->xmi_startoff1 > XFS_B_TO_FSBT(mp, xlf->xmi_isize1))
+			return false;
+		if (xlf->xmi_startoff2 > XFS_B_TO_FSBT(mp, xlf->xmi_isize2))
+			return false;
 	}
 
 	return true;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 21:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:40 [PATCH] xfs: validate intended file sizes in recovered exchange intents Kyuwon Cho
2026-12-03 21:18 ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox