From nobody Tue Sep 16 20:04:38 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B7F8C4167B for ; Fri, 30 Dec 2022 11:26:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234855AbiL3L0Z (ORCPT ); Fri, 30 Dec 2022 06:26:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234788AbiL3L0X (ORCPT ); Fri, 30 Dec 2022 06:26:23 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 655D7140C0; Fri, 30 Dec 2022 03:26:22 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id D9A0A20EE; Fri, 30 Dec 2022 11:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1672399367; bh=cx5DEN5yzbTg0lbldjz4Ma6Es6+57SY1O3L9oJVV9ds=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=rOEzMTST7ax17Nj+YLDvGarYh5kQ4KDBZeIOEVQIFf9UdpJRgksIAO8OzHWe07Y8g NK9ZUKG7fjgENsYOtlTdC1K3nh19owa7PFtoNKc4hD34JSAhzEsDbvu1hJa0OAv6dX +ZqmdLtXwNJcFp5/AxN6k/uEs5yqWbUzbyL4n7Gs= Received: from [192.168.211.146] (192.168.211.146) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 30 Dec 2022 14:26:19 +0300 Message-ID: Date: Fri, 30 Dec 2022 15:26:18 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: [PATCH 4/5] fs/ntfs3: Restore overflow checking for attr size in mi_enum_attr Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.146] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixed comment. Removed explicit initialization for INDEX_ROOT. Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/index.c=C2=A0 | 7 ++++--- =C2=A0fs/ntfs3/record.c | 5 +++++ =C2=A0fs/ntfs3/super.c=C2=A0 | 2 +- =C2=A03 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 8718df791a55..9fefeac5fe7e 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -994,7 +994,7 @@ struct INDEX_ROOT *indx_get_root(struct ntfs_index=20 *indx, struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 struct ATTR_LIST_ENTRY *le =3D NULL; =C2=A0=C2=A0=C2=A0=C2=A0 struct ATTRIB *a; =C2=A0=C2=A0=C2=A0=C2=A0 const struct INDEX_NAMES *in =3D &s_index_names[i= ndx->type]; -=C2=A0=C2=A0=C2=A0 struct INDEX_ROOT *root =3D NULL; +=C2=A0=C2=A0=C2=A0 struct INDEX_ROOT *root; =C2=A0=C2=A0=C2=A0=C2=A0 a =3D ni_find_attr(ni, NULL, &le, ATTR_ROOT, in->= name, in->name_len,=20 NULL, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0mi); @@ -1007,8 +1007,9 @@ struct INDEX_ROOT *indx_get_root(struct ntfs_index=20 *indx, struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 root =3D resident_data_ex(a, sizeof(struct INDEX_= ROOT)); =C2=A0=C2=A0=C2=A0=C2=A0 /* length check */ -=C2=A0=C2=A0=C2=A0 if (root && offsetof(struct INDEX_ROOT, ihdr) +=20 le32_to_cpu(root->ihdr.used) > -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 le32_to_cpu(a->re= s.data_size)) { +=C2=A0=C2=A0=C2=A0 if (root && +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 offsetof(struct INDEX_ROOT, ihdr) + = le32_to_cpu(root->ihdr.used) > +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 le32_to_cpu(a->re= s.data_size)) { =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return NULL; =C2=A0=C2=A0=C2=A0=C2=A0 } diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index abfe004774c0..0603169ee8a0 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -220,6 +220,11 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi,=20 struct ATTRIB *attr) =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return NULL; =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 } +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (off + asize < off) { +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 /* Overflow check= . */ +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return NULL; +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 } + =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 attr =3D Add2Ptr(attr, asize); =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 off +=3D asize; =C2=A0=C2=A0=C2=A0=C2=A0 } diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 0967035146ce..19d0889b131f 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1187,7 +1187,7 @@ static int ntfs_fill_super(struct super_block *sb,=20 struct fs_context *fc) =C2=A0=C2=A0=C2=A0=C2=A0 /* =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0* Typical $AttrDef contains up to 20 entrie= s. -=C2=A0=C2=A0=C2=A0 =C2=A0* Check for extremely large size. +=C2=A0=C2=A0=C2=A0 =C2=A0* Check for extremely large/small size. =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0*/ =C2=A0=C2=A0=C2=A0=C2=A0 if (inode->i_size < sizeof(struct ATTR_DEF_ENTRY)= || =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 inode->i_size > 100 * sizeof(s= truct ATTR_DEF_ENTRY)) { --=20 2.34.1