Skip to content

Commit 499c081

Browse files
dgarskedanielinux
authored andcommitted
Add logic to detect ELF loader collision and skip.
1 parent 754d313 commit 499c081

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/elf.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,25 @@ int elf_load_image_mmu(uint8_t *image, uintptr_t *pentry, elf_mmu_map_cb mmu_cb)
136136
}
137137
}
138138

139-
memcpy((void*)(uintptr_t)vaddr, image + offset, file_size);
140-
if (mem_size > file_size) {
141-
memset((void*)(uintptr_t)(vaddr + file_size), 0,
142-
mem_size - file_size);
139+
/* confirm the entry won't clobber any of the headers */
140+
if ((uint8_t*)vaddr + file_size < image ||
141+
(uint8_t*)vaddr > (entry_off + entry_count * entry_size))
142+
{
143+
memcpy((void*)vaddr, image + offset, file_size);
144+
if (mem_size > file_size) {
145+
memset((void*)(uintptr_t)(vaddr + file_size), 0,
146+
mem_size - file_size);
147+
}
148+
#ifdef ARCH_PPC
149+
flush_cache(paddr, mem_size);
150+
#endif
151+
}
152+
#ifdef DEBUG_ELF
153+
else {
154+
wolfBoot_printf("Section would collide with headers! Skipping\n");
143155
}
144-
#ifdef ARCH_PPC
145-
flush_cache(paddr, mem_size);
146156
#endif
147-
#endif
157+
#endif /* !ELF_PARSER */
148158
}
149159

150160
#ifdef DEBUG_ELF

0 commit comments

Comments
 (0)