From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 5527134A3C4; Sat, 30 May 2026 17:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780163103; cv=none; b=tcjJzJ7Nlxm9TwnXf+pWylZiCYVXnT8ZoT1JBHPzMs8hCsThBgOGjnuXgsm+ihHmQSW6/Q1LUvdbx76ipAaWEV97kmVA9gpJ0PxHKPlVMUv12VkQ5x+OcrcAeOZHV8O8xMhpsNxnP/RJCJmWbr7VkPLV0xH5m8Ar3kgF7P0wdvY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780163103; c=relaxed/simple; bh=/RsiHR5Rhrblr6hAwjPC6lUDmA/Ka4MXUn3XxN2/x4Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i2vb57KSBhUtGad+sx/6hF+Yweor0dN/JCH3Q3Il27mAoIINHXKp31Qx/Bv8TuUU9b2BgqwKlk81MoVJBfpjNA8Gmo7/wcQsdhR+Jl37W4yGfhnaDFcs99qN3v3fMpsSvl7CB/zewHb77XFBAZN5aOwKJiysxSgDrwyVqBzrwVI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=rM6lZxUq; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="rM6lZxUq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 964601F00893; Sat, 30 May 2026 17:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780163102; bh=td4RGocMSq+G9Wpn5tHJHLodlprZgsD2UHZbD8I4eu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rM6lZxUqmLKnvIyBkduZQCXSwPM7SjebJPLuxRIuAUMQChNug5FmFP+X2CCLqx8yQ D7Oh0p4WJTbIUxcgHccqxrq9IqI/njYC6Rrp2022wPeU+SetOTDTUHDotNHFdjEWwI FtOe0tc35L+iR0Qjzpg1rxmF6h5ngr3gW8D9NCS4= From: Greg Kroah-Hartman To: stable@vger.kernel.org, "stable@vger.kernel.org, Konstantin Komarov" Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Robert Garcia Subject: [PATCH 5.15 155/776] fs/ntfs3: Add more attributes checks in mi_enum_attr() Date: Sat, 30 May 2026 17:57:49 +0200 Message-ID: <20260530160244.472184780@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160240.228940103@linuxfoundation.org> References: <20260530160240.228940103@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Konstantin Komarov [ Upstream commit 013ff63b649475f0ee134e2c8d0c8e65284ede50 ] Signed-off-by: Konstantin Komarov [ Overflow check deleted to keep context consistent. ] Signed-off-by: Robert Garcia Signed-off-by: Greg Kroah-Hartman --- fs/ntfs3/record.c | 63 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 13 deletions(-) --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -193,8 +193,9 @@ struct ATTRIB *mi_enum_attr(struct mft_i { const struct MFT_REC *rec = mi->mrec; u32 used = le32_to_cpu(rec->used); - u32 t32, off, asize; + u32 t32, off, asize, prev_type; u16 t16; + u64 data_size, alloc_size, tot_size; if (!attr) { u32 total = le32_to_cpu(rec->total); @@ -213,6 +214,7 @@ struct ATTRIB *mi_enum_attr(struct mft_i if (!is_rec_inuse(rec)) return NULL; + prev_type = 0; attr = Add2Ptr(rec, off); } else { /* Check if input attr inside record. */ @@ -226,6 +228,7 @@ struct ATTRIB *mi_enum_attr(struct mft_i return NULL; } + prev_type = le32_to_cpu(attr->type); attr = Add2Ptr(attr, asize); off += asize; } @@ -245,7 +248,11 @@ struct ATTRIB *mi_enum_attr(struct mft_i /* 0x100 is last known attribute for now. */ t32 = le32_to_cpu(attr->type); - if ((t32 & 0xf) || (t32 > 0x100)) + if (!t32 || (t32 & 0xf) || (t32 > 0x100)) + return NULL; + + /* attributes in record must be ordered by type */ + if (t32 < prev_type) return NULL; /* Check overflow and boundary. */ @@ -254,16 +261,15 @@ struct ATTRIB *mi_enum_attr(struct mft_i /* Check size of attribute. */ if (!attr->non_res) { + /* Check resident fields. */ if (asize < SIZEOF_RESIDENT) return NULL; t16 = le16_to_cpu(attr->res.data_off); - if (t16 > asize) return NULL; - t32 = le32_to_cpu(attr->res.data_size); - if (t16 + t32 > asize) + if (t16 + le32_to_cpu(attr->res.data_size) > asize) return NULL; if (attr->name_len && @@ -274,21 +280,52 @@ struct ATTRIB *mi_enum_attr(struct mft_i return attr; } - /* Check some nonresident fields. */ - if (attr->name_len && - le16_to_cpu(attr->name_off) + sizeof(short) * attr->name_len > - le16_to_cpu(attr->nres.run_off)) { + /* Check nonresident fields. */ + if (attr->non_res != 1) + return NULL; + + t16 = le16_to_cpu(attr->nres.run_off); + if (t16 > asize) + return NULL; + + t32 = sizeof(short) * attr->name_len; + if (t32 && le16_to_cpu(attr->name_off) + t32 > t16) + return NULL; + + /* Check start/end vcn. */ + if (le64_to_cpu(attr->nres.svcn) > le64_to_cpu(attr->nres.evcn) + 1) + return NULL; + + data_size = le64_to_cpu(attr->nres.data_size); + if (le64_to_cpu(attr->nres.valid_size) > data_size) return NULL; - } - if (attr->nres.svcn || !is_attr_ext(attr)) { + alloc_size = le64_to_cpu(attr->nres.alloc_size); + if (data_size > alloc_size) + return NULL; + + t32 = mi->sbi->cluster_mask; + if (alloc_size & t32) + return NULL; + + if (!attr->nres.svcn && is_attr_ext(attr)) { + /* First segment of sparse/compressed attribute */ + if (asize + 8 < SIZEOF_NONRESIDENT_EX) + return NULL; + + tot_size = le64_to_cpu(attr->nres.total_size); + if (tot_size & t32) + return NULL; + + if (tot_size > alloc_size) + return NULL; + } else { if (asize + 8 < SIZEOF_NONRESIDENT) return NULL; if (attr->nres.c_unit) return NULL; - } else if (asize + 8 < SIZEOF_NONRESIDENT_EX) - return NULL; + } return attr; }