From nobody Sat Nov 2 16:28:30 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 14882063090171.3921504751509701; Mon, 27 Feb 2017 06:38:29 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EB8CD82027; Mon, 27 Feb 2017 06:38:27 -0800 (PST) Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com [IPv6:2a00:1450:400c:c09::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B983282027 for ; Mon, 27 Feb 2017 06:38:25 -0800 (PST) Received: by mail-wm0-x22f.google.com with SMTP id u199so20322674wmd.1 for ; Mon, 27 Feb 2017 06:38:25 -0800 (PST) Received: from localhost.localdomain ([105.149.201.216]) by smtp.gmail.com with ESMTPSA id z134sm14475167wmc.20.2017.02.27.06.38.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Feb 2017 06:38:23 -0800 (PST) X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iLx+xDseTqp8U73TljZHW6dZA5m+LgKqMo5zaY1D41s=; b=FUXNWntsyLR3rmAivXR4ExJc8HjBBPIgmNAnMN1+WtpJKaHqvjcpaz7CpwBruFa8hd L9CA2oDWqz0Fs0qAZcNR/Zti8Anjt6g09ZNnnzZ6h142+eXO2yBMmYoclQilBM2pxoSM 2Bgd3HtoRukD+jPC9iPhY/AhF6LGSkgCYezBU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iLx+xDseTqp8U73TljZHW6dZA5m+LgKqMo5zaY1D41s=; b=KnwWjaB4T3Wq/MT3C6g9xeEjvDJ8toJBRrAmsnr63l/vMtBSzRU77Ar7opvNBNJwS8 +hQa31YciQuZOwXvbvxd8Jb4nID8sxUZ+kIZJLBtvEGwiaZzmQKjNAtN1+J3x0dPiBMN wiStcmb2cfnK8g0l9vghSS0dd5J2SGDLuYuigN0C34V4mAaA0CqsE4aLVHFcogyNUlH7 IpLLEchxn/fy26byia9e/2KhWDwPQZUo/NZ2dNw32SwgOpED5KKZna6XdP66msG1aO6X 1V24s5XWuQ3bsI4aYqIL28DZBlWF6VlgIy9/XhwO0teelOzL7LaXRancjbwLRwJCJ79Z WSkg== X-Gm-Message-State: AMke39ngs0m3Wq7hscvbCs5YnndNayvDZYj0SnW+0U2dv44SCDHjIF/cINZo9B+ZHU3KHNl8 X-Received: by 10.28.145.3 with SMTP id t3mr14435406wmd.47.1488206304377; Mon, 27 Feb 2017 06:38:24 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, afish@apple.com, leif.lindholm@linaro.org, michael.d.kinney@intel.com, liming.gao@intel.com, jiewen.yao@intel.com Date: Mon, 27 Feb 2017 14:38:06 +0000 Message-Id: <1488206291-25768-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488206291-25768-1-git-send-email-ard.biesheuvel@linaro.org> References: <1488206291-25768-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v4 2/7] MdeModulePkg/PeiCore: allocate BootServicesCode memory for PE/COFF images X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: feng.tian@intel.com, lersek@redhat.com, star.zeng@intel.com, Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Ensure that any memory allocated for PE/COFF images is identifiable as a boot services code region, so that we know it requires its executable permissions to be preserved when we tighten mapping permissions later on. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reviewed-by: Jiewen Yao Reviewed-by: Liming Gao --- MdeModulePkg/Core/Pei/Image/Image.c | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Im= age/Image.c index d659de8b3e64..68e40c027e63 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -112,11 +112,12 @@ GetImageReadFunction ( IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { - PEI_CORE_INSTANCE *Private; - VOID* MemoryBuffer; + PEI_CORE_INSTANCE *Private; + EFI_PHYSICAL_ADDRESS MemoryBuffer; =20 Private =3D PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer (= )); - =20 + MemoryBuffer =3D 0; + if (Private->PeiMemoryInstalled && (((Private->HobList.HandoffInformati= onTable->BootMode !=3D BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnBoo= t)) ||=20 ((Private->HobList.HandoffInformationTable->BootMode =3D=3D BOOT_ON_= S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot))) && (EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_X64) || EFI_IMAG= E_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_IA32))) { @@ -125,9 +126,9 @@ GetImageReadFunction ( // compilers that have been tested // if (Private->ShadowedImageRead =3D=3D NULL) { - MemoryBuffer =3D AllocatePages (0x400 / EFI_PAGE_SIZE + 1); - ASSERT (MemoryBuffer !=3D NULL); - CopyMem (MemoryBuffer, (CONST VOID *) (UINTN) PeiImageReadForShadow,= 0x400); + PeiServicesAllocatePages (EfiBootServicesCode, 0x400 / EFI_PAGE_SIZE= + 1, &MemoryBuffer); + ASSERT (MemoryBuffer !=3D 0); + CopyMem ((VOID *)(UINTN)MemoryBuffer, (CONST VOID *) (UINTN) PeiImag= eReadForShadow, 0x400); Private->ShadowedImageRead =3D (PE_COFF_LOADER_READ_FILE) (UINTN) Me= moryBuffer; } =20 @@ -453,12 +454,16 @@ LoadAndRelocatePeCoffImage ( // // The PEIM is not assiged valid address, try to allocate page to = load it. // - ImageContext.ImageAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN) Alloca= tePages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize)); + Status =3D PeiServicesAllocatePages (EfiBootServicesCode, + EFI_SIZE_TO_PAGES ((UINT32) Ali= gnImageSize), + &ImageContext.ImageAddress); } } else { - ImageContext.ImageAddress =3D (EFI_PHYSICAL_ADDRESS)(UINTN) Allocate= Pages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize)); + Status =3D PeiServicesAllocatePages (EfiBootServicesCode, + EFI_SIZE_TO_PAGES ((UINT32) Align= ImageSize), + &ImageContext.ImageAddress); } - if (ImageContext.ImageAddress !=3D 0) { + if (!EFI_ERROR (Status)) { // // Adjust the Image Address to make sure it is section alignment. // --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel