mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guikun Yang <yangguikun19@qq.com>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: ntfs3@lists.linux.dev, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [Bug report] ntfs3: attr_insert_range() shifts nres.evcn of a resident attribute past the end of the MFT record buffer
Date: Sun, 15 Nov 2026 20:00:00 +0800	[thread overview]
Message-ID: <tencent_65517E3E665127A973DF0B23554E9DA6A208@qq.com> (raw)

Hi,

fallocate(FALLOC_FL_INSERT_RANGE) on a crafted NTFS image reaches a
segment-enumeration loop in attr_insert_range() that shifts the
svcn/evcn of every following DATA attribute without checking whether
the enumerated attribute is non-resident. A resident attribute placed
at the end of an extension MFT record makes le64_add_cpu(&nres.evcn,
len) do an 8-byte read-modify-write past the end of the 1024-byte
record buffer.

  BUG: KASAN: slab-out-of-bounds in attr_insert_range+0x14a1/0x1670 [ntfs3]
  Read of size 8 at addr ffff8880062d9400 by task init/1
  ...
  allocated 1024-byte region [ffff8880062d9000, ffff8880062d9400)
  The buggy address is located 0 bytes to the right

Reproduced 3/3. The negative control changes only that attribute's
type from ATTR_DATA to ATTR_END; fallocate() then returns 0 with no
KASAN report.

## This is the other branch of the function

bf9a6578e0 ("fs/ntfs3: fix slab-out-of-bounds write in
attr_insert_range()", in 7.4) fixed the **resident** branch: the
inline-data memmove used the insert length as both source offset and
copy size. The current tree has that fix:

  memmove(data + vbo + bytes, data + vbo, data_size - vbo);

The **non-resident** branch - the loop below it - is a separate path
that still has no bound (fs/ntfs3/attrib.c):

  next_svcn = le64_to_cpu(attr->nres.evcn) + 1;

  while ((attr = ni_enum_attr_ex(ni, attr, &le, &mi)) &&
         attr->type == ATTR_DATA && !attr->name_len) {
          le64_add_cpu(&attr->nres.svcn, len);
          le64_add_cpu(&attr->nres.evcn, len);
          ...
  }

The loop condition checks only the attribute type and name. The
attributes come from ni_enum_attr_ex(), which walks the attribute
list into extension MFT records, and does not imply any residency
check. nres.evcn has no meaning for a resident attribute: in that
layout the first four bytes at the same offset are res.data_size,
and the 8-byte RMW reaches past the record buffer when the attribute
is placed at its tail.

Both branches are reachable from the same fallocate() syscall; the
resident one is fixed, this one is not. Current mainline
(fs/ntfs3/attrib.c) still has the loop verbatim.

## Suggested fix

Reject resident attributes in the enumeration loop:

  while ((attr = ni_enum_attr_ex(ni, attr, &le, &mi)) &&
         attr->type == ATTR_DATA && !attr->name_len) {
+         if (!attr->non_res) {
+                 err = -EFSCORRUPTED;
+                 goto out;
+         }
          le64_add_cpu(&attr->nres.svcn, len);
          le64_add_cpu(&attr->nres.evcn, len);

Checking at the ni_enum_attr_ex() level would cover other callers
with the same assumption, but the local check is the minimal fix
for this path.

## Reproducer

The crafted image places a resident DATA attribute at the end of an
extension MFT record so that the enumerated attribute is resident and
tail-aligned. The image builder (mk_patch_record.py), positive and
negative images, a trigger program and a syzkaller-format
`syz_mount_image$ntfs3` reproducer (image embedded as zlib+base64,
followed by openat + fallocate) are in the test bundle.

Available on request.

Tested on 7.3.0 (KASAN, ntfs3 built-in). mainline 2026-11-15 checked.

Thanks,
Guikun Yang


                 reply	other threads:[~2026-11-17  1:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_65517E3E665127A973DF0B23554E9DA6A208@qq.com \
    --to=yangguikun19@qq.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®