From a0c9d5c6d9bb9dfa9641d3a98975468c5d63d9ff Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sat, 2 Nov 2013 19:16:36 +0100 Subject: [PATCH] * util/grub-mkimagexx.c (locate_sections): Reject mislinked images. --- ChangeLog | 4 ++++ util/grub-mkimagexx.c | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8f8504d9d..243e4e9cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-11-02 Vladimir Serbinenko + + * util/grub-mkimagexx.c (locate_sections): Reject mislinked images. + 2013-11-02 Vladimir Serbinenko * configure.ac: Use 0x8000 for address instead of 8000. diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index 387461311..00d1efff1 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -806,7 +806,8 @@ SUFFIX (check_elf_header) (Elf_Ehdr *e, size_t size, const struct grub_install_i into .text and .data, respectively. Return the array of section addresses. */ static Elf_Addr * -SUFFIX (locate_sections) (Elf_Shdr *sections, Elf_Half section_entsize, +SUFFIX (locate_sections) (const char *kernel_path, + Elf_Shdr *sections, Elf_Half section_entsize, Elf_Half num_sections, const char *strtab, size_t *exec_size, size_t *kernel_sz, size_t *all_align, @@ -846,8 +847,17 @@ SUFFIX (locate_sections) (Elf_Shdr *sections, Elf_Half section_entsize, grub_util_info ("locating the section %s at 0x%llx", name, (unsigned long long) current_address); if (image_target->id != IMAGE_EFI) - current_address = grub_host_to_target_addr (s->sh_addr) - - image_target->link_addr; + { + current_address = grub_host_to_target_addr (s->sh_addr) + - image_target->link_addr; + if (grub_host_to_target_addr (s->sh_addr) + != image_target->link_addr) + grub_util_error ("`%s' is miscompiled: it's start address is 0x%llx" + " instead of 0x%llx: ld.gold bug?", + kernel_path, + (unsigned long long) grub_host_to_target_addr (s->sh_addr), + (unsigned long long) image_target->link_addr); + } section_addresses[i] = current_address; current_address += grub_host_to_target_addr (s->sh_size); } @@ -935,7 +945,8 @@ SUFFIX (load_image) (const char *kernel_path, size_t *exec_size, + grub_host_to_target16 (e->e_shstrndx) * section_entsize); strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); - section_addresses = SUFFIX (locate_sections) (sections, section_entsize, + section_addresses = SUFFIX (locate_sections) (kernel_path, + sections, section_entsize, num_sections, strtab, exec_size, kernel_sz, align, image_target);