:: commit d694902642592eb52be8f9f4e341beaa6fabc7ee

mintsuki <mintsuki@protonmail.com> — 2024-06-04 01:02

parents: 7a596fa9fe

lib/elf: Check if DT_PLTREL is DT_RELA

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);
 
tab: 248 wrap: offon