mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH v2] ntfs: fix VCN overflow in ntfs_mapping_pairs_decompress()
@ 2026-04-27  2:26 Zhan Xusheng
  0 siblings, 0 replies; 4+ messages in thread
From: Zhan Xusheng @ 2026-04-27  2:26 UTC (permalink / raw)
  To: Hyunchul Lee; +Cc: linux-kernel, Zhan Xusheng

On Mon, 27 Apr 2026 09:18:38 +0900
Hyunchul Lee <hyc.lee@gmail.com> wrote:

> Just a gentle ping.
> Please let me know your thoughts.

Hi Hyunchul,

v3 was already sent with your overflows_type() suggestion applied:
https://lore.kernel.org/all/20260423045227.249857-1-zhanxusheng@xiaomi.com/

Please let me know if it looks good to you.

Thanks,
Zhan Xusheng

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: [PATCH] ntfs: fix s64 overflow in ntfs_mapping_pairs_decompress()
@ 2026-04-22  7:45 Hyunchul Lee
  2026-04-22  9:47 ` [PATCH v2] ntfs: fix VCN " Zhan Xusheng
  0 siblings, 1 reply; 4+ messages in thread
From: Hyunchul Lee @ 2026-04-22  7:45 UTC (permalink / raw)
  To: Zhan Xusheng; +Cc: Namjae Jeon, linux-fsdevel, linux-kernel, Zhan Xusheng

Hello Zhan,

2026년 4월 22일 (수) 오후 12:08, Zhan Xusheng <zhanxusheng1024@gmail.com>님이 작성:
>
> 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;

Could you use check_add_overflow() here?
In addition, attr->data.non_resident.lowest_vcn also needs to be
validated with overflows_type().

>                 /*
>                  * There might be no lcn change at all, as is the case for
> --
> 2.43.0
>
>


-- 
Thanks,
Hyunchul

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-27  2:26 [PATCH v2] ntfs: fix VCN overflow in ntfs_mapping_pairs_decompress() Zhan Xusheng
  -- strict thread matches above, loose matches on Subject: below --
2026-04-22  7:45 [PATCH] ntfs: fix s64 " Hyunchul Lee
2026-04-22  9:47 ` [PATCH v2] ntfs: fix VCN " Zhan Xusheng
2026-04-22 23:57   ` Hyunchul Lee
2026-04-27  0:18     ` Hyunchul Lee

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®