public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	linux-kernel@vger.kernel.org,
	Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: [PATCH v2] fs/ntfs3: reject  invalid evcn == (u64)-1 in mi_enum_attr()
Date: Mon, 27 Apr 2026 11:47:30 +0800	[thread overview]
Message-ID: <20260427034730.38012-1-zhanxusheng@xiaomi.com> (raw)
In-Reply-To: <20260425114246.545866b6@pumpkin>

In mi_enum_attr(), the start/end VCN validation for non-resident
attributes is:
    if (svcn > evcn + 1) goto out;

This relies on evcn + 1 arithmetic, which overflows when evcn
is (u64)-1 and wraps to 0, breaking the intended range check.

In that case, malformed on-disk metadata such as:
    svcn == 0, evcn == (u64)-1
may incorrectly pass validation.

VCN (virtual cluster number) represents cluster indices within
a NTFS volume and is bounded by the physical size of the filesystem.
Therefore, values near or equal to (u64)-1 are not valid on-disk
VCN values and should be treated as malformed metadata.

Reject this case to prevent arithmetic overflow while preserving
the original semantics of allowing svcn <= evcn + 1.

Fixes: 013ff63b6494 ("fs/ntfs3: Add more attributes checks in mi_enum_attr()")
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
 fs/ntfs3/record.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 32bdb034c2a3..ad752bebb66c 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -202,7 +202,7 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,
 	u32 used = le32_to_cpu(rec->used);
 	u32 t32, off, asize, prev_type;
 	u16 t16;
-	u64 data_size, alloc_size, tot_size;
+	u64 svcn, evcn, data_size, alloc_size, tot_size;
 
 	if (!attr) {
 		u32 total = le32_to_cpu(rec->total);
@@ -311,7 +311,10 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,
 		goto out;
 
 	/* Check start/end vcn. */
-	if (le64_to_cpu(attr->nres.svcn) > le64_to_cpu(attr->nres.evcn) + 1)
+	svcn = le64_to_cpu(attr->nres.svcn);
+	evcn = le64_to_cpu(attr->nres.evcn);
+	/* evcn == (u64)-1 is invalid on-disk VCN */
+	if (evcn == (u64)-1 || svcn > evcn + 1)
 		goto out;
 
 	data_size = le64_to_cpu(attr->nres.data_size);
-- 
2.43.0


  reply	other threads:[~2026-04-27  3:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24  2:46 [PATCH] fs/ntfs3: reject evcn == U64_MAX in mi_enum_attr() Zhan Xusheng
2026-04-24  9:20 ` David Laight
2026-04-24 13:20   ` Zhan Xusheng
2026-04-24 15:15     ` David Laight
2026-04-25  2:03       ` Zhan Xusheng
2026-04-25 10:42         ` David Laight
2026-04-27  3:47           ` Zhan Xusheng [this message]
2026-04-27  3:50           ` [PATCH v3] fs/ntfs3: reject invalid evcn == (u64)-1 " Zhan Xusheng

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=20260427034730.38012-1-zhanxusheng@xiaomi.com \
    --to=zhanxusheng1024@gmail.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --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