From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x232.google.com (mail-wm0-x232.google.com [IPv6:2a00:1450:400c:c09::232]) (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 CBAA38212B for ; Sun, 26 Feb 2017 10:30:38 -0800 (PST) Received: by mail-wm0-x232.google.com with SMTP id 196so15075064wmm.1 for ; Sun, 26 Feb 2017 10:30:38 -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=XVg5C3+o4/fR4e4gaC4Bjpv4JB1mS+5YqUZt4czq1OA=; b=fSNhJeCs7szxrb6btdZ40Se7NP7SNMBeOPQRidpOBA9vLem/ErHeu9aBpr13vdAE9W IW6Elp9GZ0qgjHMXFcnnOKwO5AGrlBmw6mBbAfLba5QZr2qM0mFNNAIpnR7djaFFBFCK TEVSJ3llXDs3zxAIEJanTFjROqyWjq/c+Cypg= 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=XVg5C3+o4/fR4e4gaC4Bjpv4JB1mS+5YqUZt4czq1OA=; b=koccGgxGZlfNi1EW9JynLO3wqqXiSJlAUlZiMrPm1RR1aKBjYTRrR8bqXTdtrz1zJU 4XSbCK7uEBC8EK0V+p25uoNqHXd48OSAhLRujdKbN8ixvwEdsCQPR45sFj79F+tDLaeI nOSvENxlYsf9fgcwJ3R8B5OSBgigAV7fFJ/MHv24AdTdWJtPG2r8S39aKKJDLwWZ/LbU Zw/2uNyjROIQRaC6segmffdrSMaAvldEg55fnOqk/lfu0M9ZELNFL88r6FCyyr3k6Wy2 EncxLMyKlgiIizTD1yb71PcK2CkOuFkYT1Pc9/AKJxsxATVUCra+J6lP9YLAhXt9glRx Eprw== X-Gm-Message-State: AMke39n7j86b3XIfFI64wnI8SJDTcIOwYo1mzOG+RYI2+9eO5ruYLR4HtXACQC+yytXwnts8 X-Received: by 10.28.52.19 with SMTP id b19mr11114221wma.134.1488133837417; Sun, 26 Feb 2017 10:30:37 -0800 (PST) Received: from localhost.localdomain ([105.149.201.216]) by smtp.gmail.com with ESMTPSA id s103sm4499474wrc.6.2017.02.26.10.30.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Feb 2017 10:30:36 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, jiewen.yao@intel.com, leif.lindholm@linaro.org Cc: afish@apple.com, michael.d.kinney@intel.com, liming.gao@Intel.com, lersek@redhat.com, feng.tian@intel.com, star.zeng@intel.com, Ard Biesheuvel Date: Sun, 26 Feb 2017 18:30:01 +0000 Message-Id: <1488133805-4773-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1488133805-4773-1-git-send-email-ard.biesheuvel@linaro.org> References: <1488133805-4773-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [PATCH v3 2/6] 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: Sun, 26 Feb 2017 18:30:39 -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 Reviewed-by: Jiewen Yao --- 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