Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 61F3C3CF960 for ; Wed, 17 Jun 2026 23:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781738035; cv=none; b=UpSH477V5JHiOzMTLFaJzVMo2aDc4cSA4E7NeiG4ZdAFOpsIU9MAp8wgYZrg3sGLTiBc3W9c2tx1wS7Ft/1rJG3wEoev2gpHfEgYBdNDDws5CC+1V7K/fjnADXZAYpXczJ6rhc+P4/OVVjhfL40C9cX15bXMdFzdJceRPOKBUhY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781738035; c=relaxed/simple; bh=Kj0TBfxEicM57cvRUBFcrL1W+6OHe2oDpqZXrRZ/o3c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ARlsyTO/fcTO1M5kS4e/EJ4gvLOglkeG+5ubBeaP/hMoUnHCsTyaLOgKn5SHE/9QqIGAE/C8leg8hFgnJNYoeOq9CJ6HFYk5jnKbjmylBWHbasDUNboGGhbBnUuT5ESZelXxQwXxhk69OEeHWw2apJHKW7/SqQQy9pvErzxgT04= 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=RMbgMf2p; arc=none smtp.client-ip=209.85.210.182 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="RMbgMf2p" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-842338c18e0so157936b3a.1 for ; Wed, 17 Jun 2026 16:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1781738033; x=1782342833; 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=4jtRzExnB/EeGtbnZ2qJXWTojvkZFyWJwa+IXv5Dkx4=; b=RMbgMf2pb8qQ3AVVp/dIoTVBJlqskOGXQuiL2SOZcSU5DOo1Fjq0BBX+BGP2WcSe3m o/4cjTuAkdvlNnM5PHS4yuIdkE/z7uTTP40ckH7b81RZd+QYLJOuZ3Vz/to8BNwtvWV4 bX0DJIPbjVYMMgNTjAUTO/scXUy76kz7XjzDxEVFtbpAYn6kSJT267quEm/peZ9dl1vy QU55b+28b6PCNm1Hx0lCeDd+i/VsNgHoH5QCheNpbwDAYpT4ApTnAUHoNB8FKxfaV8rj YCvDtiiDa0xGzWAWdBEXC8EfRZA9O25bmyrjwOpcAJCDtFbms9VGwZsfT9g96jb07K8m kRgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781738033; x=1782342833; 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=4jtRzExnB/EeGtbnZ2qJXWTojvkZFyWJwa+IXv5Dkx4=; b=OM4fsZwt+jSTHevs3RhKv5VvlNN7S6C9g63c16rpIXCfwzrQ/mVJ8NWxlkpjfxVGtN yOgB4pTEpkEDTmS7sSZ/jtgR2CubYQJtdOBjpcnSvJM5wNWTM+kGpyQlGe9/WTIiYgri vf/2yW/A+2z6pvJWyhHGijExGXYk4ypTHaaCYeloyVgLjZ8koORwnEdDqXfMZEfBWWWz dqgMION1tSXpvuuNB9t4qZil5mWY9f6+COvmed0JIHA79ncFMk79h/yjxtATMUtrmL1R ZTqWrLiyyhVKyTIaO2ujeFHLsqeqV/k56zSjT1RYXzyUZls+O7e30rIxfahvQQgcdFmZ iw6Q== X-Forwarded-Encrypted: i=1; AFNElJ/bpF1FZ9IRGYwU+U0wclLq1Zzm3UygMZCJ1dkUa/C54+vmi5IwFOVARxvSpvJTUEKiN+8DxeZoWS9O2Os=@vger.kernel.org X-Gm-Message-State: AOJu0Yx17iIRlEQV7phunHx9U5g7R1lQc1se/iKCg0JunIJCrMBFxoRi NU0rMEOx2MsXQdLNC5+xZPAjOM6u5+cKxOc0uTra73OvmCKYaQnpHHlOdv+/LQJgBA== X-Gm-Gg: AfdE7cl3lnsEUKl1qg3GxpG11znlhyabDNW4zpZy5nVPfsuXsZF/IKKgd3fCQ63PNFh y35mCZAr0D7D7dpAXk2GtnDUZZhIzQDrxow7EalzY2xUJq/pynweax5MxaUatUdvRQu/OiNvuIC xuJzzeahRKFBfgHgcOXa2mm5w8BtsnK3C6EjXMasHAl4KKeou5bF38FvCNrWEcnEwS6FTTKJ52m jaJ7vbRliAVKkZn+5sSKFg8Xo92MUPjBdc2jEQ2CBvjfiFgHbmkj4j4ZgovzwtHjtJbtx99PVtl ERSsePs3F93x/DEEuUeFFJYQvV/CRswUqJ3yo+hgWO/XmvVagJqDXwKprakLIdA8RUr3QQoeXPD PZcHclRHJrVI/FhQL/uODTfrqsuR4BTiAUXVpPGcWCsJsO8GTZ0uvPA8w5KuP09CVAWI8ClCNhw == X-Received: by 2002:a05:6a00:1709:b0:842:377a:4dcd with SMTP id d2e1a72fcca58-8453b27ecd1mr853640b3a.43.1781738032748; Wed, 17 Jun 2026 16:13:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 16:13:52 -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 2/2] fs/ntfs3: bound page_lcns[] index by the log record Date: Wed, 17 Jun 2026 16:13:43 -0700 Message-ID: <20260617231343.403432-3-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 The copy_lcns loop and the redo shorten loop index page_lcns[] at j + i, where i runs up to the log record's lcns_follow. That count is checked only against the record's own length, not the target entry, so check_dp_table() (which validates the entry's lcns_follow) does not cover it: the copy_lcns entry may even be freshly allocated after that check, and find_dp() bounds j but not i. A crafted record thus overflows page_lcns[] of an otherwise valid entry. Add dp_range_ok() and reject, before each loop, any record whose run does not fit the entry. These are the only two page_lcns[] accesses indexed by the record rather than the entry, so together with the entry validation every access is now bounded. 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 | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index b1ca84d83de5..1cc7402fdc2c 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -647,6 +647,14 @@ static inline void *enum_rstbl(struct RESTART_TABLE *t, void *c) return NULL; } +/* + * dp_range_ok - true if [j, j + count) fits in a page_lcns[cap] array. + */ +static inline bool dp_range_ok(size_t j, u32 count, u32 cap) +{ + return j < cap && count <= cap - j; +} + /* * find_dp - Search for a @vcn in Dirty Page Table. */ @@ -3801,6 +3809,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) u64 t64; u16 t16; u32 t32; + size_t j; log = kzalloc_obj(struct ntfs_log, GFP_NOFS); if (!log) @@ -4566,9 +4575,12 @@ 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); + j = le64_to_cpu(lrh->target_vcn) - le64_to_cpu(dp->vcn); + if (!dp_range_ok(j, t16, le32_to_cpu(dp->lcns_follow))) { + 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)); dp->page_lcns[j + i] = lrh->page_lcns[i]; } @@ -4985,8 +4997,14 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) /* Shorten length by any Lcns which were deleted. */ saved_len = dlen; + j = le64_to_cpu(lrh->target_vcn) - le64_to_cpu(dp->vcn); + if (!dp_range_ok(j, le16_to_cpu(lrh->lcns_follow), + le32_to_cpu(dp->lcns_follow))) { + err = -EINVAL; + goto out; + } + for (i = le16_to_cpu(lrh->lcns_follow); i; i--) { - size_t j; u32 alen, voff; voff = le16_to_cpu(lrh->record_off) + @@ -4994,7 +5012,6 @@ int log_replay(struct ntfs_inode *ni, bool *initialized) voff += le16_to_cpu(lrh->cluster_off) << SECTOR_SHIFT; /* If the Vcn question is allocated, we can just get out. */ - j = le64_to_cpu(lrh->target_vcn) - le64_to_cpu(dp->vcn); if (dp->page_lcns[j + i - 1]) break; -- 2.43.0