From d694902642592eb52be8f9f4e341beaa6fabc7ee Mon Sep 17 00:00:00 2001 From: mintsuki Date: Tue, 4 Jun 2024 03:02:55 +0200 Subject: [PATCH] lib/elf: Check if DT_PLTREL is DT_RELA --- common/lib/elf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/lib/elf.c b/common/lib/elf.c index e8089068..623a2aa3 100644 --- a/common/lib/elf.c +++ b/common/lib/elf.c @@ -30,6 +30,7 @@ #define DT_RELRENT 0x00000025 #define DT_SYMTAB 0x00000006 #define DT_SYMENT 0x0000000b +#define DT_PLTREL 0x00000014 #define DT_PLTRELSZ 0x00000002 #define DT_JMPREL 0x00000017 #define DT_FLAGS_1 0x6ffffffb @@ -256,6 +257,7 @@ static bool elf64_apply_relocations(uint8_t *elf, struct elf64_hdr *hdr, void *b uint64_t symtab_offset = 0; uint64_t symtab_ent = 0; + uint64_t dt_pltrel = 0; uint64_t dt_pltrelsz = 0; uint64_t dt_jmprel = 0; @@ -302,6 +304,9 @@ static bool elf64_apply_relocations(uint8_t *elf, struct elf64_hdr *hdr, void *b case DT_SYMENT: symtab_ent = dyn->d_un; break; + case DT_PLTREL: + dt_pltrel = dyn->d_un; + break; case DT_PLTRELSZ: dt_pltrelsz = dyn->d_un; break; @@ -367,6 +372,10 @@ static bool elf64_apply_relocations(uint8_t *elf, struct elf64_hdr *hdr, void *b panic(true, "elf: rela_ent < sizeof(struct elf64_rela)"); } + if (dt_pltrel != DT_RELA) { + panic(true, "elf: dt_pltrel != DT_RELA"); + } + for (uint16_t i = 0; i < hdr->ph_num; i++) { struct elf64_phdr *_phdr = (void *)elf + (hdr->phoff + i * hdr->phdr_size);