Skip to content

Commit 57382ec

Browse files
Yunpeng Tianaalexandrovich
authored andcommitted
fs/ntfs3: validate Dirty Page Table capacity in log_replay copy_lcns
In the analysis pass of $LogFile journal replay, log_replay() copies LCNs from each action log record into an existing Dirty Page Table (DPT) entry without bounding the destination index. A crafted NTFS image with DPT entry lcns_follow=1 and an action log record with lcns_follow=2 produces a kernel slab out-of-bounds write at mount time: BUG: KASAN: slab-out-of-bounds in log_replay+0x654c/0xdb60 Write of size 8 at addr ffff8880095e1040 by task mount Two attacker-controlled fields can drive j+i past the allocated page_lcns[] array: 1. dp->lcns_follow (capacity) can be smaller than lrh->lcns_follow. 2. lrh->target_vcn may be smaller than dp->vcn, making the u64 subtraction wrap to a huge size_t. Validate target VCN delta and per-record LCN count against the DPT entry capacity, bail via the existing out: cleanup label with -EINVAL. This mirrors the bounds-check pattern added in commit b2bc7c4 ("fs/ntfs3: Fix slab-out-of-bounds read in DeleteIndexEntryRoot") and commit 0ca0485 ("fs/ntfs3: validate rec->used in journal-replay file record check"). Fixes: b46acd6 ("fs/ntfs3: Add NTFS journal") Reported-by: Yunpeng Tian <shionthanatos@gmail.com> Reported-by: Mingda Zhang <npczmd@qq.com> Reported-by: Gongming Wang <gmwgg05@gmail.com> Reported-by: Peiyuan Xu <paulbucket12@gmail.com> Reported-by: Qinrun Dai <jupmouse@gmail.com> Cc: stable@vger.kernel.org Signed-off-by: Yunpeng Tian <shionthanatos@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 932fa0c commit 57382ec

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

fs/ntfs3/fslog.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,11 +4564,21 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
45644564
* whole routine a loop, case Lcns do not fit below.
45654565
*/
45664566
t16 = le16_to_cpu(lrh->lcns_follow);
4567-
for (i = 0; i < t16; i++) {
4568-
size_t j = (size_t)(le64_to_cpu(lrh->target_vcn) -
4569-
le64_to_cpu(dp->vcn));
4570-
dp->page_lcns[j + i] = lrh->page_lcns[i];
4571-
}
4567+
t32 = le32_to_cpu(dp->lcns_follow);
4568+
if (le64_to_cpu(lrh->target_vcn) < le64_to_cpu(dp->vcn)) {
4569+
err = -EINVAL;
4570+
goto out;
4571+
}
4572+
4573+
for (i = 0; i < t16; i++) {
4574+
size_t j = (size_t)(le64_to_cpu(lrh->target_vcn) -
4575+
le64_to_cpu(dp->vcn));
4576+
if (j >= t32 || i >= t32 - j) {
4577+
err = -EINVAL;
4578+
goto out;
4579+
}
4580+
dp->page_lcns[j + i] = lrh->page_lcns[i];
4581+
}
45724582

45734583
goto next_log_record_analyze;
45744584

0 commit comments

Comments
 (0)