public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ntfs: fix s64 overflow in ntfs_mapping_pairs_decompress()
@ 2026-04-22  3:05 Zhan Xusheng
  2026-04-22  7:45 ` Hyunchul Lee
  0 siblings, 1 reply; 8+ messages in thread
From: Zhan Xusheng @ 2026-04-22  3:05 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: linux-fsdevel, linux-kernel, Zhan Xusheng

In ntfs_mapping_pairs_decompress(), deltaxcn is decoded from the
on-disk mapping pairs array and negative values are rejected, but
large positive values up to S64_MAX pass through unchecked.  The
subsequent `vcn += deltaxcn` can then wrap the s64 accumulator to a
negative value, breaking the monotonically-increasing VCN invariant
that ntfs_rl_vcn_to_lcn() and related helpers rely on.

A crafted NTFS image with a single 8-byte run-length of S64_MAX
triggers this when lowest_vcn > 0, leading to incorrect LCN lookups
and potential reads/writes to wrong disk sectors.

Add an overflow check before the addition and treat the on-disk data
as corrupt (-EIO) when the result would exceed S64_MAX.

Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
 fs/ntfs/runlist.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs/runlist.c b/fs/ntfs/runlist.c
index b213b4976d2b..a32affb57d29 100644
--- a/fs/ntfs/runlist.c
+++ b/fs/ntfs/runlist.c
@@ -823,7 +823,16 @@ struct runlist_element *ntfs_mapping_pairs_decompress(const struct ntfs_volume *
 		 * element.
 		 */
 		rl[rlpos].length = deltaxcn;
-		/* Increment the current vcn by the current run length. */
+		/*
+		 * Increment the current vcn by the current run length.
+		 * Both are non-negative here; guard against s64 overflow
+		 * from a crafted mapping pairs array to preserve the
+		 * monotonically-increasing vcn invariant.
+		 */
+		if (unlikely(deltaxcn > S64_MAX - vcn)) {
+			ntfs_error(vol->sb, "VCN overflow in mapping pairs array.");
+			goto err_out;
+		}
 		vcn += deltaxcn;
 		/*
 		 * There might be no lcn change at all, as is the case for
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-04-27 13:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-22  3:05 [PATCH] ntfs: fix s64 overflow in ntfs_mapping_pairs_decompress() Zhan Xusheng
2026-04-22  7:45 ` Hyunchul Lee
2026-04-22  9:47   ` [PATCH v2] ntfs: fix VCN " Zhan Xusheng
2026-04-22 23:57     ` Hyunchul Lee
2026-04-23  4:52       ` [PATCH v3] " Zhan Xusheng
2026-04-27  4:52         ` Hyunchul Lee
2026-04-27 13:34         ` Namjae Jeon
2026-04-27  0:18       ` [PATCH v2] " Hyunchul Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox