From 08a45aca334d49133abdf89b21817af1217595fc Mon Sep 17 00:00:00 2001 From: Ben Levinsky Date: Mon, 1 Jun 2026 07:29:29 -0700 Subject: [PATCH] remoteproc: track loaded ELF section string-table size Store the loaded section string-table size in the ELF image information for both ELF32 and ELF64 images. Keeping the size alongside the string-table pointer allows later section name lookups to validate sh_name offsets against the actual loaded table bounds. Signed-off-by: Ben Levinsky --- lib/include/openamp/elf_loader.h | 2 ++ lib/remoteproc/elf_loader.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/include/openamp/elf_loader.h b/lib/include/openamp/elf_loader.h index a2950f8..126740c 100644 --- a/lib/include/openamp/elf_loader.h +++ b/lib/include/openamp/elf_loader.h @@ -290,6 +290,7 @@ struct elf32_info { Elf32_Phdr *phdrs; Elf32_Shdr *shdrs; void *shstrtab; + size_t shstrtab_size; }; struct elf64_info { @@ -298,6 +299,7 @@ struct elf64_info { Elf64_Phdr *phdrs; Elf64_Shdr *shdrs; void *shstrtab; + size_t shstrtab_size; }; #define ELF_STATE_INIT 0x0L diff --git a/lib/remoteproc/elf_loader.c b/lib/remoteproc/elf_loader.c index 44440b5..2e6a265 100644 --- a/lib/remoteproc/elf_loader.c +++ b/lib/remoteproc/elf_loader.c @@ -207,6 +207,21 @@ static void **elf_shstrtab_ptr(void *elf_info) } } +/** + * @brief Store the loaded ELF section string table size. + * + * @param elf_info ELF information. + * @param size Loaded section string table size. + */ +static void elf_set_shstrtab_size(void *elf_info, size_t size) +{ + if (elf_is_64(elf_info) == 0) { + ((struct elf32_info *)elf_info)->shstrtab_size = size; + } else { + ((struct elf64_info *)elf_info)->shstrtab_size = size; + } +} + static int *elf_load_state(void *elf_info) { if (elf_is_64(elf_info) == 0) { @@ -598,6 +613,7 @@ int elf_load_header(const void *img_data, size_t offset, size_t len, *shstrtab = metal_allocate_memory(shstrtab_size); if (!*shstrtab) return -RPROC_ENOMEM; + elf_set_shstrtab_size(*img_info, shstrtab_size); memcpy(*shstrtab, (const char *)img_data + shstrtab_offset, shstrtab_size);