diff mbox series

[edk2,v3,2/6] MdeModulePkg/PeiCore: allocate BootServicesCode memory for PE/COFF images

Message ID 1488133805-4773-3-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show
Series RFC: increased memory protection | expand

Commit Message

Ard Biesheuvel Feb. 26, 2017, 6:30 p.m. UTC
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 <ard.biesheuvel@linaro.org>

Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>

---
 MdeModulePkg/Core/Pei/Image/Image.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Gao, Liming Feb. 27, 2017, 6:43 a.m. UTC | #1
Ard:
  In line 128,  there is another AllocatePages() to allocate memory to store the code. To be consistent, could you help also update it? 
  
Thanks
Liming
>-----Original Message-----

>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ard

>Biesheuvel

>Sent: Monday, February 27, 2017 2:30 AM

>To: edk2-devel@lists.01.org; Yao, Jiewen <jiewen.yao@intel.com>;

>leif.lindholm@linaro.org

>Cc: Tian, Feng <feng.tian@intel.com>; Ard Biesheuvel

><ard.biesheuvel@linaro.org>; afish@apple.com; Gao, Liming

><liming.gao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>;

>lersek@redhat.com; Zeng, Star <star.zeng@intel.com>

>Subject: [edk2] [PATCH v3 2/6] MdeModulePkg/PeiCore: allocate

>BootServicesCode memory for PE/COFF images

>

>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 <ard.biesheuvel@linaro.org>

>Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>

>---

> 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

>

>_______________________________________________

>edk2-devel mailing list

>edk2-devel@lists.01.org

>https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ard Biesheuvel Feb. 27, 2017, 8:13 a.m. UTC | #2
On 27 February 2017 at 06:43, Gao, Liming <liming.gao@intel.com> wrote:
> Ard:

>   In line 128,  there is another AllocatePages() to allocate memory to store the code. To be consistent, could you help also update it?

>


OK

>>-----Original Message-----

>>From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ard

>>Biesheuvel

>>Sent: Monday, February 27, 2017 2:30 AM

>>To: edk2-devel@lists.01.org; Yao, Jiewen <jiewen.yao@intel.com>;

>>leif.lindholm@linaro.org

>>Cc: Tian, Feng <feng.tian@intel.com>; Ard Biesheuvel

>><ard.biesheuvel@linaro.org>; afish@apple.com; Gao, Liming

>><liming.gao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>;

>>lersek@redhat.com; Zeng, Star <star.zeng@intel.com>

>>Subject: [edk2] [PATCH v3 2/6] MdeModulePkg/PeiCore: allocate

>>BootServicesCode memory for PE/COFF images

>>

>>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 <ard.biesheuvel@linaro.org>

>>Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>

>>---

>> 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

>>

>>_______________________________________________

>>edk2-devel mailing list

>>edk2-devel@lists.01.org

>>https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

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.
       //