From nobody Tue Feb 10 00:24:01 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+78949+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+78949+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=posteo.de ARC-Seal: i=1; a=rsa-sha256; t=1628502724; cv=none; d=zohomail.com; s=zohoarc; b=fkuXNMDwLJ1PJHlWp0gOaj/rVMtGr19ezzJfYG9a4IgAYB4z4UYRPMIEq4//Ff+cLBiChbA19gtuIOuFRykFsG9Zc7NI+ogIiheVDvoCN3KMjV+CYgx7BrScOl82E2d+2jgtWzQ6BaqMf/X4KlGbATWRT0qvfkpdYseS1IAik2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628502724; 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=WIKsPSbOIaeZbAElFisUb6rpofpRHwIM7EpksVlM/+I=; b=I9UpJdGDY3nr3f5hc/NICC33cboFB0mGk7nPUAxUg21xHfSVZxe91X6CpwfILGn3mYGAE8WTSf6N29Z9buVeXf2TuLbpxSsKeUoHL+YKAWnENkrd4GiwhbTRm5v44Raw1+SNj88XnUq6k0Bm8r/tn6Wz48t12di0CZW2unFlpKk= 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+78949+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 1628502724810389.20533194030736; Mon, 9 Aug 2021 02:52:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id GXcfYY1788612xkoQ8E7JumH; Mon, 09 Aug 2021 02:52:04 -0700 X-Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) by mx.groups.io with SMTP id smtpd.web10.20765.1628502718075804511 for ; Mon, 09 Aug 2021 02:51:58 -0700 X-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 8AF0024002A for ; Mon, 9 Aug 2021 11:51:50 +0200 (CEST) X-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Gjrvn6MlCz6tmG; Mon, 9 Aug 2021 11:51:49 +0200 (CEST) From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Dandan Bi , Liming Gao , Vitaly Cheptsov Subject: [edk2-devel] [PATCH v2 1/7] MdeModulePkg/DxeCore: Consistent DebugImageInfoTable updates Date: Mon, 9 Aug 2021 09:51:21 +0000 Message-Id: <88816e99692b15cf61f3057ffab4d54455159c7c.1628502345.git.mhaeuser@posteo.de> In-Reply-To: References: 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,mhaeuser@posteo.de X-Gm-Message-State: aKpdPNTelKNsVbLBa2SmArAix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1628502724; bh=rLBFpKRid8PQsPXzUfNRsGGVQ3vkiZOI83og8JvsNbE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=R4WqjmkYwNkKqeZj1t3ks8RdhJchFYBK15JU6EqKth57PRvAIrPUKsLGcPi6cJLb2cU bqG4KW7Sm8aayoU+FDMK4x67EQoKL/IThxIEtgOJHyKnPDiHYsjn9G/wuIb9XMPmd7p6Y gpw62tw5dFG93nYpcpwJUlfSTXTPlFCMfRA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1628502726973100055 Content-Type: text/plain; charset="utf-8" In theory, modifications to the DebugImageInfoTable may cause exceptions. If the exception handler parses the table, this can lead to subsequent exceptions if the table state is inconsistent. Ensure the DebugImageInfoTable remains consistent during modifications. This includes: 1) Free the old table only only after the new table has been published. Mitigates use-after-free of the old table. 2) Do not insert an image entry till it is fully initialised. Entries may be inserted in the live range if an entry was deleted previously. Mitigaes the usage of inconsistent entries. 3) Free the old image entry only after the table has been updated with the NULL value. Mitigates use-after-free of the old entry. 4) Set the MODIFIED state before performing any modifications. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Cc: Vitaly Cheptsov Signed-off-by: Marvin H=C3=A4user --- MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c | 60 +++++++++++--------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c b/MdeModulePkg/Cor= e/Dxe/Misc/DebugImageInfo.c index a75d4158280b..7bd970115111 100644 --- a/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c +++ b/MdeModulePkg/Core/Dxe/Misc/DebugImageInfo.c @@ -165,10 +165,11 @@ CoreNewDebugImageInfoEntry ( IN EFI_HANDLE ImageHandle ) { - EFI_DEBUG_IMAGE_INFO *Table; - EFI_DEBUG_IMAGE_INFO *NewTable; - UINTN Index; - UINTN TableSize; + EFI_DEBUG_IMAGE_INFO *Table; + EFI_DEBUG_IMAGE_INFO *NewTable; + UINTN Index; + UINTN TableSize; + EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage; =20 // // Set the flag indicating that we're in the process of updating the tab= le. @@ -203,14 +204,6 @@ CoreNewDebugImageInfoEntry ( // Copy the old table into the new one // CopyMem (NewTable, Table, TableSize); - // - // Free the old table - // - CoreFreePool (Table); - // - // Update the table header - // - Table =3D NewTable; mDebugInfoTableHeader.EfiDebugImageInfoTable =3D NewTable; // // Enlarge the max table entries and set the first empty entry index to @@ -218,24 +211,34 @@ CoreNewDebugImageInfoEntry ( // Index =3D mMaxTableEntries; mMaxTableEntries +=3D EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE; + // + // Free the old table + // + CoreFreePool (Table); + // + // Update the table header + // + Table =3D NewTable; } =20 // // Allocate data for new entry // - Table[Index].NormalImage =3D AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_I= NFO_NORMAL)); - if (Table[Index].NormalImage !=3D NULL) { + NormalImage =3D AllocateZeroPool (sizeof (EFI_DEBUG_IMAGE_INFO_NORMAL)); + if (NormalImage !=3D NULL) { // // Update the entry // - Table[Index].NormalImage->ImageInfoType =3D (UINT32) Ima= geInfoType; - Table[Index].NormalImage->LoadedImageProtocolInstance =3D LoadedImage; - Table[Index].NormalImage->ImageHandle =3D ImageHandle; + NormalImage->ImageInfoType =3D (UINT32) ImageInfoType; + NormalImage->LoadedImageProtocolInstance =3D LoadedImage; + NormalImage->ImageHandle =3D ImageHandle; // - // Increase the number of EFI_DEBUG_IMAGE_INFO elements and set the mD= ebugInfoTable in modified status. + // Set the mDebugInfoTable in modified status, insert the entry, and + // increase the number of EFI_DEBUG_IMAGE_INFO elements. // - mDebugInfoTableHeader.TableSize++; mDebugInfoTableHeader.UpdateStatus |=3D EFI_DEBUG_IMAGE_INFO_TABLE_MOD= IFIED; + Table[Index].NormalImage =3D NormalImage; + mDebugInfoTableHeader.TableSize++; } mDebugInfoTableHeader.UpdateStatus &=3D ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_= PROGRESS; } @@ -253,8 +256,9 @@ CoreRemoveDebugImageInfoEntry ( EFI_HANDLE ImageHandle ) { - EFI_DEBUG_IMAGE_INFO *Table; - UINTN Index; + EFI_DEBUG_IMAGE_INFO *Table; + UINTN Index; + EFI_DEBUG_IMAGE_INFO_NORMAL *NormalImage; =20 mDebugInfoTableHeader.UpdateStatus |=3D EFI_DEBUG_IMAGE_INFO_UPDATE_IN_P= ROGRESS; =20 @@ -263,16 +267,20 @@ CoreRemoveDebugImageInfoEntry ( for (Index =3D 0; Index < mMaxTableEntries; Index++) { if (Table[Index].NormalImage !=3D NULL && Table[Index].NormalImage->Im= ageHandle =3D=3D ImageHandle) { // - // Found a match. Free up the record, then NULL the pointer to indic= ate the slot - // is free. + // Found a match. Set the mDebugInfoTable in modified status and NUL= L the + // pointer to indicate the slot is free and. // - CoreFreePool (Table[Index].NormalImage); + NormalImage =3D Table[Index].NormalImage; + mDebugInfoTableHeader.UpdateStatus |=3D EFI_DEBUG_IMAGE_INFO_TABLE_M= ODIFIED; Table[Index].NormalImage =3D NULL; // - // Decrease the number of EFI_DEBUG_IMAGE_INFO elements and set the = mDebugInfoTable in modified status. + // Decrease the number of EFI_DEBUG_IMAGE_INFO elements. // mDebugInfoTableHeader.TableSize--; - mDebugInfoTableHeader.UpdateStatus |=3D EFI_DEBUG_IMAGE_INFO_TABLE_M= ODIFIED; + // + // Free up the record. + // + CoreFreePool (NormalImage); break; } } --=20 2.31.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 (#78949): https://edk2.groups.io/g/devel/message/78949 Mute This Topic: https://groups.io/mt/84764914/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-