summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Bishop <nicholasbishop@google.com>2022-12-19 18:56:13 -0500
committerPeter Jones <pjones@redhat.com>2023-01-27 14:15:33 -0500
commitc7b305152802c8db688605654f75e1195def9fd6 (patch)
tree912d8ce251c7e87c57058f6feb98e1503ed9d72f
parent89972ae25c133df31290f394413c19ea903219ad (diff)
downloadefi-boot-shim-c7b305152802c8db688605654f75e1195def9fd6.tar.gz
efi-boot-shim-c7b305152802c8db688605654f75e1195def9fd6.zip
pe: Align section size up to page size for mem attrs
Setting memory attributes is generally done at page granularity, and this is enforced by checks in `get_mem_attrs` and `update_mem_attrs`. But unlike the section address, the section size isn't necessarily aligned to 4KiB. Round up the section size to fix this. Signed-off-by: Nicholas Bishop <nicholasbishop@google.com>
-rw-r--r--pe.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/pe.c b/pe.c
index 9a3679e1..5ad0914b 100644
--- a/pe.c
+++ b/pe.c
@@ -1372,7 +1372,11 @@ handle_image (void *data, unsigned int datasize,
+ Section->Misc.VirtualSize - 1);
addr = (uintptr_t)base;
- length = (uintptr_t)end - (uintptr_t)base + 1;
+ // Align the length up to PAGE_SIZE. This is required because
+ // platforms generally set memory attributes at page
+ // granularity, but the section length (unlike the section
+ // address) is not required to be aligned.
+ length = ALIGN_VALUE((uintptr_t)end - (uintptr_t)base + 1, PAGE_SIZE);
if (Section->Characteristics & EFI_IMAGE_SCN_MEM_WRITE) {
set_attrs |= MEM_ATTR_W;