From nobody Mon Feb 9 03:13:40 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+97261+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+97261+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1670856422; cv=none; d=zohomail.com; s=zohoarc; b=lVP33eguzUDub6QX93a+vpu6VoYJz6X6BdF9oj+V7gzQhjfmC5qyI9rvZ5RUEQWqJC18BXw9mEa0sjMeF5Sbe1Sf1ZeXkpxzse/aKyfaxYY2/9mAP6395bYepiEQNyP5eLvxOcLdiStbG5e/Mpmi6hkTmTCJA16VqID904LA/k4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670856422; 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=OPWrRdd4A9HLauWmB9TGEfsii2pghxCO8/+PV16DIkQ=; b=a5Jctiv4qndweIeH5s5YWK9B4m0pp7nLRTyg3CfFSU/FTu0dlNSur6b5P2zkvz9fhfbBUUyGhV+TF2NPLNBOP1RnPK0QHyVXoQXEP3L7caqU+ZLh+Yfw1+KyI694a23MI9HxmPv8PTuU4/f5s9haRAO9KDjMyg6g+NhyDMdR2k8= 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+97261+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 16708564226281002.4803870003522; Mon, 12 Dec 2022 06:47:02 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id urT1YY1788612x9OrVO1RB87; Mon, 12 Dec 2022 06:47:02 -0800 X-Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by mx.groups.io with SMTP id smtpd.web11.44999.1670856421448535571 for ; Mon, 12 Dec 2022 06:47:01 -0800 X-Received: by mail-lf1-f46.google.com with SMTP id y25so18965157lfa.9 for ; Mon, 12 Dec 2022 06:47:01 -0800 (PST) X-Gm-Message-State: nGtIdKer1EQWiGrwHxYiUJJex1787277AA= X-Google-Smtp-Source: AA0mqf4U4GN6DLJory1fLLND67zvo1IOskTv2DKy8AMwlVxuIdRox0LcQdLOyBj4Bf9IcPmwjBpEQg== X-Received: by 2002:a05:6512:3115:b0:4b5:6950:bbb2 with SMTP id n21-20020a056512311500b004b56950bbb2mr3813647lfb.66.1670856419511; Mon, 12 Dec 2022 06:46:59 -0800 (PST) X-Received: from localhost.localdomain ([77.221.215.144]) by smtp.gmail.com with ESMTPSA id t4-20020a056512030400b0049c29292250sm1643313lfp.149.2022.12.12.06.46.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 06:46:59 -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 v2 01/11] Ext4Pkg: Fix memory leak in Ext4RetrieveDirent Date: Mon, 12 Dec 2022 20:46:44 +0600 Message-Id: <20221212144654.2650-2-savvamtr@gmail.com> In-Reply-To: <20221212144654.2650-1-savvamtr@gmail.com> References: <20221212144654.2650-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=1670856422; bh=3dmnzuOaB919dEnezZbHy73DwoGhbSv2UtcBIK3ktwU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=b0/HrE0oinGfB3ice5yHfzmzomIJoLF+cp16CNt63U+Qpap5fwh+etZfqWBDztxe83H KCzQuJaoKHi9v3PvUskj/uSqxjlqsDQ8zRh1eBGPyvNwWa0mxK+8zk47xSOGxNcVRNhTe C5PtlQHezdCVpz2jXfGyGPkj8T/oWNVLcvI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1670856424191100005 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: e55f0527dde48a5f139c1b8f35acc4e6b59dd794 Signed-off-by: Savva Mitrofanov --- 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 4441e6d192b6..8b8fce568e43 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -112,8 +112,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; @@ -127,7 +126,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) { @@ -136,8 +136,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; ) { @@ -145,19 +144,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 @@ -186,8 +185,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; @@ -196,8 +195,11 @@ Ext4RetrieveDirent ( Off +=3D Partition->BlockSize; } =20 + Status =3D EFI_NOT_FOUND; + +Out: FreePool (Buf); - return EFI_NOT_FOUND; + return Status; } =20 /** --=20 2.38.1 -=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 (#97261): https://edk2.groups.io/g/devel/message/97261 Mute This Topic: https://groups.io/mt/95622329/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-