diff mbox series

[U-Boot,v2,06/14] x86: detect unsupported relocation types

Message ID 1539489134-9847-7-git-send-email-bmeng.cn@gmail.com
State Accepted
Delegated to: Bin Meng
Headers show
Series x86: Bring qemu-x86_64 target in travis-ci build/testing | expand

Commit Message

Bin Meng Oct. 14, 2018, 3:52 a.m. UTC
From: Heinrich Schuchardt <xypron.glpk@gmx.de>

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>
---

Changes in v2: None

 arch/x86/lib/relocate.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/lib/relocate.c b/arch/x86/lib/relocate.c
index ed10755..4d09e4d 100644
--- a/arch/x86/lib/relocate.c
+++ b/arch/x86/lib/relocate.c
@@ -53,6 +53,15 @@  static void do_elf_reloc_fixups64(unsigned int text_base, uintptr_t size,
 	Elf64_Addr *offset_ptr_ram;
 
 	do {
+		unsigned long long type = ELF64_R_TYPE(re_src->r_info);
+
+		if (type != R_X86_64_RELATIVE) {
+			printf("%s: unsupported relocation type 0x%llx "
+			       "at %p, ", __func__, type, re_src);
+			printf("offset = 0x%llx\n", re_src->r_offset);
+			continue;
+		}
+
 		/* Get the location from the relocation entry */
 		offset_ptr_rom = (Elf64_Addr *)(uintptr_t)re_src->r_offset;
 
@@ -91,6 +100,15 @@  static void do_elf_reloc_fixups32(unsigned int text_base, uintptr_t size,
 	Elf32_Addr *offset_ptr_ram;
 
 	do {
+		unsigned int type = ELF32_R_TYPE(re_src->r_info);
+
+		if (type != R_386_RELATIVE) {
+			printf("%s: unsupported relocation type 0x%x "
+			       "at %p, ", __func__, type, re_src);
+			printf("offset = 0x%x\n", re_src->r_offset);
+			continue;
+		}
+
 		/* Get the location from the relocation entry */
 		offset_ptr_rom = (Elf32_Addr *)(uintptr_t)re_src->r_offset;