Commit 80df194f0165cb540a2a984f95dd2b37948f54d7

Authored by Heinrich Schuchardt
Committed by Bin Meng
1 parent 194924d881

x86: detect unsupported relocation types

Currently we support only relocations of type ELF64_R_TYPE or ELF32_R_TYPE.
We should be warned if other relocation types appear in the relocation
sections.

This type of message has helped to identify code overwriting a relocation
section before relocation and incorrect parsing of relocation tables.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>

Showing 1 changed file with 18 additions and 0 deletions Side-by-side Diff

arch/x86/lib/relocate.c
... ... @@ -53,6 +53,15 @@
53 53 Elf64_Addr *offset_ptr_ram;
54 54  
55 55 do {
  56 + unsigned long long type = ELF64_R_TYPE(re_src->r_info);
  57 +
  58 + if (type != R_X86_64_RELATIVE) {
  59 + printf("%s: unsupported relocation type 0x%llx "
  60 + "at %p, ", __func__, type, re_src);
  61 + printf("offset = 0x%llx\n", re_src->r_offset);
  62 + continue;
  63 + }
  64 +
56 65 /* Get the location from the relocation entry */
57 66 offset_ptr_rom = (Elf64_Addr *)(uintptr_t)re_src->r_offset;
58 67  
... ... @@ -91,6 +100,15 @@
91 100 Elf32_Addr *offset_ptr_ram;
92 101  
93 102 do {
  103 + unsigned int type = ELF32_R_TYPE(re_src->r_info);
  104 +
  105 + if (type != R_386_RELATIVE) {
  106 + printf("%s: unsupported relocation type 0x%x "
  107 + "at %p, ", __func__, type, re_src);
  108 + printf("offset = 0x%x\n", re_src->r_offset);
  109 + continue;
  110 + }
  111 +
94 112 /* Get the location from the relocation entry */
95 113 offset_ptr_rom = (Elf32_Addr *)(uintptr_t)re_src->r_offset;
96 114