From nobody Mon Jun 8 19:49:21 2026 Received: from n169-112.mail.139.com (n169-112.mail.139.com [120.232.169.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98D8829AAF3; Wed, 27 May 2026 00:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=120.232.169.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779843367; cv=none; b=SZh//aiC1+tT5JOSz9EYOVst4KMmDeSnpVNHwTZBdKZaYKk7epexLQlP85E1jXF3HctlsuRQhn9SU9VoC5a08bI0lbUkhSyyVh4nK0CtrNnhhppVgkUzZVhnIEjczju342ZDBIX05xpIbQEodyhXWVeH0crdggMfCFOC9qswqTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779843367; c=relaxed/simple; bh=YsNiUFhM7ZNl5fxuDEq/DsxQwWAvPPpU0XM+7Vh8HeE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RLnVjypPWdtGxTDlALsks2BVl0zSzSthrqN3X6Q6jwmtUcq9jzMG8LUA8hsFJTq8bcoUovC5tl/BIIl/LdGYe6hEYTsKLtBVH5wSUq8B9EnRpGPtlNmcU5dsIz2oYWbqtreJ/my4KkOMPokYozwcJyz7NuVnIbO7VC6x7Fzg9Nw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com; spf=pass smtp.mailfrom=139.com; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b=u7HTWalx; arc=none smtp.client-ip=120.232.169.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=139.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b="u7HTWalx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=139.com; s=dkim; l=0; h=from:subject:message-id:to:cc:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=u7HTWalxfLlSLzMvvz4JkBA+4Ys1XNlFCnOUt8vBjwadeh8T2ut+aUn2LbKXhSXWS7ZGIdAI8RtSV HXWb75UKKb2qu88LMEsS5s7L3Q6GR8xTiqoUG/qjfmJi3HNsZUwASNIZvKoC63pkaIEksuU5G66SUt i751LEhKDrrzGSEE= X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG: 00000000 Received: from NTT-kernel-dev (unknown[60.247.85.88]) by rmsmtp-lg-appmail-24-12027 (RichMail) with SMTP id 2efb6a1641210f5-000f7; Wed, 27 May 2026 08:56:03 +0800 (CST) X-RM-TRANSID: 2efb6a1641210f5-000f7 From: Li hongliang <1468888505@139.com> To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: patches@lists.linux.dev, linux-kernel@vger.kernel.org, almaz.alexandrovich@paragon-software.com, ntfs3@lists.linux.dev Subject: [PATCH 5.15.y] fs/ntfs3: validate rec->used in journal-replay file record check Date: Wed, 27 May 2026 08:56:02 +0800 Message-Id: <20260527005602.3175920-1-1468888505@139.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Greg Kroah-Hartman [ Upstream commit 0ca0485e4b2e837ebb6cbd4f2451aba665a03e4b ] check_file_record() validates rec->total against the record size but never validates rec->used. The do_action() journal-replay handlers read rec->used from disk and use it to compute memmove lengths: DeleteAttribute: memmove(attr, ..., used - asize - roff) CreateAttribute: memmove(..., attr, used - roff) change_attr_size: memmove(..., used - PtrOffset(rec, next)) When rec->used is smaller than the offset of a validated attribute, or larger than the record size, these subtractions can underflow allowing us to copy huge amounts of memory in to a 4kb buffer, generally considered a bad idea overall. This requires a corrupted filesystem, which isn't a threat model the kernel really needs to worry about, but checking for such an obvious out-of-bounds value is good to keep things robust, especially on journal replay Fix this up by bounding rec->used correctly. This is much like commit b2bc7c44ed17 ("fs/ntfs3: Fix slab-out-of-bounds read in DeleteIndexEntryRoot") which checked different values in this same switch statement. Cc: Konstantin Komarov Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal") Cc: stable Assisted-by: gregkh_clanker_t1000 Signed-off-by: Greg Kroah-Hartman Signed-off-by: Konstantin Komarov Signed-off-by: Li hongliang <1468888505@139.com> --- fs/ntfs3/fslog.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index d3d006b63b27..9b12d5a7ac8d 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -2792,13 +2792,14 @@ static inline bool check_file_record(const struct M= FT_REC *rec, u16 fn =3D le16_to_cpu(rec->rhdr.fix_num); u16 ao =3D le16_to_cpu(rec->attr_off); u32 rs =3D sbi->record_size; + u32 used =3D le32_to_cpu(rec->used); =20 /* Check the file record header for consistency. */ if (rec->rhdr.sign !=3D NTFS_FILE_SIGNATURE || fo > (SECTOR_SIZE - ((rs >> SECTOR_SHIFT) + 1) * sizeof(short)) || (fn - 1) * SECTOR_SIZE !=3D rs || ao < MFTRECORD_FIXUP_OFFSET_1 || ao > sbi->record_size - SIZEOF_RESIDENT || !is_rec_inuse(rec) || - le32_to_cpu(rec->total) !=3D rs) { + le32_to_cpu(rec->total) !=3D rs || used > rs || used < ao) { return false; } =20 @@ -2810,6 +2811,15 @@ static inline bool check_file_record(const struct MF= T_REC *rec, return false; } =20 + /* + * The do_action() handlers compute memmove lengths as + * "rec->used - ", which underflows when + * rec->used is smaller than the attribute walk reached. At this + * point attr is the ATTR_END marker; rec->used must cover it. + */ + if (used < PtrOffset(rec, attr) + sizeof(attr->type)) + return false; + return true; } =20 --=20 2.34.1