mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
	Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: [PATCH] fs/ntfs3: fix out-of-bounds read in ni_query_ads()
Date: Wed,  7 Oct 2026 19:22:47 +0800	[thread overview]
Message-ID: <20261007112247.2518924-1-zhanxusheng@xiaomi.com> (raw)

ni_query_ads() copies the base inode's named $DATA attribute names,
newline separated, into the caller's iterator:

	if (vbo + err > *pos) {
		size_t off = *pos - vbo;

		used = err - off;
		done = copy_to_iter(Add2Ptr(buf, off), min(used, bytes), iter);
	}
	...
	*pos += done;
	if (done >= bytes)
		break;
	bytes -= done;
	vbo += err;

The guard establishes *pos < vbo + err but not *pos >= vbo, and off is a
size_t.  copy_to_iter() returns the number of bytes it managed to copy,
which is zero when the destination cannot be written.  *pos then stays
put while vbo advances by the full entry length, so the next iteration
runs with *pos < vbo.

For two streams whose names are 40 and 30 bytes, the second iteration
gets off = (size_t)-41 and used = 72.  min(used, bytes) keeps 72 and
Add2Ptr(buf, off) resolves to buf - 41, so copy_to_iter() reads 72 bytes
starting 41 bytes before the kmalloc(PAGE_SIZE) buffer and copies them
to userspace.

ntfs_init_ads_node() accepts the query_streams name on any regular file
(fs/ntfs3/inode.c:540) and ntfs_init_fs_context() leaves ads enabled, so
a read of file:query_streams into an unwritable buffer reaches this on a
volume with two streams on one file.

Stop the walk once *pos has fallen behind the current entry.

Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
Fixes: be310476e886 ("fs/ntfs3: Add basic support for alternative data streams")
---
 fs/ntfs3/frecord.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index bead01a953f3f..5a88c875cb2a0 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -3430,6 +3430,10 @@ ssize_t ni_query_ads(struct ntfs_inode *ni, loff_t *pos, struct iov_iter *iter)
 			break;
 		}
 
+		/* copy_to_iter() below may have copied nothing. */
+		if (*pos < vbo)
+			break;
+
 		if (vbo + err > *pos) {
 			size_t off = *pos - vbo;
 			used = err - off;

base-commit: 22430ae5d90ab288b0ee2ad99ae941f4a666b694
-- 
2.43.0


                 reply	other threads:[~2026-10-07 11:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261007112247.2518924-1-zhanxusheng@xiaomi.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    --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®