Skip to content

Commit 0d86ebb

Browse files
JordanYateskartben
authored andcommitted
llext: load: memcpy section header
When loading from `.elf` files, it is not guaranteed that section headers are word aligned with the `.elf` file. Attempting to perform a direct assignment results in the compiler assuming the input pointer is aligned, resulting in usage faults if the assumption is broken. Signed-off-by: Jordan Yates <[email protected]>
1 parent 61e177f commit 0d86ebb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

subsys/llext/llext_load.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,24 @@ static int llext_find_tables(struct llext_loader *ldr, struct llext *ext)
177177

178178
if (shdr->sh_type == SHT_SYMTAB && ldr->hdr.e_type == ET_REL) {
179179
LOG_DBG("symtab at %d", i);
180-
ldr->sects[LLEXT_MEM_SYMTAB] = *shdr;
180+
memcpy(&ldr->sects[LLEXT_MEM_SYMTAB], shdr, sizeof(*shdr));
181181
ldr->sect_map[i].mem_idx = LLEXT_MEM_SYMTAB;
182182
strtab_ndx = shdr->sh_link;
183183
table_cnt++;
184184
} else if (shdr->sh_type == SHT_DYNSYM && ldr->hdr.e_type == ET_DYN) {
185185
LOG_DBG("dynsym at %d", i);
186-
ldr->sects[LLEXT_MEM_SYMTAB] = *shdr;
186+
memcpy(&ldr->sects[LLEXT_MEM_SYMTAB], shdr, sizeof(*shdr));
187187
ldr->sect_map[i].mem_idx = LLEXT_MEM_SYMTAB;
188188
strtab_ndx = shdr->sh_link;
189189
table_cnt++;
190190
} else if (shdr->sh_type == SHT_STRTAB && i == shstrtab_ndx) {
191191
LOG_DBG("shstrtab at %d", i);
192-
ldr->sects[LLEXT_MEM_SHSTRTAB] = *shdr;
192+
memcpy(&ldr->sects[LLEXT_MEM_SHSTRTAB], shdr, sizeof(*shdr));
193193
ldr->sect_map[i].mem_idx = LLEXT_MEM_SHSTRTAB;
194194
table_cnt++;
195195
} else if (shdr->sh_type == SHT_STRTAB && i == strtab_ndx) {
196196
LOG_DBG("strtab at %d", i);
197-
ldr->sects[LLEXT_MEM_STRTAB] = *shdr;
197+
memcpy(&ldr->sects[LLEXT_MEM_STRTAB], shdr, sizeof(*shdr));
198198
ldr->sect_map[i].mem_idx = LLEXT_MEM_STRTAB;
199199
table_cnt++;
200200
}

0 commit comments

Comments
 (0)