Skip to content

Commit

Permalink
pe: Align section size up to page size for mem attrs
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nicholasbishop authored and vathpela committed Jan 27, 2023
1 parent 89972ae commit c7b3051
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c7b3051

Please sign in to comment.