lkml.org 
[lkml]   [2022]   [Jul]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2] ntfs: fix use-after-free in ntfs_ucsncmp()
Date
> Fix this by adding sanity check on end address of attibute name string.

> diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
> index 4de597a83b88..9ab8766872d2 100644
> --- a/fs/ntfs/attrib.c
> +++ b/fs/ntfs/attrib.c
> @@ -592,8 +592,12 @@ static int ntfs_attr_find(const ATTR_TYPE type, const ntfschar *name,
> a = (ATTR_RECORD*)((u8*)ctx->attr +
> le32_to_cpu(ctx->attr->length));
> for (;; a = (ATTR_RECORD*)((u8*)a + le32_to_cpu(a->length))) {
> - if ((u8*)a < (u8*)ctx->mrec || (u8*)a > (u8*)ctx->mrec +
> - le32_to_cpu(ctx->mrec->bytes_allocated))
> + u8 *mrec_end = (u8 *)ctx->mrec +
> + le32_to_cpu(ctx->mrec->bytes_allocated);
> + u8 *name_end = (u8 *)a + le16_to_cpu(a->name_offset) +
> + a->name_length;

In my opinion, name_length field just means the number of characters,
yet each character is a ntfschar type. So name should be
name_length * sizeof(ntfschar) bytes. The example is at
https://elixir.bootlin.com/linux/v5.19-rc5/source/fs/ntfs/attrib.c#L1667

> + if ((u8*)a < (u8*)ctx->mrec || (u8*)a > mrec_end ||
> + name_end > mrec_end)
> break;
> ctx->attr = a;
> if (unlikely(le32_to_cpu(a->type) > le32_to_cpu(type) ||
> --

\
 
 \ /
  Last update: 2022-07-09 02:56    [W:0.158 / U:0.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site