From nobody Mon May 6 10:43:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+39345+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39345+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1555756505; cv=none; d=zoho.com; s=zohoarc; b=cXKB86We5+LbuQ/R7FYq5culoh32Yt/CVArADhpLFxxnUurUD1myidQZO/RARvZkX42A/ijXnuFP7n68tVUDyf6TWvjXPwDWEmXaD0aM4oAWyiahPWL+6VxbyRQo1V1AWNJAMnBZM4aErwXeoXAus/2kSevS9JgSNq3ljU2XY9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555756505; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=iGvNnQVLlIKepRsAE5Ejw536cGn4183ccTKXGD/WqXc=; b=kV7I5VKcNYDTUbJSjn//W8sfrFCAnZT9PUVb2Nx0LjWbynFz5imxQwt63tzR6aB0wnQRvDc1WNRQVnpUuWAmlHBp1rz98Oq0XBirZhcIVBS5GwXr/O6PX/AnNCeK8BG3OKmPdP0nTjhIWtEqBjkBULKTv/juAEDYIU67LZj6PP4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+39345+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1555756505242351.1359888987686; Sat, 20 Apr 2019 03:35:05 -0700 (PDT) Return-Path: X-Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by groups.io with SMTP; Sat, 20 Apr 2019 03:35:04 -0700 X-Received: by mail-wm1-f68.google.com with SMTP id o25so8728871wmf.5 for ; Sat, 20 Apr 2019 03:35:03 -0700 (PDT) X-Gm-Message-State: APjAAAUN17kNGInwViVrDq0T3ROpMBklkQTgDR9Ut52+Zq4ITlo5sb8j 8qO5e9A7RR3/DNydxGO/mKIv/74TK4it3Q== X-Google-Smtp-Source: APXvYqyx+z0ZVNK6ksUwOKzevJJrrb5R7got2M8RjYRGeOQqjVrp0KOtQVcAFeKLkW1yZWX+OmBRJQ== X-Received: by 2002:a1c:a7c5:: with SMTP id q188mr5524444wme.126.1555756501681; Sat, 20 Apr 2019 03:35:01 -0700 (PDT) X-Received: from sudo.home ([2a01:cb1d:112:6f00:1c50:92b:8c96:bc6e]) by smtp.gmail.com with ESMTPSA id r18sm12109583wme.18.2019.04.20.03.35.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Apr 2019 03:35:00 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: hao.a.wu@intel.com, jian.j.wang@intel.com, michael.d.kinney@intel.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v2] MdeModulePkg/DxeCapsuleLibFmp: avoid ESRT accesses at runtime Date: Sat, 20 Apr 2019 12:34:54 +0200 Message-Id: <20190420103454.5148-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ard.biesheuvel@linaro.org Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1555756504; bh=2/tVH4Rao56NYmUJKxQLWcjr/U5igG11VcBOOFeAHF0=; h=Cc:Date:From:Reply-To:Subject:To; b=Kzrsh4ppB+f2axgQipmrGnB9Nj9KgLY5pLbrW/CQycvA5wNTYKKNdSWo3mOfk/WIHDv Rd/LB7Bg0vZ5CPJCE5+FwRB12YsT4LA5cpUfc2D7C9GyaI+EWcYfR6k7YChTGHvWyl+E0 wyvZ8NX7XzTiI8bKDoP7n4H7UpP1s/DNl/0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The DxeCapsuleLibFmp code accesses the ESRT table to decide whether a certain capsule is an FMP capsule. Since the UEFI spec mandates that the ESRT resides in EfiBootServicesData memory, this results in problems at OS runtime, since the firmware implementation itself cannot access memory that has not been virtually remapped. So let's take a private copy of the ESRT at ReadyToBoot, and store it in EfiRuntimeServicesData memory. The ESRT's size is order 10s of bytes so the memory footprint is going to be negligigble. Signed-off-by: Ard Biesheuvel Acked-by: Hao Wu Reviewed-by: Michael D Kinney --- v2: copy the whole table instead of just the list of GUIDs Still build tested only. MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c | 58 ++++++= ++++++++++---- MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf | 1 + 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c b/Md= eModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c index 602921d13c06..9e0327afb53b 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c @@ -23,6 +23,7 @@ extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable; extern BOOLEAN mIsVirtualAddrConverted; EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = =3D NULL; +EFI_EVENT mDxeRuntimeCapsuleLibReadyToBootEvent =3D NULL; =20 /** Convert EsrtTable physical address to virtual address. @@ -38,8 +39,28 @@ DxeCapsuleLibVirtualAddressChangeEvent ( IN VOID *Context ) { - UINTN Index; - EFI_CONFIGURATION_TABLE *ConfigEntry; + gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable); + mIsVirtualAddrConverted =3D TRUE; +} + +/** + Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +STATIC +VOID +EFIAPI +DxeCapsuleLibReadyToBootEventNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + UINTN Index; + EFI_CONFIGURATION_TABLE *ConfigEntry; + EFI_SYSTEM_RESOURCE_TABLE *EsrtTable; =20 // // Get Esrt table first @@ -59,16 +80,14 @@ DxeCapsuleLibVirtualAddressChangeEvent ( // // Search Esrt to check given capsule is qualified // - mEsrtTable =3D (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable; + EsrtTable =3D (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable; =20 - // - // Update protocol pointer to Esrt Table. - // - gRT->ConvertPointer (0x00, (VOID**) &(mEsrtTable)); + mEsrtTable =3D AllocateRuntimeCopyPool ( + sizeof (EFI_SYSTEM_RESOURCE_TABLE) + + EsrtTable->FwResourceCount * sizeof (EFI_SYSTEM_RESOURC= E_ENTRY), + EsrtTable); + ASSERT (mEsrtTable !=3D NULL); } - - mIsVirtualAddrConverted =3D TRUE; - } =20 /** @@ -101,6 +120,19 @@ DxeRuntimeCapsuleLibConstructor ( ); ASSERT_EFI_ERROR (Status); =20 + // + // Register notify function to cache the FMP capsule GUIDs at ReadyToBoo= t. + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + DxeCapsuleLibReadyToBootEventNotify, + NULL, + &gEfiEventReadyToBootGuid, + &mDxeRuntimeCapsuleLibReadyToBootEvent + ); + ASSERT_EFI_ERROR (Status); + return EFI_SUCCESS; } =20 @@ -127,5 +159,11 @@ DxeRuntimeCapsuleLibDestructor ( Status =3D gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEve= nt); ASSERT_EFI_ERROR (Status); =20 + // + // Close the ReadyToBoot event. + // + Status =3D gBS->CloseEvent (mDxeRuntimeCapsuleLibReadyToBootEvent); + ASSERT_EFI_ERROR (Status); + return EFI_SUCCESS; } diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf= b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf index 700d0d5dcddd..2c93e6870023 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf @@ -66,6 +66,7 @@ gEfiCapsuleReportGuid gEfiCapsuleVendorGuid ## SOMETIMES_CONSUMES ## Variabl= e:L"CapsuleUpdateData" gEfiEndOfDxeEventGroupGuid ## CONSUMES ## Event + gEfiEventReadyToBootGuid ## CONSUMES ## Event gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event =20 [Depex] --=20 2.20.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 (#39345): https://edk2.groups.io/g/devel/message/39345 Mute This Topic: https://groups.io/mt/31254157/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-