From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C1983624AB for ; Thu, 11 Jun 2026 21:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781213594; cv=none; b=u/HgwIodyFd1dsSQklslYhYSjf5s3MWNVJStCaOaFb8czo1LDHdHon1wbISxkbcbPb7kEHzikNY+N3OQ2zY/4+DLzbFLcXGqQSusnr3bRNmmri6k61PhABoRNHP49tamwy7oTNVme7fRjbWbJu+2aPnDBaF2CW0PQIdR+CaAitU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781213594; c=relaxed/simple; bh=lh3HK6R1DoAVzBu90GhUAqLKTV8x5/+or6ifAKGlGtw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Uou0xCV9XuEAkG4IErQ+C1humfyE7qgreYIBepcSn3RDe3afyFJo+zvNqRO3+Qx+yxVtiWsgiXE22T5ew6Q5jgjOuvv7FBYL60sh6N5eO8Mw3x8v1a2c4h/vw4r9VxdugzVI+1ujlxxiGr5eeo5DMvF3Fydif5Tkdm7d4ezVRWY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openai.com; spf=pass smtp.mailfrom=openai.com; dkim=pass (1024-bit key) header.d=openai.com header.i=@openai.com header.b=RgDv7Fn+; arc=none smtp.client-ip=209.85.222.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=openai.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openai.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=openai.com header.i=@openai.com header.b="RgDv7Fn+" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-91588056619so26669585a.2 for ; Thu, 11 Jun 2026 14:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openai.com; s=google; t=1781213588; x=1781818388; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p04G+PCpwT9vL1o2A8fD6xEdLkQoStt4tP7ytz6vMg0=; b=RgDv7Fn+6gmKDofv1MM3csCGkJXUtGJ13gOMVkPCrVNuTC/OE+9OHNis1FjRvF/tne kH1uuCz3rugfWYlfxToi+Oj6IugZtPEScOhvfmeLzNIHABMY3pQZCRaiDzyOaNf7BhCI KUA67VRDFqMIb2FZfhtN+Ri182oHofRd4Uw6U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781213588; x=1781818388; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=p04G+PCpwT9vL1o2A8fD6xEdLkQoStt4tP7ytz6vMg0=; b=HHK3XNcILcDk4OJWd3Mj3oM2cXkk32dy3LrMG4kHvOgMtoP7WpTgCU73TVO51mDW9F /RIn/lWU1Wd/o+SNwFsG7QLuH7Ioba9kswA5ZHiL8EMjGB9if+t4Vp731ztec99TFTLX QqkbMeU+j5V/3TpJa1Cjvrgv37Kr60puCrHD0WiWh6p4OKyJPShV46HknvDL/FDnStSZ cutxb2ljBxvuDzricmUD/U1GjaLohhCKgi7aIM4/Hk8G5/i/LZZb6LEZ5W+PrIkempCF YWp8eXjuRdAi9U35o76Mee7RXQxj3j/EkYduet0yjp9pxOlqI0MDSDZqrZkTePGzng6e OjEQ== X-Gm-Message-State: AOJu0YwpZz0+QIxtpAqNvTfR8o/98jFmlbRkQ85+jYGHGxZ+pXE1p2Wv lEHlPj7iPG0um8vX0JR9D2KYpZR4pkHCSSTIP6qommv1j3JyBaN+D3arUF/pqYewr9k= X-Gm-Gg: Acq92OGwD8/rtDLlpNO+A2X7CNNcJwuUrubBFn8zz4i8NmLV5kbIOX+OL0qxUH+napC u/hn5buCwSXMI4D8hC8KnSK17jefSiLX7c1aoZxVSRL2JeOA1op06Utij3ZEYRj0n4K+jlQrGAh vP3/K5nYTNoXDEG44ykYAcK7GfWnTWNOcfqXU2CPlWeaWb7cwiWoS+55zKsTDTCC6wQQHt+ggle 0YWVJdVi+Uqro2NoRwbIGAwcXdxZxbtimgTERuZ0V0chlOkhgn2wXDKDDLo0YN1KEDjHUZLoUtT JmBnk9hh5YeQK/tDCmIHCfCu+Tm7d7tB4vbgKlONeCU4CNYCrvyEL8DAjo/i70Z5WhCXctpX8ek J5o41RrixE18N4trt9idH+a57JfWb6U4VGS84wMbaRpzrpOR9c97P3HKDZ9ysefMRznmjy1E93D a92Q03c7tuk2589y5byq4WQjN9Vmyy/Czsvqn8tHUK/rJEuHAPy+3tFSCUeL5KYQ4ABUZw9c3+w 38IQvxOk/4kOBuXQb3JyqSbCsvQFifiNN0= X-Received: by 2002:a05:620a:f0c:b0:915:a101:48d with SMTP id af79cd13be357-9160ad93320mr721143085a.56.1781213588300; Thu, 11 Jun 2026 14:33:08 -0700 (PDT) Received: from com-75606.node.ndb.openai.org ([209.249.37.146]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9161a006ef0sm26666385a.24.2026.06.11.14.33.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 11 Jun 2026 14:33:08 -0700 (PDT) From: Kyle Zeng To: ntfs3@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Konstantin Komarov , outbounddisclosures@openai.com, Kyle Zeng Subject: [PATCH] fs/ntfs3: validate dirty page table entry sizes Date: Thu, 11 Jun 2026 14:33:04 -0700 Message-ID: <20260611213304.16654-1-kylebot@openai.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The generic restart table check only verifies the table header and free-list shape. Dirty Page Table entries also carry an entry-local LCN array whose length is controlled by lcns_follow, and replay later trusts that value when converting version-0 entries and when copying LCNs from log records. A malformed $LogFile can provide a Dirty Page Table dump whose generic restart table is valid but whose entry is too small for the declared lcns_follow count. log_replay() can then run the version-0 conversion memmove() past the kmemdup() allocation, or later copy/read past dp->page_lcns when a log record spans beyond the matched DPT entry. Add Dirty Page Table-specific validation before copying the table: require entries to be large enough for the typed DPT layout, require the old version-0 source layout to fit before conversion, and require lcns_follow to fit within the restart table entry. Also validate each log record's LCN span against the matched DPT entry before touching dp->page_lcns. Assisted-by: Codex:gpt-5.5 Signed-off-by: Kyle Zeng --- fs/ntfs3/fslog.c | 61 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index acfa18b84401..1fc9d04806b5 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -647,6 +647,23 @@ static inline void *enum_rstbl(struct RESTART_TABLE *t, void *c) return NULL; } +static inline bool dptbl_lcns_in_range(const struct DIR_PAGE_ENTRY *dp, + u64 vcn, u16 lcns_follow) +{ + u64 dp_vcn = le64_to_cpu(dp->vcn); + u32 dp_lcns = le32_to_cpu(dp->lcns_follow); + u64 off; + + if (vcn < dp_vcn) + return false; + + off = vcn - dp_vcn; + if (off > dp_lcns) + return false; + + return lcns_follow <= dp_lcns - (u32)off; +} + /* * find_dp - Search for a @vcn in Dirty Page Table. */ @@ -657,12 +674,8 @@ static inline struct DIR_PAGE_ENTRY *find_dp(struct RESTART_TABLE *dptbl, struct DIR_PAGE_ENTRY *dp = NULL; while ((dp = enum_rstbl(dptbl, dp))) { - u64 dp_vcn = le64_to_cpu(dp->vcn); - - if (dp->target_attr == ta && vcn >= dp_vcn && - vcn < dp_vcn + le32_to_cpu(dp->lcns_follow)) { + if (dp->target_attr == ta && dptbl_lcns_in_range(dp, vcn, 1)) return dp; - } } return NULL; } @@ -778,6 +791,37 @@ static bool check_rstbl(const struct RESTART_TABLE *rt, size_t bytes) return true; } +static bool check_dptbl(const struct RESTART_TABLE *rt, bool is_restart_v0) +{ + u16 rsize = le16_to_cpu(rt->size); + struct DIR_PAGE_ENTRY *dp = NULL; + + if (rsize < sizeof(struct DIR_PAGE_ENTRY)) + return false; + + if (is_restart_v0 && rsize < sizeof(struct DIR_PAGE_ENTRY_32)) + return false; + + while ((dp = enum_rstbl((struct RESTART_TABLE *)rt, dp))) { + u32 lcns_follow = le32_to_cpu(dp->lcns_follow); + size_t bytes; + + bytes = struct_size(dp, page_lcns, lcns_follow); + if (bytes > rsize) + return false; + + if (!is_restart_v0) + continue; + + bytes = size_add(offsetof(struct DIR_PAGE_ENTRY_32, page_lcns_low), + array_size(lcns_follow, sizeof(u64))); + if (bytes > rsize) + return false; + } + + return true; +} + /* * free_rsttbl_idx - Free a previously allocated index a Restart Table. */ @@ -4204,7 +4248,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) t32 = rec_len - t16; /* Now check that this is a valid restart table. */ - if (!check_rstbl(rt, t32)) { + if (!check_rstbl(rt, t32) || !check_dptbl(rt, !rst->major_ver)) { err = -EINVAL; goto out; } @@ -4547,9 +4591,13 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) * whole routine a loop, case Lcns do not fit below. */ t16 = le16_to_cpu(lrh->lcns_follow); + if (!dptbl_lcns_in_range(dp, t64, t16)) { + 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)); + size_t j = (size_t)(t64 - le64_to_cpu(dp->vcn)); dp->page_lcns[j + i] = lrh->page_lcns[i]; } @@ -4928,6 +4976,12 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) if (!dp) goto read_next_log_do_action; + t16 = le16_to_cpu(lrh->lcns_follow); + if (!dptbl_lcns_in_range(dp, t64, t16)) { + err = -EINVAL; + goto out; + } + if (rec_lsn < le64_to_cpu(dp->oldest_lsn)) goto read_next_log_do_action; -- 2.43.0