From nobody Fri Jun 12 12:46:29 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 626893FADF8 for ; Fri, 15 May 2026 08:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778833394; cv=none; b=YPBORppBU6GEJJJd8kMUjF8Qudusxst6ew1sDMIOURPFadeSUFb5r+FQ9mmj/csVyj7/6cTOx5NYHAVAUwgu0l99OeoJ0z4qLZWHCzR7Jx//YRSyDGw+3iCmS42hEy2w98CjcOYMyPodPkci6GYXsb9Y5nXDNKDWXx+3pTv1SaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778833394; c=relaxed/simple; bh=kf0TrrJpgVAYeBXNpY6fNQGA/hm8ajYhClup86nat0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KiaLlQTonK4F2oWtRxh2odpDRyy0kMxgn34trEbiCgnZYu/CuWBBm4cE5B7dG0Ci/MdfKBePG9sZ86S1OgIFVjFbN0vXx3I2hiuog6jcprMkeXtM88x6Sow2/MjSfhHV0Gucbk7k68sx2O9fFzasCa+8cYa2Yl+i8vnGhTq0pHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HET2oxw3; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HET2oxw3" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-835386ff122so8552096b3a.3 for ; Fri, 15 May 2026 01:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778833392; x=1779438192; 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=DDJhfoHAUgZQanl3xvd/N6+ekkXj0jZn5bqMRuYYEWM=; b=HET2oxw3nF7Zkp+nbYF/m91tvRzQlMaBd8GvzRyXwSbPqJewUkSNP2ESEOEJITvxKT Teb6W6Ca+9eyHf9oawY/uNtZtNImiJKax6r6zP+eYTLTDJKuBwbq6z6P51ZaTPpYI3Mp AvdjFxD66lJrGMBPnnR8M4DZt5NkzobMn0h0/qknGeh17R+rsowm3WDQTm5fX2Q3HMvG bCkHP69qxCHcgqnZ5fLVxnZn3a7BDzJu6WrTvd0iOrE4PpmwS+njoFQN8WEtR5KsGMWf Nn0rYmPK6dWDkjbIkV132AL05s0UxQkX9K7fCPTJuRZ0AcrEQ5RkaMNmBB3N2vUjCRN9 knDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778833392; x=1779438192; 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=DDJhfoHAUgZQanl3xvd/N6+ekkXj0jZn5bqMRuYYEWM=; b=XFJaFjQNV2IovnKC7/3YPFN3MvrlJNUOP4tguUBuFzNSdBgJo93SWMxJQWNc0JjKnj RMbZkfuOENwWGGGtPRK1/k32tp+Q7uoMJB6qO71u/bq64h7nufGuDMotxV7to4Wa+Tkw hx1KvrN8co5KbZEFkOeMuprGEXt9kWBkjAWgYPBPqNUILpxO5qu5PWmWpybmJ5vNiyWe 1OOVDmkN9e3cKFk3nQ5+xYpwe6mFPL/DNhXxw6eFgp4BwZMEwg7mW3fBx1+8uBVPIsZJ crAhTop0B6YcVVmCyTvZwf2lfnDNHnMQ1+eQ1Kg4lPLdkpPTjbfwTg3KVC6lIQ2xCmNf CDoA== X-Forwarded-Encrypted: i=1; AFNElJ/MY1BIEiPy/V9eNaOv8ioRCLMQAiwuCW/20/SLvTr1FvAdwsxgJTa5sK0nT9B0cMEeDOAgzicY25k15II=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7D/SGXSlXTFZ648V/n7LLDo6FUtCnO5jGbZP5vtAwZaL876hZ aJEYybvuvhB82aJYh8X8C5w9ICBOtxVQ3zGmT3QBhtj2Mc80oSxbRsB9 X-Gm-Gg: Acq92OEl1DS1dTopXzWnB0/KBehimg8pn+q/00fXZ0AclwgG9XUkM4aAz7H6IbqkQCa /dkws/ybxyPHbzbf5OFMsKzBc2562s7avqm1+R+pm9jhATjoxoAvMkc0ZpqFGUnFp6CiezXcVTK EPnzAakRhaSPv30KvKFTQS1OH1Mc3s4cdQwxe3RMbLR3ukJ7Ok36t7olHF7G3MWFA0/StrA2Jvg cQZ2qSZmPvOLJwux38fZMRijHOSFDhOLgg5/htVeQsX4nd8m84+1zz+d6mDcWT6bcgDBbAbC76q Hr/k+cexBtW5wPm+EmffPknTN38ZLbOLbP1Rebu2WUQxLMV4TaLBjNPlb/NlQhMQj6iDjcy95Uz JOScRNWsfZktOnMYm9IkNwp4+Wz9j3ugT+d21LYoCcFsQYV2Sn/6W5ih73aU3z/FsmZkpNB18XA e4HmKkSv65SaSQYd20o8p1/KVA5//ko1NIZxIRGA== X-Received: by 2002:a05:6a00:a22a:b0:82a:65fa:cecf with SMTP id d2e1a72fcca58-83f33aebd61mr3456119b3a.4.1778833392367; Fri, 15 May 2026 01:23:12 -0700 (PDT) Received: from DESKTOP-MOQC9AF.mioffice.cn ([43.224.245.246]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-83f19775c97sm5318589b3a.15.2026.05.15.01.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2026 01:23:11 -0700 (PDT) From: fra-build X-Google-Original-From: fra-build To: almaz.alexandrovich@paragon-software.com, david.laight.linux@gmail.com Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com Subject: [PATCH v4] fs/ntfs3: reject out-of-range evcn in mi_enum_attr() Date: Fri, 15 May 2026 16:23:05 +0800 Message-ID: <20260515082305.54624-1-fra@build.local> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427035025.38158-1-zhanxusheng@xiaomi.com> References: <20260427035025.38158-1-zhanxusheng@xiaomi.com> 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: Zhan Xusheng In mi_enum_attr(), the start/end VCN validation for non-resident attributes is: if (svcn > evcn + 1) goto out; When evcn is U64_MAX the "evcn + 1" expression wraps to 0 and any svcn passes the check. For evcn values close to U64_MAX (but not equal to it) the right-hand side is still a meaningless near-wrap upper bound, so a malformed on-disk attribute with svcn =3D=3D 0 and evcn near U64_MAX can pass mi_enum_attr() unrejected. VCN (virtual cluster number) is a cluster index, so any valid evcn is bounded by the volume's total cluster count, which ntfs3 holds in sbi->used.bitmap.nbits (set up in ntfs_init_from_boot() before any caller of mi_enum_attr() runs). Reject evcn values that fall outside this range; this rejects all out-of-range evcn values, not just U64_MAX, and as a side effect prevents the "evcn + 1" wraparound entirely. Fixes: 013ff63b6494 ("fs/ntfs3: Add more attributes checks in mi_enum_attr(= )") Signed-off-by: Zhan Xusheng Reviewed-by: David Laight --- fs/ntfs3/record.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index 32bdb034c2a3..4379446bcf96 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -202,7 +202,7 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, stru= ct mft_inode *mi, u32 used =3D le32_to_cpu(rec->used); u32 t32, off, asize, prev_type; u16 t16; - u64 data_size, alloc_size, tot_size; + u64 svcn, evcn, data_size, alloc_size, tot_size; =20 if (!attr) { u32 total =3D le32_to_cpu(rec->total); @@ -310,8 +310,17 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, str= uct mft_inode *mi, if (t32 && le16_to_cpu(attr->name_off) + t32 > t16) goto out; =20 - /* Check start/end vcn. */ - if (le64_to_cpu(attr->nres.svcn) > le64_to_cpu(attr->nres.evcn) + 1) + /* + * Check start/end vcn. evcn must be a valid cluster index, i.e. + * less than the volume's total cluster count (sbi->used.bitmap.nbits); + * rejecting it here also keeps "svcn > evcn + 1" meaningful, since + * evcn =3D=3D U64_MAX would wrap "evcn + 1" to 0. svcn does not need + * its own bound: once evcn < nbits, "svcn > evcn + 1" implies + * svcn <=3D nbits. + */ + svcn =3D le64_to_cpu(attr->nres.svcn); + evcn =3D le64_to_cpu(attr->nres.evcn); + if (evcn >=3D mi->sbi->used.bitmap.nbits || svcn > evcn + 1) goto out; =20 data_size =3D le64_to_cpu(attr->nres.data_size); --=20 2.43.0