mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: linkinjeon@kernel.org, hyc.lee@gmail.com
Cc: liubaolin12138@163.com, ernest.borowski.git@proton.me,
	ntfs@lists.linux.dev, linux-kernel@vger.kernel.org,
	zhanxusheng@xiaomi.com, syzbot@syzkaller.appspotmail.com,
	stable@vger.kernel.org
Subject: [PATCH] ntfs: map a read past the end of the runlist as a hole
Date: Wed,  2 Dec 2026 15:24:45 +0800	[thread overview]
Message-ID: <20261202072445.1975205-1-zhanxusheng1024@gmail.com> (raw)

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


             reply	other threads:[~2026-12-02  7:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:24 Zhan Xusheng [this message]
2026-12-02 10:38 ` liubaolin
2026-12-02 11:17 ` liubaolin
2026-12-02 11:28   ` liubaolin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202072445.1975205-1-zhanxusheng1024@gmail.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=ernest.borowski.git@proton.me \
    --cc=hyc.lee@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liubaolin12138@163.com \
    --cc=ntfs@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=syzbot@syzkaller.appspotmail.com \
    --cc=zhanxusheng@xiaomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®