efi_loader: ImageSize must be multiple of SectionAlignment
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 3 Apr 2018 20:29:32 +0000 (22:29 +0200)
committerAlexander Graf <agraf@suse.de>
Wed, 4 Apr 2018 09:37:40 +0000 (11:37 +0200)
According to the Portable Executable and Common Object File Format
Specification the image size must be a multiple of the alignment
of sections.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/efi_loader/efi_image_loader.c

index 701387b95f242313fc9aa8a5fb36dc5290831a3e..74c6a9f92130acf440eaf7cb3d1cf1a820bb8cfb 100644 (file)
@@ -175,6 +175,7 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info)
                entry = efi_reloc + opt->AddressOfEntryPoint;
                rel_size = opt->DataDirectory[rel_idx].Size;
                rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress;
+               virt_size = ALIGN(virt_size, opt->SectionAlignment);
        } else if (can_run_nt32 &&
                   (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)) {
                IMAGE_OPTIONAL_HEADER32 *opt = &nt->OptionalHeader;
@@ -190,6 +191,7 @@ void *efi_load_pe(void *efi, struct efi_loaded_image *loaded_image_info)
                entry = efi_reloc + opt->AddressOfEntryPoint;
                rel_size = opt->DataDirectory[rel_idx].Size;
                rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress;
+               virt_size = ALIGN(virt_size, opt->SectionAlignment);
        } else {
                printf("%s: Invalid optional header magic %x\n", __func__,
                       nt->OptionalHeader.Magic);