* [PATCH] ntfs: map a read past the end of the runlist as a hole
@ 2026-12-02 7:24 Zhan Xusheng
2026-12-02 10:38 ` liubaolin
2026-12-02 11:17 ` liubaolin
0 siblings, 2 replies; 4+ messages 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] 4+ messages in thread
* Re: [PATCH] ntfs: map a read past the end of the runlist as a hole
2026-12-02 7:24 [PATCH] ntfs: map a read past the end of the runlist as a hole Zhan Xusheng
@ 2026-12-02 10:38 ` liubaolin
2026-12-02 11:17 ` liubaolin
1 sibling, 0 replies; 4+ messages in thread
From: liubaolin @ 2026-12-02 10:38 UTC (permalink / raw)
To: Zhan Xusheng, linkinjeon, hyc.lee
Cc: ernest.borowski.git, ntfs, linux-kernel, zhanxusheng, syzbot, stable
在 2026/12/2 15:24, Zhan Xusheng 写道:
> 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;
Looks good to me.
Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ntfs: map a read past the end of the runlist as a hole
2026-12-02 7:24 [PATCH] ntfs: map a read past the end of the runlist as a hole Zhan Xusheng
2026-12-02 10:38 ` liubaolin
@ 2026-12-02 11:17 ` liubaolin
2026-12-02 11:28 ` liubaolin
1 sibling, 1 reply; 4+ messages in thread
From: liubaolin @ 2026-12-02 11:17 UTC (permalink / raw)
To: Zhan Xusheng, linkinjeon, hyc.lee
Cc: ernest.borowski.git, ntfs, linux-kernel, zhanxusheng, syzbot, stable
在 2026/12/2 15:24, Zhan Xusheng 写道:
> 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;
Hi Xusheng,
This patch looks good to me.
Since "ntfs: trim the sizes after a short write" makes this existing
issue easier to trigger, would you consider submitting the two patches
together as a series, with this fix first?
That would make the intended merge order clear and allow CI to test
both changes together.
Thanks,
Baolin.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ntfs: map a read past the end of the runlist as a hole
2026-12-02 11:17 ` liubaolin
@ 2026-12-02 11:28 ` liubaolin
0 siblings, 0 replies; 4+ messages in thread
From: liubaolin @ 2026-12-02 11:28 UTC (permalink / raw)
To: Zhan Xusheng, linkinjeon, hyc.lee
Cc: ernest.borowski.git, ntfs, linux-kernel, zhanxusheng, syzbot, stable
在 2026/12/2 19:17, liubaolin 写道:
>
>
> 在 2026/12/2 15:24, Zhan Xusheng 写道:
>> 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;
>
> Hi Xusheng,
> This patch looks good to me.
> Since "ntfs: trim the sizes after a short write" makes this existing
> issue easier to trigger, would you consider submitting the two patches
> together as a series, with this fix first?
> That would make the intended merge order clear and allow CI to test
> both changes together.
>
> Thanks,
> Baolin.
Hi Xusheng,
Sorry, I forgot that "ntfs: trim the sizes after a short write" has
already been merged into ntfs-next.
Please disregard my previous email. Apologies for the confusion.
I've reviewed this patch and it looks good to me.
Thanks for submitting it.
Thanks,
Baolin.
Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-02 11:29 UTC | newest]
Thread overview: 4+ messages (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
2026-12-02 10:38 ` liubaolin
2026-12-02 11:17 ` liubaolin
2026-12-02 11:28 ` liubaolin
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®