From nobody Sun Feb 8 20:52:35 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+109411+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+109411+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1696810080; cv=none; d=zohomail.com; s=zohoarc; b=e2ewBClqVsyUk8W9PMAzcnFw6JDjoN6WIQyD/agE/36PZ+O+fNGaNlrb0JBT3VtB42ziPF0mWDXRlHCVWgBbRLvwHGDuS9fGbTZlIX7zG8HZzwen8FhF+2Ep/+kvXV9cSuVnsT+JFdskXEBqXP6PNPSB1w+jL0uOF3FRvanKt34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696810080; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=lauFYX89plH+CEHknR5PjYYju3gxC5UXmIGl8AMMlpo=; b=jA/+nflW9TCoCrs6g67yONta8JUkS1jf1qfhSK2iaRd2tXCbVMJ7YdB8lN+DnuaI+dpK9/OasO1W55S5MhGXQC3Al8ktrb9vB9bQYZ3b0U84EK7p+Zfy43QIWPbozFit5QIY0q4AJHdQLqaFazqRHJIhDpwsTRKUDFq9I63j9II= 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+109411+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 1696810080119653.8477006416366; Sun, 8 Oct 2023 17:08:00 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=hT1NNutESIkLwX0/SNVUDFFDyw0CGubccoC6MtJmEXM=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1696810079; v=1; b=G+dJLVCmsUjirRpUFHcgWlDf6AC15TqOD3C6MkqTXYkP9DCiOXNdcs32cINtRPdYN8h6sUbe z7VzbR5dcI0UmGdk7ORmy0omubHYQvrNTJdy7p2Vmo/iNMU6bOs3dDzjhxyhUIlUh8FeMz/1Xjb oOEpIKS8YM4j4A20LCM3Hcvs= X-Received: by 127.0.0.2 with SMTP id gzhxYY1788612xr2GG7KGmjQ; Sun, 08 Oct 2023 17:07:59 -0700 X-Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) by mx.groups.io with SMTP id smtpd.web10.50214.1696810079110814199 for ; Sun, 08 Oct 2023 17:07:59 -0700 X-Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6c646b5028dso2698345a34.3 for ; Sun, 08 Oct 2023 17:07:59 -0700 (PDT) X-Gm-Message-State: jU69BhMxaYpd16pAgDN0Fq73x1787277AA= X-Google-Smtp-Source: AGHT+IFiR7dXGneFwb1vM/YXahLxA2a60nnPYNhk9SgX+R4OqJPqBkmKnb2kCuo6IWeJx6opJ62tkA== X-Received: by 2002:a05:6871:70e:b0:1a6:b183:b0ab with SMTP id f14-20020a056871070e00b001a6b183b0abmr17614190oap.40.1696810078276; Sun, 08 Oct 2023 17:07:58 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id t20-20020a62ea14000000b0068fcc7f6b00sm5048320pfh.74.2023.10.08.17.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 17:07:57 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Dandan Bi Subject: [edk2-devel] [PATCH v5 06/28] MdeModulePkg: Apply Protections to the HOB List Date: Sun, 8 Oct 2023 17:07:18 -0700 Message-ID: <20231009000742.1792-7-taylor.d.beebe@gmail.com> In-Reply-To: <20231009000742.1792-1-taylor.d.beebe@gmail.com> References: <20231009000742.1792-1-taylor.d.beebe@gmail.com> MIME-Version: 1.0 Precedence: Bulk 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,taylor.d.beebe@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1696810082282100029 Content-Type: text/plain; charset="utf-8" Because the platform memory protection settings will be stored in the HOB, the HOB list should be marked read-only and non-executable as soon as possible in boot. This patch page-aligns the allocated HOB list in DXE and marks it RO/NX during memory protection initialization. Signed-off-by: Taylor Beebe Cc: Jian J Wang Cc: Liming Gao Cc: Dandan Bi Acked-by: Laszlo Ersek --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 18 ++++++------ MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 29 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gc= d.c index 792cd2e0af23..72bd036eab1e 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -2764,21 +2764,21 @@ CoreInitializeGcdServices ( } =20 // - // Relocate HOB List to an allocated pool buffer. + // Relocate HOB List to allocated pages. // The relocation should be at after all the tested memory resources add= ed // (except the memory space that covers HOB List) to the memory services, // because the memory resource found in CoreInitializeMemoryServices() // may have not enough remaining resource for HOB List. // - NewHobList =3D AllocateCopyPool ( - (UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart), - *HobStart - ); - ASSERT (NewHobList !=3D NULL); - - *HobStart =3D NewHobList; - gHobList =3D NewHobList; + NewHobList =3D AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PhitHob->EfiFree= MemoryBottom - (UINTN)(*HobStart))); + if (NewHobList !=3D NULL) { + CopyMem (NewHobList, *HobStart, (UINTN)PhitHob->EfiFreeMemoryBottom - = (UINTN)(*HobStart)); + *HobStart =3D NewHobList; + } else { + ASSERT (NewHobList !=3D NULL); + } =20 + gHobList =3D *HobStart; if (MemorySpaceMapHobList !=3D NULL) { // // Add and allocate the memory space that covers HOB List to the memor= y services diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index 7cc829b17402..94ed3111688b 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -967,6 +967,32 @@ InitializeDxeNxMemoryProtectionPolicy ( } } =20 +/** + Mark the HOB list as read-only and non-executable. +**/ +STATIC +VOID +ProtectHobList ( + VOID + ) +{ + EFI_PEI_HOB_POINTERS Hob; + + Hob.Raw =3D GetHobList (); + + // Find the end of the HOB list. + while (!END_OF_HOB_LIST (Hob)) { + Hob.Raw =3D GET_NEXT_HOB (Hob); + } + + // Protect the HOB list. + SetUefiImageMemoryAttributes ( + (UINTN)gHobList, + ALIGN_VALUE (((UINTN)Hob.Raw + GET_HOB_LENGTH (Hob)) - (UINTN)GetHobLi= st (), EFI_PAGE_SIZE), + EFI_MEMORY_XP | EFI_MEMORY_RO + ); +} + /** A notification for CPU_ARCH protocol. =20 @@ -1007,6 +1033,9 @@ MemoryProtectionCpuArchProtocolNotify ( // HeapGuardCpuArchProtocolNotify (); =20 + // Mark the HOB list XP and RO. + ProtectHobList (); + if (mImageProtectionPolicy =3D=3D 0) { goto Done; } --=20 2.42.0.windows.2 -=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 (#109411): https://edk2.groups.io/g/devel/message/109411 Mute This Topic: https://groups.io/mt/101843347/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-