Skip to contentSkip to conversation

ntfs: detect mapping-pairs LCN accumulator overflow

PATCH Applied Samuel Moelius 2 participants 2 messages Jun 3 – Jun 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ntfs: detect mapping-pairs LCN accumulator overflow

The NTFS mapping-pairs parser accumulates relative LCN deltas in a signed integer. A corrupted attribute can drive that addition past the representable range.

One corrupt runlist shape sets the accumulated LCN to S64_MAX and then adds a delta of 1 in the next mapping-pairs entry.

Signed overflow is undefined and can turn an invalid runlist into a different set of physical clusters.

Check the LCN addition for overflow before storing the next run.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 fs/ntfs/runlist.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ntfs/runlist.c +5 -1
index e7de3d01257e..e9294a5f4cbf 100644
@@ -860,7 +860,11 @@ struct runlist_element *ntfs_mapping_pairs_decompress(const struct ntfs_volume *
 			for (deltaxcn = (s8)buf[b--]; b > b2; b--)
 				deltaxcn = (deltaxcn << 8) + buf[b];
 			/* Change the current lcn to its new value. */
-			lcn += deltaxcn;
+			if (unlikely(check_add_overflow(lcn, deltaxcn, &lcn))) {
+				ntfs_error(vol->sb,
+						"LCN overflow in mapping pairs array.");
+				goto err_out;
+			}
 #ifdef DEBUG
 			/*
 			 * On NTFS 1.2-, apparently can have lcn == -1 to
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 8 lines · Samuel Moelius

The NTFS mapping-pairs parser accumulates relative LCN deltas in a signed integer. A corrupted attribute can drive that addition past the representable range.

One corrupt runlist shape sets the accumulated LCN to S64_MAX and then adds a delta of 1 in the next mapping-pairs entry.

Quoted 7 lines

Signed overflow is undefined and can turn an invalid runlist into a different set of physical clusters.

Check the LCN addition for overflow before storing the next run.

Assisted-by Codex:gpt-5.5-cyber-preview

Applied it to #ntfs-next.
Thanks!