From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99137+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99137+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811791; cv=none; d=zohomail.com; s=zohoarc; b=LaqLXaQEevLwP24TIh06+j+RR5md4nuE4M7u09Y2ubUEdPCpz1I3zhfPsz7Kklxwp4NdCp4LK2YFPD+HJB1yPf5an2NzCHF7fAHJ52VSf/VmwhqbdcUV4udYQdwjfsAzB0avK1gr7CCeFY8dz+Moe4iWTq4UCXD16Hqv8oRbzwI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811791; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=T1ngt6lb3yCVCgHf8GxU5B6S5Kbve0NoACtNeKqe7bY=; b=WhDAcuh2IcZBnwFyRt7rnNHpkGUW29Ag+eLhPc6m6/pL3UgYI2IYplD+RINRI5/9lIUy7HwcmTzm4PTziaS8p7dwcGMMb61arPFM2zPpZhbEq7m1OII3j0XdugBATOyH7z+SSc3D/hx6qw+x8kiZINPCCheLVWzUw/2w8NtNVfo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99137+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811791308119.37852652183028; Fri, 27 Jan 2023 01:29:51 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id WPQvYY1788612xoTzZLlIGSB; Fri, 27 Jan 2023 01:29:51 -0800 X-Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by mx.groups.io with SMTP id smtpd.web10.98477.1674811790268316894 for ; Fri, 27 Jan 2023 01:29:50 -0800 X-Received: by mail-lf1-f54.google.com with SMTP id x40so7177168lfu.12 for ; Fri, 27 Jan 2023 01:29:50 -0800 (PST) X-Gm-Message-State: ID5w7h0t0UqrKiFpbuNAHkttx1787277AA= X-Google-Smtp-Source: AMrXdXtI1QQF3rMri9EdRtCQGOfi7yKvQVLMHdG1o7LxGrcAFSEUnMhGZ6DBA5M8I3FbsgNfVHePng== X-Received: by 2002:ac2:4a7a:0:b0:4cb:880:581c with SMTP id q26-20020ac24a7a000000b004cb0880581cmr8398064lfp.65.1674811788286; Fri, 27 Jan 2023 01:29:48 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.47 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:48 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 01/11] Ext4Pkg: Fix memory leak in Ext4RetrieveDirent Date: Fri, 27 Jan 2023 15:29:35 +0600 Message-Id: <20230127092945.94389-2-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811791; bh=2wADgPmSEUm4UrO/joeTSe1E20ld+52BP6Ha1KSGjSk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=L7jeg3Iw/VI+lcKi/xVJ65WI/psptdKm3HePK2HR8mkodLt1ahVJRCURt7XDBg22pdh on+OvdUe+Bppe7GFPNGr9UeXZPMTg3Y7YppbhqV1UWNpvdPG6q8jshayDjSbtu4mjOaeY 7QgYsHTxyRJkRwwZhf3LZ4BsGJCb6oRg0/M= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811792606100008 Content-Type: text/plain; charset="utf-8" We need to free buffer on return if BlockRemainder !=3D 0. Also changed return logic from function to use use common exit to prevent code duplication. Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user > Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Directory.c | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dx= e/Directory.c index 456916453952..f80b1aacd459 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -113,8 +113,7 @@ Ext4RetrieveDirent ( UINTN ToCopy; UINTN BlockOffset; =20 - Status =3D EFI_NOT_FOUND; - Buf =3D AllocatePool (Partition->BlockSize); + Buf =3D AllocatePool (Partition->BlockSize); =20 if (Buf =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; @@ -128,7 +127,8 @@ Ext4RetrieveDirent ( DivU64x32Remainder (DirInoSize, Partition->BlockSize, &BlockRemainder); if (BlockRemainder !=3D 0) { // Directory inodes need to have block aligned sizes - return EFI_VOLUME_CORRUPTED; + Status =3D EFI_VOLUME_CORRUPTED; + goto Out; } =20 while (Off < DirInoSize) { @@ -137,8 +137,7 @@ Ext4RetrieveDirent ( Status =3D Ext4Read (Partition, Directory, Buf, Off, &Length); =20 if (Status !=3D EFI_SUCCESS) { - FreePool (Buf); - return Status; + goto Out; } =20 for (BlockOffset =3D 0; BlockOffset < Partition->BlockSize; ) { @@ -146,19 +145,19 @@ Ext4RetrieveDirent ( RemainingBlock =3D Partition->BlockSize - BlockOffset; // Check if the minimum directory entry fits inside [BlockOffset, En= dOfBlock] if (RemainingBlock < EXT4_MIN_DIR_ENTRY_LEN) { - FreePool (Buf); - return EFI_VOLUME_CORRUPTED; + Status =3D EFI_VOLUME_CORRUPTED; + goto Out; } =20 if (!Ext4ValidDirent (Entry)) { - FreePool (Buf); - return EFI_VOLUME_CORRUPTED; + Status =3D EFI_VOLUME_CORRUPTED; + goto Out; } =20 if ((Entry->name_len > RemainingBlock) || (Entry->rec_len > Remainin= gBlock)) { // Corrupted filesystem - FreePool (Buf); - return EFI_VOLUME_CORRUPTED; + Status =3D EFI_VOLUME_CORRUPTED; + goto Out; } =20 // Unused entry @@ -193,8 +192,8 @@ Ext4RetrieveDirent ( ToCopy =3D MIN (Entry->rec_len, sizeof (EXT4_DIR_ENTRY)); =20 CopyMem (Result, Entry, ToCopy); - FreePool (Buf); - return EFI_SUCCESS; + Status =3D EFI_SUCCESS; + goto Out; } =20 BlockOffset +=3D Entry->rec_len; @@ -203,8 +202,11 @@ Ext4RetrieveDirent ( Off +=3D Partition->BlockSize; } =20 + Status =3D EFI_NOT_FOUND; + +Out: FreePool (Buf); - return EFI_NOT_FOUND; + return Status; } =20 /** --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99137): https://edk2.groups.io/g/devel/message/99137 Mute This Topic: https://groups.io/mt/96562690/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99138+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99138+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811792; cv=none; d=zohomail.com; s=zohoarc; b=SVBQsFTya/TBS2xtHk/saeqfe1v5SCyJbtPipP/KZSgv4k/GaqgdBmL3Iayhhk0+kCvMkTVEhnjZ/utSpDkWv7Wdvk8WXayG89BgNbMPn54+zSpbBCaHOpfxgJp1rleZMN/wZL76c5pULPaCz4H6CJi4J3ydEsep1EKwiu6J0eI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811792; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=UNA+znyxRLrHEMAQYttwQiWcIV4Q/TBEP7vSsV45c9s=; b=m+F9O0QNfgwWANK97Ee343FSvX3SNJJNlqhdgzCQSuxx1G4yNpAJXlUkA9EEHftbF9/+ykZb6T/xJkwoBrJ2IvFOaxGeLhrZmZ/5sq7RR94SAE12qoW83uBRHKT2olAfJVpbrZpXa5zmj4L+0eoCnhrw6asMoz7+6Nn4NPpQEK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99138+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811792250243.61645559347187; Fri, 27 Jan 2023 01:29:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id dcDTYY1788612x5SexmqWRN0; Fri, 27 Jan 2023 01:29:51 -0800 X-Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web10.98478.1674811791016216494 for ; Fri, 27 Jan 2023 01:29:51 -0800 X-Received: by mail-lf1-f43.google.com with SMTP id d30so7204309lfv.8 for ; Fri, 27 Jan 2023 01:29:50 -0800 (PST) X-Gm-Message-State: BuXHNQryiBxSsPaZmW2SZJ9xx1787277AA= X-Google-Smtp-Source: AMrXdXvoxL1NGvGk/FUVL+BEoKEX+bp0mfFDF6sDIXtspZ47QGiqYgCt2waa/QphK9s+F9u6ED05ng== X-Received: by 2002:a05:6512:3048:b0:4b9:a91c:b0c9 with SMTP id b8-20020a056512304800b004b9a91cb0c9mr13230709lfb.7.1674811789233; Fri, 27 Jan 2023 01:29:49 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:48 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 02/11] Ext4Pkg: Fix incorrect checksum metadata feature check Date: Fri, 27 Jan 2023 15:29:36 +0600 Message-Id: <20230127092945.94389-3-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811791; bh=+uJJ9KDwP3wJI7dV4C13DBSkdje9wSyMjbm0zAx5uS4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=O/qloDKJUOxzCNsZ+o0jP8/e3yZnT4d8fpQvFoeI4ROWf/k2pIDDB/wsy9m80nMgBDM bX0xVhPKhAiMW3Q0vfwOuOsB/ih0Iy1oAzoZRtkr3djmgzXkMOqHkBofI7ZfGX5tvd5fH Uyx25MH0GDarNObj5WyzJXYm4p0mHg9uBbE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811792596100005 Content-Type: text/plain; charset="utf-8" Missing comparison !=3D 0 leads to broken logic condition. Also replaced CSUM_SEED feature_incompat check with predefined macro EXT4_HAS_INCOMPAT Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Superblock.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Superblock.c b/Features/Ext4Pkg/Ext4D= xe/Superblock.c index 5a3c7f478187..35dcf3c007c8 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Superblock.c +++ b/Features/Ext4Pkg/Ext4Dxe/Superblock.c @@ -220,13 +220,11 @@ Ext4OpenSuperblock ( } =20 // At the time of writing, it's the only supported checksum. - if (Partition->FeaturesCompat & EXT4_FEATURE_RO_COMPAT_METADATA_CSUM && - (Sb->s_checksum_type !=3D EXT4_CHECKSUM_CRC32C)) - { + if (EXT4_HAS_METADATA_CSUM (Partition) && (Sb->s_checksum_type !=3D EXT4= _CHECKSUM_CRC32C)) { return EFI_UNSUPPORTED; } =20 - if ((Partition->FeaturesIncompat & EXT4_FEATURE_INCOMPAT_CSUM_SEED) !=3D= 0) { + if (EXT4_HAS_INCOMPAT (Partition, EXT4_FEATURE_INCOMPAT_CSUM_SEED)) { Partition->InitialSeed =3D Sb->s_checksum_seed; } else { Partition->InitialSeed =3D Ext4CalculateChecksum (Partition, Sb->s_uui= d, 16, ~0U); --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99138): https://edk2.groups.io/g/devel/message/99138 Mute This Topic: https://groups.io/mt/96562691/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99139+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99139+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811793; cv=none; d=zohomail.com; s=zohoarc; b=MQKKICXkDvYN31H+ssgpar47LrDBAWwk1ZByowAhIhxufjAitjt2xUlt3MesnN71VJUYl8L5OMp9+xpelVj78oHOkJhHQ9sIsZtB4pRPGM9uMK/ejPSP1BUl5kfElTMPy+Jxs9B01Iky7rwTHJTnPOuoLiDhyWrNdYgPNj4GvrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811793; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=21A3jZEGi34ojvewE2Vwf0Iik5nn+iX/RSJWe8sO+4g=; b=bzF4kEyDlk0i+o7BJ7WzDbX9JpDFEJ49A1WL8BfJtk9cHXEiZ15q5YUOUsVaT3w+nrpg30wLdxi0HHhCVdf/Lsf73uOFGfmEAXZ3vtXlypr80QyuvWA0SWcgtsbr5keDb+GPgmwcjhmYaC+rSeiOX1S2z2S7eIPgHVkTumDCuuM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99139+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811793264364.8429237807312; Fri, 27 Jan 2023 01:29:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9sEEYY1788612xoF4YyxiShx; Fri, 27 Jan 2023 01:29:52 -0800 X-Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by mx.groups.io with SMTP id smtpd.web11.98570.1674811791892615145 for ; Fri, 27 Jan 2023 01:29:52 -0800 X-Received: by mail-lf1-f51.google.com with SMTP id o20so7236246lfk.5 for ; Fri, 27 Jan 2023 01:29:51 -0800 (PST) X-Gm-Message-State: wLjr7Q6w5HEaQicxC9u7VyYOx1787277AA= X-Google-Smtp-Source: AMrXdXsfizZ44ZhWyly8mV/kWtna1DxvV01uG4WxLpjMdLHrznlTL2a75H/lqZVp5YRW7lKKyFK+Vw== X-Received: by 2002:a05:6512:114e:b0:4d0:8469:b196 with SMTP id m14-20020a056512114e00b004d08469b196mr12391671lfg.3.1674811790107; Fri, 27 Jan 2023 01:29:50 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:49 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 03/11] Ext4Pkg: Fix division by zero by adding check for s_inodes_per_group Date: Fri, 27 Jan 2023 15:29:37 +0600 Message-Id: <20230127092945.94389-4-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811792; bh=WpXjbcbwBxSCuR5disBmf0vaWBnJ8NpmewsXkYTbEP4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Oy36ppahkms+iCW10iQRi4mspEVhqadHZCCUkO0TnJdPfETvIJHY0Z7TM7FcwBDC2Sr OhcxxSSQgIBtwV310nPCKNYILiLERW6EcjjIMhzTlk2lPYcVWzyzRMkZbKAxNoJC6KzFw Mmki6oQZ6VpE3B370Jnak78Otee7hL9V/KQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811794646100016 Content-Type: text/plain; charset="utf-8" Superblock s_inodes_per_group field can't be zero, it leads to division by zero in BlockGroup routine Ext4ReadInode Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Superblock.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Features/Ext4Pkg/Ext4Dxe/Superblock.c b/Features/Ext4Pkg/Ext4D= xe/Superblock.c index 35dcf3c007c8..be3527e4d618 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Superblock.c +++ b/Features/Ext4Pkg/Ext4Dxe/Superblock.c @@ -243,6 +243,11 @@ Ext4OpenSuperblock ( =20 DEBUG ((DEBUG_FS, "Read only =3D %u\n", Partition->ReadOnly)); =20 + if (Sb->s_inodes_per_group =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "[ext4] Inodes per group can not be zero\n")); + return EFI_VOLUME_CORRUPTED; + } + Partition->BlockSize =3D (UINT32)LShiftU64 (1024, Sb->s_log_block_size); =20 // The size of a block group can also be calculated as 8 * Partition->Bl= ockSize --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99139): https://edk2.groups.io/g/devel/message/99139 Mute This Topic: https://groups.io/mt/96562692/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99140+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99140+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811793; cv=none; d=zohomail.com; s=zohoarc; b=laH3t0NtP2JPiVSWIoARz1PSF9X0nT4OeYRcYGAc9c9z7b5GNqaeZBxJhMfUTvGusXzIJWkbVe2h6ta4iI9gu0Jy7uIGicdjv41qLmDFUvIeZ2qYOWRNmZv29mTpEahNcIO6b4J7G/E5Ngg73AZc6Wm6607ACyXsusaSJ/XFKUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811793; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=w1hgSnO2gCNEgWzoWtnhodyi1Z5rFBOgr60J1PFixFw=; b=fUr3D10QLqt4UAZVqbDAVj0IHkBzxyHkPQudcV/H8nZc9fcHfoN4fVsf/jEMdnEbs1dYJvGR1XoSepGTk5uect2fCo1/D+tTyN+FGqO0tr57khdsuqoD8DCQjbRxhvQG3rIMW8rRa3eTTZVuWxuYobYIFP7aVdz1twyqVV1o0Po= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99140+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811793902115.88111382721775; Fri, 27 Jan 2023 01:29:53 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6mqAYY1788612xrlME4R7AV3; Fri, 27 Jan 2023 01:29:53 -0800 X-Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by mx.groups.io with SMTP id smtpd.web10.98479.1674811792817229856 for ; Fri, 27 Jan 2023 01:29:53 -0800 X-Received: by mail-lf1-f42.google.com with SMTP id bp15so7179084lfb.13 for ; Fri, 27 Jan 2023 01:29:52 -0800 (PST) X-Gm-Message-State: REajX9oKQQdPOO3AHQ2izb4qx1787277AA= X-Google-Smtp-Source: AMrXdXv0zh9uag0Jo+eqt2mwBHd75REQxVVfv7GvuxU9hRh9fvnDANPUwqaskegir3sW3rRP1JvM+g== X-Received: by 2002:ac2:4146:0:b0:4cc:553f:5b68 with SMTP id c6-20020ac24146000000b004cc553f5b68mr8036038lfi.40.1674811791014; Fri, 27 Jan 2023 01:29:51 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:50 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 04/11] Ext4Pkg: Add inode number validity check Date: Fri, 27 Jan 2023 15:29:38 +0600 Message-Id: <20230127092945.94389-5-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811793; bh=4jqIoMHX0CsZAPZR17Oykvx/rhyijoo5PRi5t7TKRPE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=abJ2hW839ju0r9b8qYDn/Gu0klICZ6nHa0++GRo0Oj/SGyRGkwG1RkYKk14S3skOicL jq6Z/umAq5cqcYWTqYYybGEjHtHwKwZYBVoKsJlI9ChiKCqT25nLPpeV3XdrlSBHLN1l2 4ez9QeK6Wv93+w3HFEM5c3jx3QJmVUmnOds= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811794630100014 Content-Type: text/plain; charset="utf-8" We need to validate inode number to prevent possible null-pointer dereference of directory parent in Ext4OpenDirent. Also checks that inode number valid across opened partition before we read it in Ext4ReadInode. Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov --- Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h | 13 ++++++++-- Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 25 ++++++++++++++++++++ Features/Ext4Pkg/Ext4Dxe/BlockGroup.c | 5 ++++ Features/Ext4Pkg/Ext4Dxe/Directory.c | 10 ++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h b/Features/Ext4Pkg/Ext4Dxe= /Ext4Disk.h index d0a455d0e572..70cb6c3209dd 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h @@ -484,8 +484,17 @@ typedef UINT64 EXT4_BLOCK_NR; typedef UINT32 EXT2_BLOCK_NR; typedef UINT32 EXT4_INO_NR; =20 -// 2 is always the root inode number in ext4 -#define EXT4_ROOT_INODE_NR 2 +/* Special inode numbers */ +#define EXT4_ROOT_INODE_NR 2 +#define EXT4_USR_QUOTA_INODE_NR 3 +#define EXT4_GRP_QUOTA_INODE_NR 4 +#define EXT4_BOOT_LOADER_INODE_NR 5 +#define EXT4_UNDEL_DIR_INODE_NR 6 +#define EXT4_RESIZE_INODE_NR 7 +#define EXT4_JOURNAL_INODE_NR 8 + +/* First non-reserved inode for old ext4 filesystems */ +#define EXT4_GOOD_OLD_FIRST_INODE_NR 11 =20 #define EXT4_BLOCK_FILE_HOLE 0 =20 diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index f608def7c9eb..2e489ce4dd86 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -287,6 +287,31 @@ Ext4GetBlockGroupDesc ( IN UINT32 BlockGroup ); =20 +/** + Retrieves the first usable non-reserved inode number from the superblock + of the opened partition. + + @param[in] Partition Pointer to the opened ext4 partition. + + @return The first usable inode number (non-reserved). +**/ +#define EXT4_FIRST_INODE_NR(Partition) = \ + ((Partition->SuperBlock.s_rev_level =3D=3D EXT4_GOOD_OLD_REV) ? = \ + EXT4_GOOD_OLD_FIRST_INODE_NR : = \ + Partition->SuperBlock.s_first_ino) + +/** + Checks inode number validity across superblock of the opened partition. + + @param[in] Partition Pointer to the opened ext4 partition. + + @return TRUE if inode number is valid. +**/ +#define EXT4_IS_VALID_INODE_NR(Partition, InodeNum) = \ + (InodeNum =3D=3D EXT4_ROOT_INODE_NR || = \ + (InodeNum >=3D EXT4_FIRST_INODE_NR(Partition) && = \ + InodeNum <=3D Partition->SuperBlock.s_inodes_count)) + /** Reads an inode from disk. =20 diff --git a/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c b/Features/Ext4Pkg/Ext4D= xe/BlockGroup.c index cba96cd95afc..f34cdc5dbad7 100644 --- a/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c +++ b/Features/Ext4Pkg/Ext4Dxe/BlockGroup.c @@ -50,6 +50,11 @@ Ext4ReadInode ( EXT4_BLOCK_NR InodeTableStart; EFI_STATUS Status; =20 + if (!EXT4_IS_VALID_INODE_NR (Partition, InodeNum)) { + DEBUG ((DEBUG_ERROR, "[ext4] Error reading inode: inode number %lu isn= 't valid\n", InodeNum)); + return EFI_VOLUME_CORRUPTED; + } + BlockGroupNumber =3D (UINT32)DivU64x64Remainder ( InodeNum - 1, Partition->SuperBlock.s_inodes_per_group, diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dx= e/Directory.c index f80b1aacd459..2e9a58a7e329 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -164,6 +164,10 @@ Ext4RetrieveDirent ( if (Entry->inode =3D=3D 0) { BlockOffset +=3D Entry->rec_len; continue; + } else if (!EXT4_IS_VALID_INODE_NR (Partition, Entry->inode)) { + DEBUG ((DEBUG_ERROR, "[ext4] Ext4RetrieveDirent directory entry in= ode number %u isn't valid\n", Entry->inode)); + Status =3D EFI_VOLUME_CORRUPTED; + goto Out; } =20 Status =3D Ext4GetUcs2DirentName (Entry, DirentUcs2Name); @@ -510,6 +514,12 @@ Ext4ReadDir ( // (which we should not expose to ReadDir). ShouldSkip =3D Entry.inode =3D=3D 0 || Entry.name_len =3D=3D 0 || IsDo= tOrDotDot; =20 + if ((Entry.inode !=3D 0) && !EXT4_IS_VALID_INODE_NR (Partition, Entry.= inode)) { + DEBUG ((DEBUG_ERROR, "[ext4] Ext4ReadDir directory entry inode numbe= r %u isn't valid\n", Entry.inode)); + Status =3D EFI_VOLUME_CORRUPTED; + goto Out; + } + if (ShouldSkip) { Offset +=3D Entry.rec_len; continue; --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99140): https://edk2.groups.io/g/devel/message/99140 Mute This Topic: https://groups.io/mt/96562693/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99142+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99142+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811795; cv=none; d=zohomail.com; s=zohoarc; b=b30fFL1YhCL4u5GORJ/ClDJJ/N+MfSEhHBwqmbuJtk+qwhNmXSQoG4RSS0J2Hl4QwAEPCaDQm9EK/8Ul9KSDOAr7u1h8Bjw2Cmp+aGSItOrrhTLW0MHuf95M7yP5jOqCdDeEIppWJ8BSuBBVAldlBHjhNZKPzSgRTXQuwY0V4iU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811795; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6UoRfhl1z6zNMKxktXbjEXkuzyCm48lRax/gDvIJswc=; b=kG0D+8gdBCduu2VUbbdNBo/xXwo+7OgH9VrsRONX9knqFKDwePqqHYNs0I6LCvKnUGFujG190fTvs1MwPjoL5cu/I6ETwSEuSbcJKSY8B+igi7B1QUGS7Ey8QbCFOszAPBxKR5Rnad4Z20AwztnU6QIh9Y8YkhybaDV8zekTbXE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99142+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811795476797.2286019128658; Fri, 27 Jan 2023 01:29:55 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id jPPRYY1788612xX1yuDga0sO; Fri, 27 Jan 2023 01:29:55 -0800 X-Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by mx.groups.io with SMTP id smtpd.web10.98480.1674811793804468085 for ; Fri, 27 Jan 2023 01:29:54 -0800 X-Received: by mail-lf1-f41.google.com with SMTP id v17so1309963lfd.7 for ; Fri, 27 Jan 2023 01:29:53 -0800 (PST) X-Gm-Message-State: YYyQmKXB7MRaeyxCB9DXcPicx1787277AA= X-Google-Smtp-Source: AMrXdXvn1v+YYCFY25nwCK1x+xq+dGtbWTvVJ++dkaVcWYBB3WWOLxjteQlHrfwUQEbG5J7B7VdGaA== X-Received: by 2002:ac2:55b0:0:b0:4d5:5b50:f8f0 with SMTP id y16-20020ac255b0000000b004d55b50f8f0mr10356242lfg.46.1674811791890; Fri, 27 Jan 2023 01:29:51 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:51 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 05/11] Ext4Pkg: Fix shift out of bounds in Ext4OpenSuperblock Date: Fri, 27 Jan 2023 15:29:39 +0600 Message-Id: <20230127092945.94389-6-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811795; bh=KP2SKZL4plVxpj05loIeeLP/4FAgT+E+HCvaXzqKk4s=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=cgV4O+EG08WV0xQ4VjF/zaWOO4dZ2jbT9J5SW5JALhvCwzCe56Bx17UYTvWtKbHcc3f KoDdBSq1MvZ51SzAHfaY558K7oS4n2bwKj9iu0h2PANPZZ+mcxKeiysDCs6Uk14xDLLXB liAhDUyGqpK1H0LLVplErQcwZsepEH8saq8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811796648100023 Content-Type: text/plain; charset="utf-8" Missing check for wrong s_log_block_size exponent leads to shift out of bounds. Limit block size to 2 MiB Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 14 ++++++++++++++ Features/Ext4Pkg/Ext4Dxe/Superblock.c | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index 2e489ce4dd86..a23323319a59 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -40,6 +40,20 @@ #define EXT4_EFI_PATH_MAX 4096 #define EXT4_DRIVER_VERSION 0x0000 =20 +// +// The EXT4 Specification doesn't strictly limit block size and this value= could be up to 2^31, +// but in practice it is limited by PAGE_SIZE due to performance significa= nt impact. +// Many EXT4 implementations have size of block limited to PAGE_SIZE. In m= any cases it's limited +// to 4096, which is a commonly supported page size on most MMU-capable ha= rdware, and up to 65536. +// So, to take a balance between compatibility and security measures, it i= s decided to use the +// value of 2MiB as the limit, which is equal to page size on new hardware. +// As for supporting big block sizes, EXT4 has a RO_COMPAT_FEATURE called = BIGALLOC, which changes +// EXT4 to use clustered allocation, so that each bit in the ext4 block al= location bitmap addresses +// a power of two number of blocks. So it would be wiser to implement and = use this feature +// if there is such a need instead of big block size. +// +#define EXT4_LOG_BLOCK_SIZE_MAX 11 + /** Opens an ext4 partition and installs the Simple File System protocol. =20 diff --git a/Features/Ext4Pkg/Ext4Dxe/Superblock.c b/Features/Ext4Pkg/Ext4D= xe/Superblock.c index be3527e4d618..3f56de93c105 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Superblock.c +++ b/Features/Ext4Pkg/Ext4Dxe/Superblock.c @@ -248,6 +248,11 @@ Ext4OpenSuperblock ( return EFI_VOLUME_CORRUPTED; } =20 + if (Sb->s_log_block_size > EXT4_LOG_BLOCK_SIZE_MAX) { + DEBUG ((DEBUG_ERROR, "[ext4] SuperBlock s_log_block_size %lu is too bi= g\n", Sb->s_log_block_size)); + return EFI_UNSUPPORTED; + } + Partition->BlockSize =3D (UINT32)LShiftU64 (1024, Sb->s_log_block_size); =20 // The size of a block group can also be calculated as 8 * Partition->Bl= ockSize --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99142): https://edk2.groups.io/g/devel/message/99142 Mute This Topic: https://groups.io/mt/96562695/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99141+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99141+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811795; cv=none; d=zohomail.com; s=zohoarc; b=gY+PAkegGPTzxdUd3tu6mftOFKwI9OE85VbVpYIEtyW9S/Rgw7PY4jfISs2JP/60FsdNmdRxz2juPU9WKu0C8ZDibuJxWJAmpUb3EplZmU3zD5cnQggBFv9hiKMzydtKEHxpI2K16D6xNTnJNt3NAp1GRynm+BfVRzdjfVK4hVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811795; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Iebp8oXyP4MffAYPrznmjDtPw0INSBseYYTqX1Rliwg=; b=ZbiY5OmwhRiMjXBk37nW8oNVs2tC9FJRlY1gWv+ZspqBSNNxitOWGtX+dFA11ZNda2tM6FwL4BbI5ZvPauVFpXvXN9a+bTZqjBektdXBikkPLpBZ7fN7AqaCIha5yBw5YejW2/59OVQD9yo6gOUGF1MWL8CjqhmKgAP/C2BK4vs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99141+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811795068379.70818028859856; Fri, 27 Jan 2023 01:29:55 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uiJSYY1788612x7qO7nBOR4j; Fri, 27 Jan 2023 01:29:54 -0800 X-Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by mx.groups.io with SMTP id smtpd.web11.98570.1674811791892615145 for ; Fri, 27 Jan 2023 01:29:54 -0800 X-Received: by mail-lf1-f51.google.com with SMTP id o20so7236438lfk.5 for ; Fri, 27 Jan 2023 01:29:53 -0800 (PST) X-Gm-Message-State: PghygozbskK2kAAxes3Ablsax1787277AA= X-Google-Smtp-Source: AMrXdXsBgCJ5shgEXYr/lKJLL/LJ83cFuK1U7kNQoEaBP1CexF2jA9sIeg7zKL6lJwnRfu6jizN+3w== X-Received: by 2002:ac2:4473:0:b0:4ca:f97f:4a21 with SMTP id y19-20020ac24473000000b004caf97f4a21mr10105563lfl.37.1674811792783; Fri, 27 Jan 2023 01:29:52 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:52 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 06/11] Ext4Pkg: Corrects integer overflow check logic in DiskUtil Date: Fri, 27 Jan 2023 15:29:40 +0600 Message-Id: <20230127092945.94389-7-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811794; bh=BR5Ayh3q9eQXkW5Xg7PgC4Hk27UIkRxLlKchwIFOaa4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=esopnXck7DFEmbLSXPwCv1PGb0Ii1fqXTob7MMh22jSTyBlFV3hYj1WTUO9Zwf3gCNG BFUgHIBRsd0CE1nEJnj4EEtxFfreV0DpFF4pie/n1EoD2sqQMaBdXzDIBKEPyc1vCJbem vStcLUmeWHld4PTA1N4GeTB5c5JAYrhYUZU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811796646100021 Content-Type: text/plain; charset="utf-8" Corrects multiplication overflow check code Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Pkg.dsc | 2 +- Features/Ext4Pkg/Ext4Dxe/DiskUtil.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Pkg.dsc b/Features/Ext4Pkg/Ext4Pkg.dsc index 59bc327ebf6e..621c63eaf92d 100644 --- a/Features/Ext4Pkg/Ext4Pkg.dsc +++ b/Features/Ext4Pkg/Ext4Pkg.dsc @@ -46,7 +46,7 @@ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib= /BaseOrderedCollectionRedBlackTreeLib.inf BaseUcs2Utf8Lib|RedfishPkg/Library/BaseUcs2Utf8Lib/BaseUcs2Utf8Lib.inf - =20 + # # Required for stack protector support # diff --git a/Features/Ext4Pkg/Ext4Dxe/DiskUtil.c b/Features/Ext4Pkg/Ext4Dxe= /DiskUtil.c index 32da35f7d9f5..c4af956da926 100644 --- a/Features/Ext4Pkg/Ext4Dxe/DiskUtil.c +++ b/Features/Ext4Pkg/Ext4Dxe/DiskUtil.c @@ -60,11 +60,11 @@ Ext4ReadBlocks ( // Check for overflow on the block -> byte conversions. // Partition->BlockSize is never 0, so we don't need to check for that. =20 - if (Offset > DivU64x32 ((UINT64)-1, Partition->BlockSize)) { + if ((NumberBlocks !=3D 0) && (DivU64x64Remainder (Offset, BlockNumber, N= ULL) !=3D Partition->BlockSize)) { return EFI_INVALID_PARAMETER; } =20 - if (Length > (UINTN)-1/Partition->BlockSize) { + if ((NumberBlocks !=3D 0) && (Length / NumberBlocks !=3D Partition->Bloc= kSize)) { return EFI_INVALID_PARAMETER; } =20 @@ -94,12 +94,12 @@ Ext4AllocAndReadBlocks ( =20 Length =3D NumberBlocks * Partition->BlockSize; =20 - if (Length > (UINTN)-1/Partition->BlockSize) { + // Check for integer overflow + if ((NumberBlocks !=3D 0) && (Length / NumberBlocks !=3D Partition->Bloc= kSize)) { return NULL; } =20 Buf =3D AllocatePool (Length); - if (Buf =3D=3D NULL) { return NULL; } --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99141): https://edk2.groups.io/g/devel/message/99141 Mute This Topic: https://groups.io/mt/96562694/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99143+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99143+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811797; cv=none; d=zohomail.com; s=zohoarc; b=A5vew0Q8Iow55X8+QykQiTYOgDk/HDzXi5LfQBZO3RbdaJaNrI+2O2hkPl7rEtxbHs58ISx3UXkqmQPiHEviUqpBOjTx8b5r3i9Xx7GPBVQHoRsUmI5aKgK5JXFTlouH8B1ZCIQUTVgWkQcRifPTj3lai4q2rXQMFOjKGXH8SPg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811797; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=5Ju/gJ7m4/zrNTU0VhX9uXgcfWnmvv+MZQegKIawe9U=; b=LIuIDS8Zky8aPazKHWE041DZ/3cJHE9FKEdWFj1oNV9PpAtffJaX2hFbhIzZxvVKC0VAlJwBQFRlDPNirdiMQFVYZR/L9McFVKwfLCVQf3VOxyPjP/cbUnSGQ+ekWaTvyhzL9I2fjmYTBAUNK1oL9Tk0gTAxMlxy2iPnkcMYdME= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99143+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811797231391.1554052935443; Fri, 27 Jan 2023 01:29:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id eMyvYY1788612x0Cu3kAK6se; Fri, 27 Jan 2023 01:29:56 -0800 X-Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by mx.groups.io with SMTP id smtpd.web10.98482.1674811795893637453 for ; Fri, 27 Jan 2023 01:29:56 -0800 X-Received: by mail-lj1-f179.google.com with SMTP id j15so3962629ljg.8 for ; Fri, 27 Jan 2023 01:29:55 -0800 (PST) X-Gm-Message-State: DZajiuHyMoMnjsni02xGeWrvx1787277AA= X-Google-Smtp-Source: AMrXdXtCznDUgCro4sy6yWhfSTLi3Ao7AAmXw3qmIzqG0CGuqaF2feVVFv0jxB+kh4rGMSeovVFgTw== X-Received: by 2002:a2e:a9a4:0:b0:28b:74b5:590e with SMTP id x36-20020a2ea9a4000000b0028b74b5590emr12974607ljq.50.1674811793727; Fri, 27 Jan 2023 01:29:53 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.52 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:53 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 07/11] Ext4Pkg: Check that source file is directory in Ext4OpenInternal Date: Fri, 27 Jan 2023 15:29:41 +0600 Message-Id: <20230127092945.94389-8-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811796; bh=9H/R5cAea4qLASmeL38zAO4xfMeNqANqlp74kKrNvlI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=jPm/HVQYwfR8EzEv3PDAS3EU/B2UUe+xaEiXNR/zT5xneLlkbr4o2nhLw8+VchgSWuo lDMshVT9blpGH9GJZuf1cv+Ixd7S5uRiKxf00Pu6M9g+Cw2jNvukA80AA0LifkE6qn5Wy x7RadQ2KhhG+XDOB7LF6Fs9RYUXeiY38ijc= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811798661100032 Content-Type: text/plain; charset="utf-8" This check already present in the while loop below, but absent for cases when input file is nameless, so to handle assertion in Ext4ReadFile we need to add it at the top of function Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/File.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c b/Features/Ext4Pkg/Ext4Dxe/Fil= e.c index 8dfe324255f4..9dde4a5d1a2d 100644 --- a/Features/Ext4Pkg/Ext4Dxe/File.c +++ b/Features/Ext4Pkg/Ext4Dxe/File.c @@ -207,6 +207,11 @@ Ext4OpenInternal ( Level =3D 0; =20 DEBUG ((DEBUG_FS, "[ext4] Ext4OpenInternal %s\n", FileName)); + + if (!Ext4FileIsDir (Current)) { + return EFI_INVALID_PARAMETER; + } + // If the path starts with a backslash, we treat the root directory as t= he base directory if (FileName[0] =3D=3D L'\\') { FileName++; @@ -219,6 +224,10 @@ Ext4OpenInternal ( return EFI_ACCESS_DENIED; } =20 + if (!Ext4FileIsDir (Current)) { + return EFI_INVALID_PARAMETER; + } + // Discard leading path separators while (FileName[0] =3D=3D L'\\') { FileName++; @@ -242,10 +251,6 @@ Ext4OpenInternal ( =20 DEBUG ((DEBUG_FS, "[ext4] Opening %s\n", PathSegment)); =20 - if (!Ext4FileIsDir (Current)) { - return EFI_INVALID_PARAMETER; - } - if (!Ext4IsLastPathSegment (FileName)) { if (!Ext4DirCanLookup (Current)) { return EFI_ACCESS_DENIED; --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99143): https://edk2.groups.io/g/devel/message/99143 Mute This Topic: https://groups.io/mt/96562696/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99145+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99145+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811798; cv=none; d=zohomail.com; s=zohoarc; b=cEHpU5/dTDul6zu/gH3ea4VxIYXDOWuGmX70LKSg8zvhvMKI6TPRT1TYeZCJk+3wTqcx5tLb9jN1ATr7py4XLdP5nqHGQgYbb/CYtD6jKUKYdDbwfyzjtwVoqqx38a0p5QJ19zwecwKVgSIcJEgwvPTRPYcqmPb31Yx6OeJ0R2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811798; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=+WkLI8UD2bm1xsoBsue/5KExmhEvGej3z2l0sWxXD9Y=; b=VtfbmlJMcxKaYtRzI6C905Zx8O20Xt7lC03Fz+928mnuQo8+4DQa8EgHgx5LTU2l2OlkNsOZB6wYdqYGOBi+UfpZ8v90LVwka+2MQt7jbenlXYGmylZ+Fxoi1SEjT4BwJiNrg65JlKRBb5SzKddGqVAL6e9AzLksvOzKziSmBNk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99145+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811798589603.8625302288704; Fri, 27 Jan 2023 01:29:58 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uYgNYY1788612x1nhNCIcD24; Fri, 27 Jan 2023 01:29:58 -0800 X-Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web10.98483.1674811796503971478 for ; Fri, 27 Jan 2023 01:29:56 -0800 X-Received: by mail-lf1-f43.google.com with SMTP id br9so7244170lfb.4 for ; Fri, 27 Jan 2023 01:29:56 -0800 (PST) X-Gm-Message-State: ErYuBxmzlUODu0P0XybcTbTdx1787277AA= X-Google-Smtp-Source: AMrXdXuBlZN+3uRDNHi0ye/5ic9zI85kn/yeSBSFdJ6bd2jPiFfV79lBCq5gTjdK9+qFJ8mqukVxuQ== X-Received: by 2002:ac2:44d5:0:b0:4cc:8572:c7bc with SMTP id d21-20020ac244d5000000b004cc8572c7bcmr9270934lfm.65.1674811794634; Fri, 27 Jan 2023 01:29:54 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:54 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 08/11] Ext4Pkg: Check VolumeName allocation correctness in Ext4GetVolumeName Date: Fri, 27 Jan 2023 15:29:42 +0600 Message-Id: <20230127092945.94389-9-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811798; bh=bcn0WcmIXfCRdstDeNctk4koseAx0vlsKzLO49/hJ2Q=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=qyklgXrcOZGK0++3pso3b4vxqAsJ4ynxJtmeOKSRhtN3V5FOwH1j+dabacA5IXCi+SJ 7iATkL6PdGXf7Mc8WG9wk8j3JP2I4JQMxGd/pr7qUba79DrprfyPMIW3S1sEXwm80mhsW 2P8vv+j/vCFqoUVZkIoK0WrqyHOMUlT+o68= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811800646100039 Content-Type: text/plain; charset="utf-8" Missing check in some cases leads to failed StrCpyS call in Ext4GetVolumeLabelInfo. Also correct condition that checks Inode pointer for being NULL in Ext4AllocateInode Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: cfbbae595eec ("Ext4Pkg: Add handling of EFI_FILE_SYSTEM_VOLUME_LABEL= GetInfo().") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/File.c | 10 ++++++++-- Features/Ext4Pkg/Ext4Dxe/Inode.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c b/Features/Ext4Pkg/Ext4Dxe/Fil= e.c index 9dde4a5d1a2d..677caf88fbdc 100644 --- a/Features/Ext4Pkg/Ext4Dxe/File.c +++ b/Features/Ext4Pkg/Ext4Dxe/File.c @@ -719,7 +719,11 @@ Ext4GetVolumeName ( =20 VolNameLength =3D StrLen (VolumeName); } else { - VolumeName =3D AllocateZeroPool (sizeof (CHAR16)); + VolumeName =3D AllocateZeroPool (sizeof (CHAR16)); + if (VolumeName =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + VolNameLength =3D 0; } =20 @@ -786,7 +790,9 @@ Ext4GetFilesystemInfo ( Info->VolumeSize =3D MultU64x32 (TotalBlocks, Part->BlockSize); Info->FreeSpace =3D MultU64x32 (FreeBlocks, Part->BlockSize); =20 - StrCpyS (Info->VolumeLabel, VolNameLength + 1, VolumeName); + Status =3D StrCpyS (Info->VolumeLabel, VolNameLength + 1, VolumeName); + + ASSERT_EFI_ERROR (Status); =20 FreePool (VolumeName); =20 diff --git a/Features/Ext4Pkg/Ext4Dxe/Inode.c b/Features/Ext4Pkg/Ext4Dxe/In= ode.c index e44b5638599f..90e3eb88f523 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Inode.c +++ b/Features/Ext4Pkg/Ext4Dxe/Inode.c @@ -230,7 +230,7 @@ Ext4AllocateInode ( =20 Inode =3D AllocateZeroPool (InodeSize); =20 - if (!Inode) { + if (Inode =3D=3D NULL) { return NULL; } =20 --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99145): https://edk2.groups.io/g/devel/message/99145 Mute This Topic: https://groups.io/mt/96562698/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99144+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99144+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811797; cv=none; d=zohomail.com; s=zohoarc; b=LzD/jKbKj+YEGQj62MY1oraInXPRQTBDXXS8MEcB7rYuL7Oy6/lJHvBY0a5PPkIFzgoGaeKH3PGGBSKFD9cvFnP1AYTEz/JKmbos49iETZw4NGlKvtA/uVXOyQivx1505Ztn39xH0lDx6fKbQphb1XiElqjpJRggVLMhs9aI808= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811797; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=i3xPSi0WnwVF5T264Q9kqkGtXEWH+Wy1GMFYsxLfhOU=; b=IFL3oSnpyziRjZEdPwI9GUQhNrEAkobkCNBobGnMi8JMaBsTz6eMATbAB3D3EFU4oiZyUc4uh59Rs+gJN00SaJfnE8ndFhlp5+9vEYLwsAeA37yNdn1piI/MRb0+5UhJHkCereUHzJx8Y0e/Ek3vWkSLc6kYxBDPsVaH8spdQms= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99144+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811797404314.90061681881514; Fri, 27 Jan 2023 01:29:57 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZQ32YY1788612xRizlJoOhMw; Fri, 27 Jan 2023 01:29:57 -0800 X-Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by mx.groups.io with SMTP id smtpd.web10.98479.1674811792817229856 for ; Fri, 27 Jan 2023 01:29:56 -0800 X-Received: by mail-lf1-f42.google.com with SMTP id bp15so7179379lfb.13 for ; Fri, 27 Jan 2023 01:29:56 -0800 (PST) X-Gm-Message-State: cMSdJOEiyZiOoSJuXB0CcLPXx1787277AA= X-Google-Smtp-Source: AMrXdXv8ELOlsrH1OrK5fe5CQqZ5KVR043XvI336ViCnX/GYc1dz+y5C2xPOU8yJm1wyGHb48RjWgw== X-Received: by 2002:ac2:434f:0:b0:4b5:9e70:ca6e with SMTP id o15-20020ac2434f000000b004b59e70ca6emr11076779lfl.17.1674811795517; Fri, 27 Jan 2023 01:29:55 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.54 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:55 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 09/11] Ext4Pkg: Add missing exit Status in Ext4OpenDirent Date: Fri, 27 Jan 2023 15:29:43 +0600 Message-Id: <20230127092945.94389-10-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811797; bh=wSHL6SRH+JazKuasnnXpg8rCiuZ70HUHOUjEaavGMBg=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=MW8GATQ5+mNcEcfsLR3W+3CjQHDEjZlzvlrgy6smnc6O+VvQV4sEfkBp+D8QuLKOKDA AVmYgi+eZF5OniL7P+y32LV0H0xWhRhcv/CEud1PLFAvF5Ke9LzYxlP/XYfm59LYyyx4k /6U7/UIdvJAVtOPfrv21VrVx01W6mAtYQdM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811798654100031 Content-Type: text/plain; charset="utf-8" Missing EFI_OUT_OF_RESOURCES exit status on failed Ext4CreateDentry leads to NULL-pointer dereference in Ext4GetFileInfo (passing NULL buffer in Ext4ReadDir) Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: 21b1853880d5 ("Ext4Pkg: Add a directory entry tree.") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Directory.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dx= e/Directory.c index 2e9a58a7e329..0753a20b5377 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -267,7 +267,8 @@ Ext4OpenDirent ( } else { File->Dentry =3D Ext4CreateDentry (FileName, Directory->Dentry); =20 - if (!File->Dentry) { + if (File->Dentry =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; goto Error; } } --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99144): https://edk2.groups.io/g/devel/message/99144 Mute This Topic: https://groups.io/mt/96562697/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99146+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99146+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811798; cv=none; d=zohomail.com; s=zohoarc; b=ENmdOX7EaD7fd/YqErgR1MS6QP5HSw++rG/yeSRDj2z5FGmrOqjh5pFb8lQn6W5PMGC407Etij+DqtvC7V3Y4yprfJlnVsPG7nC69NHylJULZ20U1VinfvQtqeWbhaV6tXDyZH77OioLxal0pSGMEENyqXTpW4OciJtGIrwR3H0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811798; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=fEd7nA764YB6aEXm1AfqB1snZG2WhoxyFzxU+KQZlQo=; b=TyOdZkQc+qi48ppuxNgVjux3h9aH78aeX9Ez0glaAJj0uCBXynrclSl/21/9Xgewchyyq/mD/k+O6sIpu8DGSb6CW0LMNaVZ06QEMJMb5OG4si2Kl9SL7uKd21SVdNRECd8KaNTja+77/hvmhnmaBK3p5gCq3km9YjLRUE8dx1o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99146+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1674811798398760.0599007505668; Fri, 27 Jan 2023 01:29:58 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id SMU9YY1788612xIhu1KBDZVO; Fri, 27 Jan 2023 01:29:58 -0800 X-Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by mx.groups.io with SMTP id smtpd.web11.98570.1674811791892615145 for ; Fri, 27 Jan 2023 01:29:57 -0800 X-Received: by mail-lf1-f51.google.com with SMTP id o20so7236637lfk.5 for ; Fri, 27 Jan 2023 01:29:56 -0800 (PST) X-Gm-Message-State: JmIFeaUQgIYgT3cH6twVcwhhx1787277AA= X-Google-Smtp-Source: AMrXdXtSIZ7PXKTrZkL+meJFHud42DJNIpODDrB2FdLJjDeBy073YrXmWfqQJ31DrYGT3rzyNgzHmg== X-Received: by 2002:ac2:5299:0:b0:4d2:bb83:e7e6 with SMTP id q25-20020ac25299000000b004d2bb83e7e6mr9224708lfm.59.1674811796419; Fri, 27 Jan 2023 01:29:56 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:56 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 10/11] Ext4Pkg: Fixes build on MSVC Date: Fri, 27 Jan 2023 15:29:44 +0600 Message-Id: <20230127092945.94389-11-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811798; bh=P6C7x79RnvJBJRFmoYdNbWnPrP4m7bogcO72f1ESX80=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Q6n3MvDaC1aerDRCT0oiDXUk8fVB/6N8AMwSa40zKTaUkg+5AtUQHngEX6a5OxheuNz 1kRnbrsEPH5oih6DJgRPbbq8u5ovcxRc2hUHmwOuAbPK0rUNvqwAXEyTd+HYoOnZ3A+wx ZuB4TN7xo7lX5M12bZCsBEeMIb8fOLiBy7w= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811798666100033 Content-Type: text/plain; charset="utf-8" Accessing array using index of uint64 type makes MSVC compiler to include `__allmul` function in NOOPT which is not referenced in IA32. So we null-terminates string using ReadSize, which should be equal to SymlinkSizeTmp after correct reading. Also adds missing MultU64x32 in Ext4Read. Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: 7c46116b0e18 ("Ext4Pkg: Add ext2/3 support") Fixes: e81432fbacb7 ("Ext4Pkg: Add symbolic links support") Signed-off-by: Savva Mitrofanov --- Features/Ext4Pkg/Ext4Dxe/Inode.c | 4 ++-- Features/Ext4Pkg/Ext4Dxe/Symlink.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Inode.c b/Features/Ext4Pkg/Ext4Dxe/In= ode.c index 90e3eb88f523..8db051d3c444 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Inode.c +++ b/Features/Ext4Pkg/Ext4Dxe/Inode.c @@ -152,7 +152,7 @@ Ext4Read ( } else { // Uninitialized extents behave exactly the same as file holes, ex= cept they have // blocks already allocated to them. - HoleLen =3D (Ext4GetExtentLength (&Extent) * Partition->BlockSize)= - HoleOff; + HoleLen =3D MultU64x32 (Ext4GetExtentLength (&Extent), Partition->= BlockSize) - HoleOff; } =20 WasRead =3D HoleLen > RemainingRead ? RemainingRead : (UINTN)HoleLen; @@ -166,7 +166,7 @@ Ext4Read ( Partition->BlockSize ); ExtentLengthBytes =3D Extent.ee_len * Partition->BlockSize; - ExtentLogicalBytes =3D (UINT64)Extent.ee_block * Partition->BlockSiz= e; + ExtentLogicalBytes =3D MultU64x32 ((UINT64)Extent.ee_block, Partitio= n->BlockSize); ExtentOffset =3D CurrentSeek - ExtentLogicalBytes; ExtentMayRead =3D (UINTN)(ExtentLengthBytes - ExtentOffset); =20 diff --git a/Features/Ext4Pkg/Ext4Dxe/Symlink.c b/Features/Ext4Pkg/Ext4Dxe/= Symlink.c index 19b357ac6ba0..8b1511a38b55 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Symlink.c +++ b/Features/Ext4Pkg/Ext4Dxe/Symlink.c @@ -1,7 +1,7 @@ /** @file Symbolic links routines =20 - Copyright (c) 2022 Savva Mitrofanov All rights reserved. + Copyright (c) 2022-2023 Savva Mitrofanov All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 @@ -155,11 +155,6 @@ Ext4ReadSlowSymlink ( return Status; } =20 - // - // Add null-terminator - // - SymlinkTmp[SymlinkSizeTmp] =3D '\0'; - if (SymlinkSizeTmp !=3D ReadSize) { DEBUG (( DEBUG_FS, @@ -168,6 +163,11 @@ Ext4ReadSlowSymlink ( return EFI_VOLUME_CORRUPTED; } =20 + // + // Add null-terminator + // + SymlinkTmp[ReadSize] =3D '\0'; + *AsciiSymlinkSize =3D SymlinkAllocateSize; *AsciiSymlink =3D SymlinkTmp; =20 --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99146): https://edk2.groups.io/g/devel/message/99146 Mute This Topic: https://groups.io/mt/96562700/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 19 14:32:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99147+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99147+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1674811799; cv=none; d=zohomail.com; s=zohoarc; b=ge+fm09Y8GUNC22EbyxVowF3zBe2D/gIW3C06ES5GRbLt21KOaLQh50ISX7btNU563yzYbMTeuxU+dWZkivJeEED/fgnEzerzwoBuVI2BazLhGceieI9WyzsOer8Qu0hHedytKgkk+PrXs2MkF7DqhhCg7N8HY5dF7xXtCNl6IQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674811799; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=4uecp6Kg8rcGEkDG2wcsZE5Qy1qQdKOBCB908vEd5RY=; b=md2r3+WOtgTjUbM2gDekjBzJWWFuklrFo6AZyRGlOSZmxguIFgvgQj5OTqU5EKoPIRCTtxVlntAKMs9mqzUXNCWqUqcXF7nJk5ngadykRPNSWDywV4HqJ14ANQj9c594StC6GkJ64xGHCjiNcGOjfM7mCxxqB6KdjLS1MCjABzQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99147+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16748117992431015.3584276358164; Fri, 27 Jan 2023 01:29:59 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4oBcYY1788612xbNBmWYD25K; Fri, 27 Jan 2023 01:29:58 -0800 X-Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by mx.groups.io with SMTP id smtpd.web10.98483.1674811796503971478 for ; Fri, 27 Jan 2023 01:29:58 -0800 X-Received: by mail-lf1-f43.google.com with SMTP id br9so7244308lfb.4 for ; Fri, 27 Jan 2023 01:29:57 -0800 (PST) X-Gm-Message-State: cqEG6xEukMF49gJh72XHjPhux1787277AA= X-Google-Smtp-Source: AK7set+4JKaWx5iKroDE4ssUnMBoTiyWI3RzlAUuIskP2LUKekFcuTRmAZl1lD7mlL6d3pBkm7NZpg== X-Received: by 2002:a05:6512:3986:b0:4d8:57dc:fcdd with SMTP id j6-20020a056512398600b004d857dcfcddmr114281lfu.56.1674811797391; Fri, 27 Jan 2023 01:29:57 -0800 (PST) X-Received: from localhost.localdomain ([176.62.67.29]) by smtp.gmail.com with ESMTPSA id t11-20020a056512068b00b004cc8196a308sm229071lfe.98.2023.01.27.01.29.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 27 Jan 2023 01:29:57 -0800 (PST) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-devel] [edk2-platforms][PATCH v3 11/11] Ext4Pkg: Filter out directory entry names containing \0 as invalid Date: Fri, 27 Jan 2023 15:29:45 +0600 Message-Id: <20230127092945.94389-12-savvamtr@gmail.com> In-Reply-To: <20230127092945.94389-1-savvamtr@gmail.com> References: <20230127092945.94389-1-savvamtr@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,savvamtr@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1674811798; bh=FJCP2YNkeZ5Dd8Io6CVU0i07XDk8A0UDPSYWH8q9p5w=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=W/1qPoEZRhDQkwIPf13BNo2JADfhDGcjevfcoreZAS04znobwMz/g+Hgc/v88fHMxm1 YNGQX1B3xJ3OJFfwuiRdN/zgs7xwpA4ixS2vxvC1ajn102tcifuGQK+dJPPcwEeQGanR6 7Nipcn+XJaldIdzObfrRHpwhXLgmQVlFxZI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1674811800661100042 Content-Type: text/plain; charset="utf-8" The directory entry name conventions forbid having null-terminator symbols in its body and can lead to undefined behavior conditions and crashes Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Fixes: 89b2bb0db263 ("Ext4Pkg: Fix and clarify handling regarding non-utf8 = dir entries") Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user Reviewed-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Directory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dx= e/Directory.c index 0753a20b5377..465749c9b51d 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -28,9 +28,16 @@ Ext4GetUcs2DirentName ( { CHAR8 Utf8NameBuf[EXT4_NAME_MAX + 1]; UINT16 *Str; + UINTN Index; EFI_STATUS Status; =20 - CopyMem (Utf8NameBuf, Entry->name, Entry->name_len); + for (Index =3D 0; Index < Entry->name_len; ++Index) { + if (Entry->name[Index] =3D=3D '\0') { + return EFI_INVALID_PARAMETER; + } + + Utf8NameBuf[Index] =3D Entry->name[Index]; + } =20 Utf8NameBuf[Entry->name_len] =3D '\0'; =20 --=20 2.39.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99147): https://edk2.groups.io/g/devel/message/99147 Mute This Topic: https://groups.io/mt/96562701/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-