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: Re: ntfs3: two out-of-bounds reads in $LogFile replay (restart page resize, restart table offset)
Date: Fri, 06 Nov 2026 23:30:00 +0800	[thread overview]
Message-ID: <tencent_64A24695F85844F5A5227DB38C503A219B0A@qq.com> (raw)
In-Reply-To: <c21c25-ntfs3-logfile-oob-20261106@qq.com>

Hi,

Two more in the same path while re-checking it - one OOB read, one OOB
write. Same forged-logfile setup as before, mainline 2026-11-06
unchanged.

## 3. Undo pass indexes the open-attribute table without the bound the
   redo pass has

The redo pass bounds target_attr (fs/ntfs3/fslog.c:5105):

  t16 = le16_to_cpu(lrh->target_attr);
  if (t16 >= bytes_per_rt(oatbl)) {
          err = -EINVAL;
          goto out;
  }
  oe = Add2Ptr(oatbl, t16);

The undo pass does not (fslog.c:5251):

  oe = Add2Ptr(oatbl, le16_to_cpu(lrh->target_attr));
  oa = oe->ptr;

check_log_rec() only validates target_attr when lcns_follow != 0, so a
record with undo_op != Noop, lcns_follow = 0 and target_attr beyond
the open-attribute table reaches oe->ptr outside the table:

  BUG: KASAN: slab-out-of-bounds in log_replay+0xafda/0xf580
  Read of size 8 ... located 104 bytes to the right of allocated
  344-byte region (kmalloc-512)
  Allocated by: init_rsttbl -> log_replay

In our run the table is 0x158 bytes and target_attr = 0x1A0.

Suggested fix: mirror the redo-pass check in the undo pass.

## 4. Dirty page table size underflow in the analysis pass ->
   OOB write via copy_lcns()

The number of lcns per dirty-page entry is computed differently in
two places. The version-0 conversion has a guard (fslog.c:4357):

  t16 = le16_to_cpu(dptbl->size);
  if (t16 < sizeof(struct DIR_PAGE_ENTRY)) { ... goto out; }
  t32 = (t16 - sizeof(struct DIR_PAGE_ENTRY)) / sizeof(u64);

The analysis pass does the same subtraction without the guard
(fslog.c:4666):

  if (dptbl) {
          t32 = (le16_to_cpu(dptbl->size) -
                 sizeof(struct DIR_PAGE_ENTRY)) / sizeof(u64);
  }

dptbl->size is an on-disk u16. A table header of size = 0x10, total = 0
passes check_rstbl() (rsize nonzero, no allocated entries) and
check_dp_table() (nothing to enumerate). The unsigned subtraction then
wraps, and copy_lcns() copies lrh->lcns_follow = 0x60 entries into
dp->page_lcns[] of a table that extend_rsttbl() allocated for the
bogus per-entry size - the 29th entry writes past the end:

  BUG: KASAN: slab-out-of-bounds in log_replay+0x8b01/0xf580
  Write of size 8 ... located 0 bytes to the right of allocated
  280-byte region (kmalloc-512)
  Allocated by: extend_rsttbl -> log_replay

This is an OOB write, unlike the three reads reported so far.

Suggested fix: apply the same t16 < sizeof(struct DIR_PAGE_ENTRY)
guard (or reject size < sizeof(struct DIR_PAGE_ENTRY) in
check_rstbl()/check_dp_table() itself, which covers both sites).

## Context

Both reproduce 3/3 with panic_on_warn=1, mount(2) alone, clean image
mounts fine as control. The forged volume is the same one used for
reports 1 and 2 - each of the four findings differs from the last by
one field of one log record.

Four different missing-bound mechanisms are now known on this replay
path: buffer resizing (report 1), unbounded in-record offset (report
2), redo/undo asymmetry (3) and the version-0/analysis asymmetry plus
underflow (4). Given the pattern, a systematic pass over the remaining
offsets in log_replay() may be more effective than fixing these one by
one - happy to test any patch.

Both sites are unchanged in mainline as of 2026-11-06.

Thanks,
Guikun Yang


       reply	other threads:[~2026-11-07  4:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <c21c25-ntfs3-logfile-oob-20261106@qq.com>
2026-11-06 15:30 ` Guikun Yang [this message]
     [not found] ` <c26c27-ntfs3-logfile-more-20261106@qq.com>
2026-11-07 14:00   ` Guikun Yang
2026-11-06 14:00 Guikun Yang

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_64A24695F85844F5A5227DB38C503A219B0A@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®