From nobody Sat Feb 7 07:10:38 2026 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-