* [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit
@ 2026-11-17 16:47 Shashank Mohan Jain
2026-11-17 21:10 ` Brian Foster
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Shashank Mohan Jain @ 2026-11-17 16:47 UTC (permalink / raw)
To: Christian Brauner
Cc: Darrick J. Wong, Matthew Wilcox, Brian Foster, Christoph Hellwig,
Carlos Maiolino, linux-xfs, linux-fsdevel, linux-kernel
iomap_fill_dirty_folios() turns the page index at which the dirty
folio lookup ended into the file offset it returns to the caller:
*start = (pstart << PAGE_SHIFT);
pstart is a pgoff_t. On a 32-bit kernel the shift is done in 32 bits
and the upper bits are lost for every offset at or above 4 GiB.
XFS uses the returned offset in xfs_buffered_write_iomap_begin() to
trim an unwritten mapping to the range covered by the lookup. With the
truncated offset the end of that range is below its start and
xfs_trim_extent() leaves a mapping of zero length. iomap_iter_done()
warns about it,
WARNING: fs/iomap/iter.c:38 at iomap_iter+0x33c/0x36c
WARNING: fs/iomap/iter.c:39 at iomap_iter+0x34c/0x36c
and iomap_zero_range() does not terminate: a mapping of zero length is
what the iterator takes for the start of an iteration, so it asks for
the next mapping again and again without checking how much of the
range is left.
On i386 with XFS (4k blocks) this is enough to trigger it:
fd = open("f", O_RDWR | O_CREAT, 0644);
fallocate(fd, 0, 5ULL << 30, 1 << 20);
ftruncate(fd, (5ULL << 30) + 1000);
ftruncate() never returns. The task spins in iomap_zero_range() with
the inode locked and does not react to SIGKILL. A write behind an
unaligned EOF which is in an unwritten block above 4 GiB fails with
EFSCORRUPTED instead, after "XFS (vda): Access to block zero in inode
132 start_block: 0 start_off: 140002 blkcnt: 0 extent-state: 0":
fallocate(fd, 0, 5ULL << 30, 1000);
pwrite(fd, buf, 100, (5ULL << 30) + 8192);
The same calls work below 4 GiB, and v6.19 behaves like v7.3-rc6.
Cast the page index to loff_t before the shift.
Tested with an i386 kernel in qemu and XFS on a virtio disk: the two
sequences above hang and fail without this change and succeed with
it.
Fixes: 395ed1ef0012 ("iomap: optional zero range dirty folio processing")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
---
Prepared with Claude Code (Anthropic), model Claude Opus 5.5
(claude-opus-5-5).
First sent privately to security@kernel.org on 11 October; Matthew
Wilcox asked for it to be posted as a normal patch. Sorry for the delay.
The code is unchanged in mainline, so this is the same fix, rebased on
666539eecdf4.
fs/iomap/buffered-io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 6d843b1..846f87a 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -1735,7 +1735,7 @@ iomap_fill_dirty_folios(
}
count = filemap_get_folios_dirty(mapping, &pstart, pend, iter->fbatch);
- *start = (pstart << PAGE_SHIFT);
+ *start = (loff_t)pstart << PAGE_SHIFT;
*iomap_flags |= IOMAP_F_FOLIO_BATCH;
return count;
}
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit
2026-11-17 16:47 [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit Shashank Mohan Jain
@ 2026-11-17 21:10 ` Brian Foster
2026-11-17 23:08 ` shashank Jain
2026-11-18 8:25 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Brian Foster @ 2026-11-17 21:10 UTC (permalink / raw)
To: Shashank Mohan Jain
Cc: Christian Brauner, Darrick J. Wong, Matthew Wilcox,
Christoph Hellwig, Carlos Maiolino, linux-xfs, linux-fsdevel,
linux-kernel
On Tue, Nov 17, 2026 at 10:17:56PM +0530, Shashank Mohan Jain wrote:
> iomap_fill_dirty_folios() turns the page index at which the dirty
> folio lookup ended into the file offset it returns to the caller:
>
> *start = (pstart << PAGE_SHIFT);
>
> pstart is a pgoff_t. On a 32-bit kernel the shift is done in 32 bits
> and the upper bits are lost for every offset at or above 4 GiB.
>
> XFS uses the returned offset in xfs_buffered_write_iomap_begin() to
> trim an unwritten mapping to the range covered by the lookup. With the
> truncated offset the end of that range is below its start and
> xfs_trim_extent() leaves a mapping of zero length. iomap_iter_done()
> warns about it,
>
> WARNING: fs/iomap/iter.c:38 at iomap_iter+0x33c/0x36c
> WARNING: fs/iomap/iter.c:39 at iomap_iter+0x34c/0x36c
>
> and iomap_zero_range() does not terminate: a mapping of zero length is
> what the iterator takes for the start of an iteration, so it asks for
> the next mapping again and again without checking how much of the
> range is left.
>
> On i386 with XFS (4k blocks) this is enough to trigger it:
>
> fd = open("f", O_RDWR | O_CREAT, 0644);
> fallocate(fd, 0, 5ULL << 30, 1 << 20);
> ftruncate(fd, (5ULL << 30) + 1000);
>
> ftruncate() never returns. The task spins in iomap_zero_range() with
> the inode locked and does not react to SIGKILL. A write behind an
> unaligned EOF which is in an unwritten block above 4 GiB fails with
> EFSCORRUPTED instead, after "XFS (vda): Access to block zero in inode
> 132 start_block: 0 start_off: 140002 blkcnt: 0 extent-state: 0":
>
> fallocate(fd, 0, 5ULL << 30, 1000);
> pwrite(fd, buf, 100, (5ULL << 30) + 8192);
>
> The same calls work below 4 GiB, and v6.19 behaves like v7.3-rc6.
>
> Cast the page index to loff_t before the shift.
>
> Tested with an i386 kernel in qemu and XFS on a virtio disk: the two
> sequences above hang and fail without this change and succeed with
> it.
>
> Fixes: 395ed1ef0012 ("iomap: optional zero range dirty folio processing")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
> ---
Reviewed-by: Brian Foster <bfoster@redhat.com>
> Prepared with Claude Code (Anthropic), model Claude Opus 5.5
> (claude-opus-5-5).
>
> First sent privately to security@kernel.org on 11 October; Matthew
> Wilcox asked for it to be posted as a normal patch. Sorry for the delay.
> The code is unchanged in mainline, so this is the same fix, rebased on
> 666539eecdf4.
>
> fs/iomap/buffered-io.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index 6d843b1..846f87a 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -1735,7 +1735,7 @@ iomap_fill_dirty_folios(
> }
>
> count = filemap_get_folios_dirty(mapping, &pstart, pend, iter->fbatch);
> - *start = (pstart << PAGE_SHIFT);
> + *start = (loff_t)pstart << PAGE_SHIFT;
> *iomap_flags |= IOMAP_F_FOLIO_BATCH;
> return count;
> }
>
> base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit
2026-11-17 16:47 [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit Shashank Mohan Jain
2026-11-17 21:10 ` Brian Foster
@ 2026-11-17 23:08 ` shashank Jain
2026-11-18 8:25 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: shashank Jain @ 2026-11-17 23:08 UTC (permalink / raw)
To: Christian Brauner
Cc: Darrick J. Wong, Matthew Wilcox, Brian Foster, Christoph Hellwig,
Carlos Maiolino, linux-xfs, linux-fsdevel, linux-kernel
One correction to the note under the ---: it was Willy Tarreau on
security@kernel.org who asked me to post this publicly, not Matthew
Wilcox. Sorry for the noise, Matthew.
Shashank
On Tue, Nov 17, 2026 at 10:18 PM Shashank Mohan Jain <jain.sm@gmail.com> wrote:
>
> iomap_fill_dirty_folios() turns the page index at which the dirty
> folio lookup ended into the file offset it returns to the caller:
>
> *start = (pstart << PAGE_SHIFT);
>
> pstart is a pgoff_t. On a 32-bit kernel the shift is done in 32 bits
> and the upper bits are lost for every offset at or above 4 GiB.
>
> XFS uses the returned offset in xfs_buffered_write_iomap_begin() to
> trim an unwritten mapping to the range covered by the lookup. With the
> truncated offset the end of that range is below its start and
> xfs_trim_extent() leaves a mapping of zero length. iomap_iter_done()
> warns about it,
>
> WARNING: fs/iomap/iter.c:38 at iomap_iter+0x33c/0x36c
> WARNING: fs/iomap/iter.c:39 at iomap_iter+0x34c/0x36c
>
> and iomap_zero_range() does not terminate: a mapping of zero length is
> what the iterator takes for the start of an iteration, so it asks for
> the next mapping again and again without checking how much of the
> range is left.
>
> On i386 with XFS (4k blocks) this is enough to trigger it:
>
> fd = open("f", O_RDWR | O_CREAT, 0644);
> fallocate(fd, 0, 5ULL << 30, 1 << 20);
> ftruncate(fd, (5ULL << 30) + 1000);
>
> ftruncate() never returns. The task spins in iomap_zero_range() with
> the inode locked and does not react to SIGKILL. A write behind an
> unaligned EOF which is in an unwritten block above 4 GiB fails with
> EFSCORRUPTED instead, after "XFS (vda): Access to block zero in inode
> 132 start_block: 0 start_off: 140002 blkcnt: 0 extent-state: 0":
>
> fallocate(fd, 0, 5ULL << 30, 1000);
> pwrite(fd, buf, 100, (5ULL << 30) + 8192);
>
> The same calls work below 4 GiB, and v6.19 behaves like v7.3-rc6.
>
> Cast the page index to loff_t before the shift.
>
> Tested with an i386 kernel in qemu and XFS on a virtio disk: the two
> sequences above hang and fail without this change and succeed with
> it.
>
> Fixes: 395ed1ef0012 ("iomap: optional zero range dirty folio processing")
> Cc: stable@vger.kernel.org
> Assisted-by: LLM
> Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
> ---
> Prepared with Claude Code (Anthropic), model Claude Opus 5.5
> (claude-opus-5-5).
>
> First sent privately to security@kernel.org on 11 October; Matthew
> Wilcox asked for it to be posted as a normal patch. Sorry for the delay.
> The code is unchanged in mainline, so this is the same fix, rebased on
> 666539eecdf4.
>
> fs/iomap/buffered-io.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index 6d843b1..846f87a 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -1735,7 +1735,7 @@ iomap_fill_dirty_folios(
> }
>
> count = filemap_get_folios_dirty(mapping, &pstart, pend, iter->fbatch);
> - *start = (pstart << PAGE_SHIFT);
> + *start = (loff_t)pstart << PAGE_SHIFT;
> *iomap_flags |= IOMAP_F_FOLIO_BATCH;
> return count;
> }
>
> base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit
2026-11-17 16:47 [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit Shashank Mohan Jain
2026-11-17 21:10 ` Brian Foster
2026-11-17 23:08 ` shashank Jain
@ 2026-11-18 8:25 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-11-18 8:25 UTC (permalink / raw)
To: Shashank Mohan Jain
Cc: Darrick J. Wong, Matthew Wilcox, Brian Foster, Christoph Hellwig,
Carlos Maiolino, linux-xfs, linux-fsdevel, linux-kernel
On Tue, 17 Nov 2026 22:17:56 +0530, Shashank Mohan Jain wrote:
> iomap_fill_dirty_folios() turns the page index at which the dirty
> folio lookup ended into the file offset it returns to the caller:
>
> *start = (pstart << PAGE_SHIFT);
>
> pstart is a pgoff_t. On a 32-bit kernel the shift is done in 32 bits
> and the upper bits are lost for every offset at or above 4 GiB.
>
> [...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit
https://git.kernel.org/vfs/vfs/c/4d841b11ce1d
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-18 8:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 16:47 [PATCH] iomap: fix offset truncation in iomap_fill_dirty_folios() on 32-bit Shashank Mohan Jain
2026-11-17 21:10 ` Brian Foster
2026-11-17 23:08 ` shashank Jain
2026-11-18 8:25 ` Christian Brauner
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.