Skip to content

Commit

Permalink
lib/elf: Check if DT_PLTREL is DT_RELA
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Jun 4, 2024
1 parent 7a596fa commit d694902
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions common/lib/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d694902

Please sign in to comment.