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

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

On Fri, Dec 04, 2026 at 01:40:21AM +0900, Kyuwon Cho wrote:
> 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.

Please have your test generator write a new fstest for this issue
and submit it. Just submitting a fix is only half the job, because
we still have no way to verify that the regression is fixed.

IMO, any sort of 'llm-guided test generator' should be outputting
fstests format tests and getting ti merged upstream for every issue
that they find. This allows the failure and the fix to be verified
by both upstream (devs) and downstream (distros) with minimal extra
effort. It should be trivial to get an LLM to automatically create a
fstests test for the issue...

> 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;
>  	}

Fix looks fine, though.

Reviewed-by: Dave Chinner <dchinner@redhat.com>

-Dave.
-- 
Dave Chinner
dgc@kernel.org

^ permalink raw reply	[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