mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ntfs: detect mapping-pairs LCN accumulator overflow
@ 2026-06-03 17:41 Samuel Moelius
  2026-06-05 13:44 ` Namjae Jeon
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Moelius @ 2026-06-03 17:41 UTC (permalink / raw)
  To: Namjae Jeon
  Cc: Samuel Moelius, Hyunchul Lee, open list:NTFS FILESYSTEM, open list

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
Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
---
 fs/ntfs/runlist.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs/runlist.c b/fs/ntfs/runlist.c
index e7de3d01257e..e9294a5f4cbf 100644
--- a/fs/ntfs/runlist.c
+++ b/fs/ntfs/runlist.c
@@ -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
-- 
2.43.0


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

* Re: [PATCH] ntfs: detect mapping-pairs LCN accumulator overflow
  2026-06-03 17:41 [PATCH] ntfs: detect mapping-pairs LCN accumulator overflow Samuel Moelius
@ 2026-06-05 13:44 ` Namjae Jeon
  0 siblings, 0 replies; 2+ messages in thread
From: Namjae Jeon @ 2026-06-05 13:44 UTC (permalink / raw)
  To: Samuel Moelius; +Cc: Hyunchul Lee, open list:NTFS FILESYSTEM, open list

On Thu, Jun 4, 2026 at 2:41 AM Samuel Moelius
<sam.moelius@trailofbits.com> wrote:
>
> 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
> Signed-off-by: Samuel Moelius <sam.moelius@trailofbits.com>
Applied it to #ntfs-next.
Thanks!

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

end of thread, other threads:[~2026-06-05 13:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-03 17:41 [PATCH] ntfs: detect mapping-pairs LCN accumulator overflow Samuel Moelius
2026-06-05 13:44 ` Namjae Jeon

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

Powered by JetHome