* Re: ntfs3: two out-of-bounds reads in $LogFile replay (restart page resize, restart table offset)
[not found] <c21c25-ntfs3-logfile-oob-20261106@qq.com>
@ 2026-11-06 15:30 ` Guikun Yang
[not found] ` <c26c27-ntfs3-logfile-more-20261106@qq.com>
1 sibling, 0 replies; 3+ messages in thread
From: Guikun Yang @ 2026-11-06 15:30 UTC (permalink / raw)
To: Konstantin Komarov; +Cc: ntfs3, linux-fsdevel, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ntfs3: two out-of-bounds reads in $LogFile replay (restart page resize, restart table offset)
[not found] ` <c26c27-ntfs3-logfile-more-20261106@qq.com>
@ 2026-11-07 14:00 ` Guikun Yang
0 siblings, 0 replies; 3+ messages in thread
From: Guikun Yang @ 2026-11-07 14:00 UTC (permalink / raw)
To: Konstantin Komarov; +Cc: ntfs3, linux-fsdevel, linux-kernel
Hi,
One more landing of the undo-pass lookup gap reported as item 3 - same
missing check, different field. The redo pass validates the
open-attribute table lookup three ways before using it; the undo pass
validates none of them.
Redo pass (fs/ntfs3/fslog.c:5105-5124):
t16 = le16_to_cpu(lrh->target_attr);
if (t16 >= bytes_per_rt(oatbl)) /* 1. bounds */
... goto out;
oe = Add2Ptr(oatbl, t16);
if (oe->next != RESTART_ENTRY_ALLOCATED_LE) /* 2. allocated */
... goto out;
oa = oe->ptr;
if (!oa) { /* 3. non-NULL */
... goto out;
}
Undo pass (fslog.c:5251):
oe = Add2Ptr(oatbl, le16_to_cpu(lrh->target_attr));
oa = oe->ptr;
t16 = le16_to_cpu(lrh->lcns_follow);
if (!t16)
goto add_allocated_vcns;
is_mapped = run_lookup_entry(oa->run1, ...);
Item 3 in my previous mail was the missing bounds check (an index past
the table reads outside the allocation). The same PoC with one field
changed - lcns_follow from 0 to 1 - selects an in-bounds but unused
entry (target_attr 0x18 points at entry 0 of a table with used=total=0,
so oe->ptr is NULL) and reaches run_lookup_entry(oa->run1, ...) with
oa == NULL:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001
KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
RIP: 0010:log_replay+0xabe6/0xf580 [ntfs3]
ntfs_loadlog_and_replay -> ntfs_fill_super
So one fix - mirroring all three redo-pass checks at the undo-pass
lookup, ideally in one helper shared by both - covers both landings and
the third one (in-bounds, allocated, but oe->ptr NULL) that I have not
built separately.
Both PoCs are the same four-record forged log as before, differing by
one field each; 3/3 with panic_on_warn=1, mount(2) alone, clean image
mounts fine. Unchanged in mainline as of 2026-11-07.
The reproducer bundle for items 3-5 plus this one is available on
request as a single archive - same base image, per-finding one-field
patches.
Thanks,
Guikun Yang
^ permalink raw reply [flat|nested] 3+ messages in thread
* ntfs3: two out-of-bounds reads in $LogFile replay (restart page resize, restart table offset)
@ 2026-11-06 14:00 Guikun Yang
0 siblings, 0 replies; 3+ messages in thread
From: Guikun Yang @ 2026-11-06 14:00 UTC (permalink / raw)
To: Konstantin Komarov; +Cc: ntfs3, linux-fsdevel, linux-kernel
Hi,
Two related out-of-bounds reads are reachable through $LogFile replay
during mount. Both are in fs/ntfs3/fslog.c, both need only a crafted
volume whose restart area is internally consistent (valid USA, client
list, seq_num_bits), and both are unfixed in current mainline.
BUG: KASAN: slab-out-of-bounds Read in log_replay+0x...
BUG: KASAN: slab-out-of-bounds Read in check_rstbl+0x...
Both reproduce 3/3 (6/6 for #1) with panic_on_warn=1; the unmodified
volume mounts cleanly as a control. Trigger is mount(2) alone; no file
is opened.
## 1. Restart page buffer not resized when sys_page_size is adopted
log_replay() starts with the host page size:
log->page_size = norm_file_page(PAGE_SIZE, &log->l_size, true); /* 4096 */
log->one_page_buf = kmalloc(log->page_size, GFP_NOFS);
The restart page is read while log->page_size is still 4096, so
log->rst_info.r_page is a 4096-byte allocation. Later the on-disk page
size is adopted:
t32 = le32_to_cpu(log->rst_info.r_page->sys_page_size);
if (log->page_size != t32) {
log->page_size = norm_file_page(t32, &log->l_size, ...);
if (log->page_size > old_page_size) {
buf = krealloc(log->one_page_buf, log->page_size, ...);
log->one_page_buf = buf;
}
}
5a35454179 ("fs/ntfs3: resize log->one_page_buf when adopting on-disk
page size") added exactly this krealloc, but it only covers
one_page_buf. rst_info.r_page stays at the old size and is never
re-read, and the restart area is then copied out of it:
ra2 = Add2Ptr(log->rst_info.r_page, ra_off);
log->ra_size = le16_to_cpu(ra2->ra_len); /* raw on-disk u16 */
memcpy(ra, ra2, log->ra_size);
The destination ra is kzalloc(log->restart_size), sized from the
adopted page size and large enough. The source ra2 points into the
still-4096-byte r_page, and ra_len is bounded only by
sys_page_size - ra_off. With sys_page_size = 8192 (a legal power of
two, accepted by norm_file_page) and ra_len just past 4096 - ra_off,
the memcpy reads past the end of the kmalloc-4k object (80 bytes in
our run). The branch at fslog.c:4181
memcpy(ra->clients, Add2Ptr(ra2, t16), le16_to_cpu(ra2->ra_len) - t16);
has the same problem from the other side.
## 2. Restart table redo_off is unbounded
The restart tables (transaction table, dirty page table, open
attribute table) are loaded through a shared path:
t16 = le16_to_cpu(lrh->redo_off);
rt = Add2Ptr(lrh, t16);
t32 = rec_len - t16;
if (!check_rstbl(rt, t32))
goto out;
redo_off is only checked for 8-byte alignment (check_log_rec()), not
against rec_len, and rec_len - t16 is an unsigned subtraction that
wraps when redo_off > rec_len. check_rstbl() then dereferences
rt->size as its first statement - either from the wrapped length or,
when redo_off lands at the end of the record buffer, from memory past
the page buffer entirely.
check_add_overflow() protection added for the record header only
covers client_data_len + rec_hdr_len; these in-record offsets are not
covered. In our run redo_off = 0xFD0 puts rt exactly at the end of the
4 KiB record buffer:
BUG: KASAN: slab-out-of-bounds in check_rstbl+0x...
Read of size 2 ...
check_rstbl -> log_replay -> ntfs_loadlog_and_replay -> ntfs_fill_super
Allocated by: read_log_page -> find_log_rec -> read_log_rec_lcb
All three table load sites share this code, so one forged offset
reaches the transaction table, the dirty page table and the open
attribute table alike.
## Environment common to both
The forged $LogFile is internally consistent - update sequence array,
client list, seq_num_bits - so every existing check passes; only the
missing bounds above are abused. The replay machinery needed two
details in last_log_lsn(): clearing RESTART_SINGLE_PAGE_IO, and giving
the tail page's last_end_lsn a different sequence number so the
major-1 tail-page logic does not rewrite file_off back to the LSN.
The reproducer (one image builder covering both cases, ready-made
images, serial logs) is available on request.
Both code paths are unchanged in mainline as of 2026-11-06.
## Suggested fixes
1. Re-read (or reallocate) rst_info.r_page at the adopted page size
before ra2 is derived from it; alternatively bound ra_len by the
size the page buffer was actually allocated with.
2. In the table load path, validate redo_off <= rec_len before
computing rt, and use check_add_overflow() for rec_len - t16 (or
reject redo_off > rec_len outright), matching what
e2fcb0040b did for client_data_len.
Thanks,
Guikun Yang
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-07 16:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <c21c25-ntfs3-logfile-oob-20261106@qq.com>
2026-11-06 15:30 ` ntfs3: two out-of-bounds reads in $LogFile replay (restart page resize, restart table offset) Guikun Yang
[not found] ` <c26c27-ntfs3-logfile-more-20261106@qq.com>
2026-11-07 14:00 ` Guikun Yang
2026-11-06 14:00 Guikun Yang
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®