* [PATCH] ntfs: map a read past the end of the runlist as a hole
@ 2026-12-02 7:24 Zhan Xusheng
0 siblings, 0 replies; only message in thread
From: Zhan Xusheng @ 2026-12-02 7:24 UTC (permalink / raw)
To: linkinjeon, hyc.lee
Cc: liubaolin12138, ernest.borowski.git, ntfs, linux-kernel,
zhanxusheng, syzbot, stable
From: Zhan Xusheng <zhanxusheng@xiaomi.com>
ntfs_read_iomap_begin_non_resident() maps at most the rest of the run
holding the offset. At or past the allocated size,
ntfs_attr_vcn_to_rl() returns the end of the runlist, whose length is 0,
so the rest of the run comes out negative and is returned as the length
of the mapping:
WARNING: fs/iomap/iter.c:39 at iomap_iter
iomap_readahead
ntfs_readahead
read_pages
page_cache_ra_unbounded
do_page_cache_ra
page_cache_ra_order
filemap_fault
Readahead gets there when the file shrinks after the readahead window
was sized from i_size. "ntfs: trim the sizes after a short write"
makes that easy to hit: a write that runs out of space is rolled back
to what it wrote while a MAP_POPULATE mmap() of the file faults it in.
Map the range past the end of the runlist as a hole.
Fixes: b041ca562526 ("ntfs: update iomap and address space operations")
Tested-by: syzbot@syzkaller.appspotmail.com
Cc: stable@vger.kernel.org
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
Found by syzbot ci on "ntfs: trim the sizes after a short write":
https://ci.syzbot.org/series/9c5fb049-3646-4d3b-8f57-43553c5c1bb0
Tested in a VM on ntfs-next 329758f9d73b with the reproducer's image,
the reproducer's mmap() and write() in a loop of 30 runs: the WARNING
fires within 12 runs without the patch, in 5 of 5 boots, and not in 4
boots of 30 runs with it. The read mapping of 19cc08c1a6a6, the base
syzbot ci tested, has the same code. fsx (buffered and O_DIRECT), mmap,
partial O_DIRECT, insert/collapse range and the short write cases give
the same results with and without the patch. No lockdep or KASAN
reports.
fs/ntfs/iomap.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/ntfs/iomap.c b/fs/ntfs/iomap.c
index ce916707f69b..8124c5f62700 100644
--- a/fs/ntfs/iomap.c
+++ b/fs/ntfs/iomap.c
@@ -248,7 +248,12 @@ static int ntfs_read_iomap_begin_non_resident(struct inode *inode, loff_t offset
return -EIO;
}
- if (rl_length && length > rl_length - vcn_ofs)
+ /*
+ * At or past the allocated size, ntfs_attr_vcn_to_rl() returns the
+ * end of the runlist and rl_length is not positive: map the rest as a
+ * hole.
+ */
+ if (rl_length > 0 && length > rl_length - vcn_ofs)
iomap->length = rl_length - vcn_ofs;
else
iomap->length = length;
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-02 7:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 7:24 [PATCH] ntfs: map a read past the end of the runlist as a hole Zhan Xusheng
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®