aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
authorYunpeng Tian <shionthanatos@gmail.com>2026-05-04 07:19:43 -0700
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>2026-05-26 11:58:23 +0200
commitc4e5d32cb5226660d9e0f6b9e01d98ba0d8872dc (patch)
tree84bc37b80f33264c87729dbadd873faba6c11fe7 /fs
parent4a81c53124fc28473a353d041dccfe558e68096c (diff)
downloadlinux-next-history-c4e5d32cb5226660d9e0f6b9e01d98ba0d8872dc.tar.gz
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 b2bc7c44ed17 ("fs/ntfs3: Fix slab-out-of-bounds read in DeleteIndexEntryRoot") and commit 0ca0485e4b2e ("fs/ntfs3: validate rec->used in journal-replay file record check"). Fixes: b46acd6a6a62 ("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>
Diffstat (limited to 'fs')
-rw-r--r--fs/ntfs3/fslog.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index 66ead9db26ee7..767f7cdab8d15 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -4564,11 +4564,21 @@ copy_lcns:
* whole routine a loop, case Lcns do not fit below.
*/
t16 = le16_to_cpu(lrh->lcns_follow);
- for (i = 0; i < t16; i++) {
- size_t j = (size_t)(le64_to_cpu(lrh->target_vcn) -
- le64_to_cpu(dp->vcn));
- dp->page_lcns[j + i] = lrh->page_lcns[i];
- }
+ t32 = le32_to_cpu(dp->lcns_follow);
+ if (le64_to_cpu(lrh->target_vcn) < le64_to_cpu(dp->vcn)) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ for (i = 0; i < t16; i++) {
+ size_t j = (size_t)(le64_to_cpu(lrh->target_vcn) -
+ le64_to_cpu(dp->vcn));
+ if (j >= t32 || i >= t32 - j) {
+ err = -EINVAL;
+ goto out;
+ }
+ dp->page_lcns[j + i] = lrh->page_lcns[i];
+ }
goto next_log_record_analyze;