From nobody Fri Mar 14 05:43:41 2025 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+101124+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+101124+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1678727908; cv=none; d=zohomail.com; s=zohoarc; b=MknpnrsvBOv3xLMesM03dBSvDjNPoC5iZ/oGqt8CQmnBxBHvywRp7FdesNxNoKKL/836C3A6HH9uCVW4JVH/YtCor0xDzxk5XjMqhlla90ggsusJpqgW/Gk/Fb4mgQdVB9NB1+cYBkuTQ7Axbg4crH5kf2pbhIQxpeI87AcA6tQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678727908; h=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=69NbtLUA8FQjdC/cXy2+oUzUw2PRLaSHKiQOGUAbtQA=; b=SwQcF9PAgkONRRhUaMeU+7EMOWwhIG5NNqrEXW1cBQM9q2H29vSG7xYW0Ast9GBJBMwvdTpLZMuK8cNOtFrDr7SHTy6ItmnzR4ABjB7GLGuq7SlbupdK5H8HSxo+Vmh1P9qzhMMRsgFzPw0EEUP5preTcdKIQbwaI8G4Qq00ImM= 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+101124+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 1678727908364422.2072183479306; Mon, 13 Mar 2023 10:18:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PDSoYY1788612x9Cfwele25f; Mon, 13 Mar 2023 10:18:28 -0700 X-Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mx.groups.io with SMTP id smtpd.web11.26498.1678727907526273415 for ; Mon, 13 Mar 2023 10:18:27 -0700 X-Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 12D9B61314; Mon, 13 Mar 2023 17:18:27 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 474EAC433EF; Mon, 13 Mar 2023 17:18:24 +0000 (UTC) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Michael Kinney , Liming Gao , Jiewen Yao , Michael Kubacki , Sean Brogan , Rebecca Cran , Leif Lindholm , Sami Mujawar , Taylor Beebe Subject: [edk2-devel] [PATCH v5 20/38] MdeModulePkg/DxeCore: Permit preliminary CPU arch fallback Date: Mon, 13 Mar 2023 18:16:56 +0100 Message-Id: <20230313171714.3866151-21-ardb@kernel.org> In-Reply-To: <20230313171714.3866151-1-ardb@kernel.org> References: <20230313171714.3866151-1-ardb@kernel.org> 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,ardb@kernel.org X-Gm-Message-State: 6yT0U5Iw53cahpxXJvAfJRnxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678727908; bh=iHvj5PWBQSChg8D9xMI1N0mphZPuqbs63b6rFrMSPu0=; h=Cc:Date:From:Reply-To:Subject:To; b=clVffIjqxgAmOVLyKRQPs5KWmnJQEfubAbjJ6Oc7jW+kqcCuF+u3n99HYx+tTDLWVOp SOO6bTvLrZHYuQx9i0nBo7PaBB8dFV8K4EgfOMqsDtdLvOvsQljrX4Q0pCP71cn9v/gHO KlHjztjisPDm/VbbDJM1Oow9y/kB/IwfsJE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678727910169100009 Content-Type: text/plain; charset="utf-8" Store the address of the SetMemoryAttributes() member of the CPU arch protocol in a global variable, and invoke it via this variable. This by itself should have not result in functional changes, but it permits platforms to provide an preliminary implementation of this member at link time, allowing the DXE core to enforce strict memory permissions even before dispatching the CPU arch protocol driver itself. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/C= ore/Dxe/Misc/MemoryProtection.c index 3e6f2b4e74cc..8df3e881c5c4 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -66,6 +66,8 @@ extern LIST_ENTRY mGcdMemorySpaceMap; =20 STATIC LIST_ENTRY mProtectedImageRecordList; =20 +EFI_CPU_SET_MEMORY_ATTRIBUTES gCpuSetMemoryAttributes; + /** Sort code section in image record, based upon CodeSegmentBase from low t= o high. =20 @@ -224,8 +226,8 @@ SetUefiImageMemoryAttributes ( =20 DEBUG ((DEBUG_INFO, "SetUefiImageMemoryAttributes - 0x%016lx - 0x%016lx = (0x%016lx)\n", BaseAddress, Length, FinalAttributes)); =20 - ASSERT (gCpu !=3D NULL); - gCpu->SetMemoryAttributes (gCpu, BaseAddress, Length, FinalAttributes); + ASSERT (gCpuSetMemoryAttributes !=3D NULL); + gCpuSetMemoryAttributes (gCpu, BaseAddress, Length, FinalAttributes); } =20 /** @@ -408,7 +410,7 @@ ProtectUefiImage ( DEBUG ((DEBUG_INFO, "ProtectUefiImageCommon - 0x%x\n", LoadedImage)); DEBUG ((DEBUG_INFO, " - 0x%016lx - 0x%016lx\n", (EFI_PHYSICAL_ADDRESS)(= UINTN)LoadedImage->ImageBase, LoadedImage->ImageSize)); =20 - if (gCpu =3D=3D NULL) { + if (gCpuSetMemoryAttributes =3D=3D NULL) { return; } =20 @@ -995,6 +997,8 @@ MemoryProtectionCpuArchProtocolNotify ( goto Done; } =20 + gCpuSetMemoryAttributes =3D gCpu->SetMemoryAttributes; + // // Apply the memory protection policy on non-BScode/RTcode regions. // @@ -1278,7 +1282,7 @@ ApplyMemoryProtectionPolicy ( // permission attributes, and it is the job of the driver that installs = this // protocol to set the permissions on existing allocations. // - if (gCpu =3D=3D NULL) { + if (gCpuSetMemoryAttributes =3D=3D NULL) { return EFI_SUCCESS; } =20 @@ -1318,5 +1322,5 @@ ApplyMemoryProtectionPolicy ( // NewAttributes =3D GetPermissionAttributeForMemoryType (NewType); =20 - return gCpu->SetMemoryAttributes (gCpu, Memory, Length, NewAttributes); + return gCpuSetMemoryAttributes (gCpu, Memory, Length, NewAttributes); } --=20 2.39.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 (#101124): https://edk2.groups.io/g/devel/message/101124 Mute This Topic: https://groups.io/mt/97586023/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-