Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 3A5103D093C for ; Wed, 17 Jun 2026 23:13:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781738032; cv=none; b=rnX1GGZoRVpmo+Tr633colIDRiC7cJQdnga/QGyYSglfm+a9U8QLM1hyAxo++U7mRV2DaA5NpEoop3zmV/EnG8xYmXy2JIrCq0+AykAB3otu5A1S+wST3m/I7XR6czTzALbeOxoXP5KaZwYdu0oD+tOdGF05NKlQ+lS0o3K8cGI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781738032; c=relaxed/simple; bh=yRpTV2fREwzzqOKDQ1mQKF+YgHG+RYpUg5V3/o+sfI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nlQaoBIFj9lDP1Yrxcy/ACikn2Ey7PKF/KOmC/KNaMpRALYV5OfA0lVLx5ubxmsBK9pT1VyWWgdQ7PSXfmngv9b9nKl6cQAzykbsddKMdZsHImwYEn1VKnN6h8nS4G7TGzEhlaYqHQRygiyBpal3fHeg88ehNX04nfoglnXFw9M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu; spf=pass smtp.mailfrom=asu.edu; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b=TFKrChDM; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b="TFKrChDM" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-84229481d44so89945b3a.0 for ; Wed, 17 Jun 2026 16:13:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1781738031; x=1782342831; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t1WZSdnDOexkXvu4kbAp0KpA84CDGtsQuc6Gr9g6y/4=; b=TFKrChDMnKdCcwz0uXwxKbJ6fxc9l2rBd8rE+WRt3f/JfCoMpjetIblwa+zULCirE4 XoGdg2i5TgkhFpAvItbydLX8Jowckycw9Q0rJOHJ9UQdENhCfvU109D4k4MyNYnoBQrV j4+wzaigeLmCrx4vKM7jcSYyKgyNpAaB0xdBLRywT280hE+KEGHL4IL8yygY+/Kj7npL e4Nmm4EMkqlxyxqhtHGHz9CLKlowQo1nT7EiFgn8u6KUmWpveaKUhkceZxnyFAqa5bWw OkCv2VDHM9dktv+3UA47edRnzt7fUZBF0tbmXsmOjQFq/3BIh12nrcYtOUhsVaWjj4V3 wkGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781738031; x=1782342831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=t1WZSdnDOexkXvu4kbAp0KpA84CDGtsQuc6Gr9g6y/4=; b=Cz7IlZ1whLy0UJREdg3suj7ihrCchBlPODZdBFh6Xd12cQkLqN9wHbVmz/si0TMZa6 oWCVwpjILKfKyiuSVYT+gNnsP7ynf44T3yUlQzHmb/E/+ROEB3rRMBfGNIqRWSiPN/QB 4wVYuzJotTrLBJspzzPHb9hNtnOcsX3kUEjuWe1mdB6t6jMCiYsG1G17nD0gHJ+IOW0J sxYXJJL5avCSZhNSnFBMlXmJmdFvBhocmUaHZYBUlIcIrXT7o8+iLqf2Q7k4MzYBb+Ch 5W5T7HYlbdvg3lktvK+pLju8vkaIO/Sxo+0aEQzyDXWKC/DXGSMzEB5S/A50euWXH7G9 gKHA== X-Forwarded-Encrypted: i=1; AFNElJ+AXwyRVFZ9dfnnQea2PIptPpBTohkUJjFjneVVpBUrpjep43ZjVo1rGeAgIj6yz/LL16bFJK908G8z4Aw=@vger.kernel.org X-Gm-Message-State: AOJu0YwsAV6aMDw1GvyUioiez+++i+M9EDK/EHa/fwpiWxHBDgN9MTNM Wdb5orJFKWEZe1nEtqEFUqC9nXj+EkUd/Z7aj3CqX+SdfC21dAgPeC2EyoRMIUnIrA== X-Gm-Gg: AfdE7cmja/hd7G3VS1GxtwQ98T4pITFpMoRdKy35fJ6tLXgbBS7rKNSD817ezdCDTzl ZSzgcR6jUL2OO6HlLORK1ap5CtSklf/6AarmXxbar79UU+f7f00RFvzmAjlsBcKv3lj0/eHnOei mUSVGSxB7qdAS/Bx/szNd098M+zdqUSmccgafq/V8VxON7nepRFI3boInowMi959C0WJJES3XvE X66kWxEIT9K+GmtmKdCrruevtGQyr4pUHBVx/KV9JKc4vrT2bSAYMMIFEAoZvqDQz7MCQhLKKp2 shCql3+WjsgdKiF3lZ9TA+8DPT7VDFBixmY78lBJw0CsNpHDywHGNFRJlVk4U1pWc8XvhXLLE6/ HiWOM1URN6/F1tnblnlOBoKCrGADXCoLI+VuzvHHGGdEoiCbvksIoju3k5g8OPSyVmkEJeXZiaA == X-Received: by 2002:a05:6a00:238c:b0:842:5712:c2c2 with SMTP id d2e1a72fcca58-8453b3a63cemr907532b3a.41.1781738030668; Wed, 17 Jun 2026 16:13:50 -0700 (PDT) Received: from p1.. ([2607:fb90:ec29:4018:2b5d:3e92:f9ad:889c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8434acf4b5csm21073427b3a.23.2026.06.17.16.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 16:13:50 -0700 (PDT) From: Xiang Mei To: Konstantin Komarov Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org, Weiming Shi , Xiang Mei , stable@vger.kernel.org Subject: [PATCH v2 1/2] fs/ntfs3: validate dirty page table on log replay Date: Wed, 17 Jun 2026 16:13:42 -0700 Message-ID: <20260617231343.403432-2-xmei5@asu.edu> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260617231343.403432-1-xmei5@asu.edu> References: <20260617231343.403432-1-xmei5@asu.edu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Each DIR_PAGE_ENTRY ends in a page_lcns[] array whose length is the on-disk lcns_follow field. check_rstbl() validates the table bookkeeping but never checks that this array fits in the entry, so a crafted lcns_follow lets the v0->v1 conversion memmove and later replay passes run off the entry. Add check_dp_table() to reject, right after check_rstbl(), any entry larger than its size claims via struct_size() (the same expression used to allocate these entries, so the check is overflow-safe by construction). All consumers can then trust lcns_follow as the real capacity. This covers every page_lcns[] access whose index is bounded by the entry itself (the conversion memmove, the HotFix store via find_dp(), and the self-bounded scan loops). Accesses whose index comes from the log record need a separate bound and are handled in a follow-up patch. Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") Cc: stable@vger.kernel.org Reported-by: Weiming Shi Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Xiang Mei --- v2: resend to public mailing list fs/ntfs3/fslog.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index acfa18b84401..b1ca84d83de5 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -778,6 +778,20 @@ static bool check_rstbl(const struct RESTART_TABLE *rt, size_t bytes) return true; } +static bool check_dp_table(const struct RESTART_TABLE *dptbl) +{ + u32 rsize = le16_to_cpu(dptbl->size); + struct DIR_PAGE_ENTRY *dp = NULL; + + while ((dp = enum_rstbl((struct RESTART_TABLE *)dptbl, dp))) { + if (struct_size(dp, page_lcns, le32_to_cpu(dp->lcns_follow)) > + rsize) + return false; + } + + return true; +} + /* * free_rsttbl_idx - Free a previously allocated index a Restart Table. */ @@ -4209,6 +4223,11 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) goto out; } + if (!check_dp_table(rt)) { + err = -EINVAL; + goto out; + } + dptbl = kmemdup(rt, t32, GFP_NOFS); if (!dptbl) { err = -ENOMEM; -- 2.43.0