From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x22b.google.com (mail-wm0-x22b.google.com [IPv6:2a00:1450:400c:c09::22b]) (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 50B7F82161 for ; Fri, 24 Feb 2017 07:05:12 -0800 (PST) Received: by mail-wm0-x22b.google.com with SMTP id v186so16712548wmd.0 for ; Fri, 24 Feb 2017 07:05:12 -0800 (PST) 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=bo3RDMGP0os0yZ1FCiCOmHWWahEhdZ9oNlsN0M4viw4=; b=j76Qu0Gs7FVAhEuP0qLOMqqoQuZEMNwiby5eZ+2+XRECJqvKHGgbpPNpHF/9JVImkF WfFbeqRBRfSed0FP2DAd4d0FS6thTmdFZJCtl4wVlP7o6LA5hs75yjixdk5j7XfNh/Ua MHz9SkUlV4eXhsWT+uA9YZ5xomvcCA/T0no2I= 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=bo3RDMGP0os0yZ1FCiCOmHWWahEhdZ9oNlsN0M4viw4=; b=DU0mcLgoPJWNl36pHXPNS0/JvQdw7JpN2GnBW9lpD5n1l0zs0PJx6A4A6ps+uAz+0z NoorQhL0Z/9gpcDolk2dTMfx7gOh0UfaYBGNo9MySLA7x9xibOc3xz7j/bGSEjwmTzPi sMx6zlhbK66EuBDm2npv/q3qL1/kfEp4aWc/1nQGA+VAqpRbA6hP2QOnGWU48YXgNJnv DidcYFLs4mK6xVmi17poUNBFtTA4uy+rg1+KDij9exj+yaPO5pdhhwyX7Jif7hXzwlWW 2hjfKhyOP/44KsHJSYj2rhYsOYuhQYP4MZCe7Z++vBXc+kIkOMMDV2jJc+O79jxWuVNw 0EeQ== X-Gm-Message-State: AMke39knkYV9AGw1VZ0aUJheVxt9i+5d9/wIgGEe+d3F1kOuShTnfwFpkxe5Nx1D9qaj9Eyl X-Received: by 10.28.166.199 with SMTP id p190mr3151595wme.25.1487948710903; Fri, 24 Feb 2017 07:05:10 -0800 (PST) Received: from localhost.localdomain ([105.149.201.216]) by smtp.gmail.com with ESMTPSA id w207sm2687048wmw.1.2017.02.24.07.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Feb 2017 07:05:10 -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 Cc: lersek@redhat.com, feng.tian@intel.com, star.zeng@intel.com, Ard Biesheuvel Date: Fri, 24 Feb 2017 15:04:56 +0000 Message-Id: <1487948699-3179-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487948699-3179-1-git-send-email-ard.biesheuvel@linaro.org> References: <1487948699-3179-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [PATCH v2 2/5] 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: , X-List-Received-Date: Fri, 24 Feb 2017 15:05:12 -0000 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 --- MdeModulePkg/Core/Pei/Image/Image.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c index d659de8b3e64..8cc9ed93e9b6 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -453,12 +453,16 @@ LoadAndRelocatePeCoffImage ( // // The PEIM is not assiged valid address, try to allocate page to load it. // - ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize)); + Status = PeiServicesAllocatePages (EfiBootServicesCode, + EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize), + &ImageContext.ImageAddress); } } else { - ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) AllocatePages (EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize)); + Status = PeiServicesAllocatePages (EfiBootServicesCode, + EFI_SIZE_TO_PAGES ((UINT32) AlignImageSize), + &ImageContext.ImageAddress); } - if (ImageContext.ImageAddress != 0) { + if (!EFI_ERROR (Status)) { // // Adjust the Image Address to make sure it is section alignment. // -- 2.7.4