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 <ben.levinsky@amd.com>
This commit is contained in:
Ben Levinsky
2026-09-21 09:50:11 +02:00
committed by Arnaud Pouliquen
parent 872a4fcae7
commit 08a45aca33
2 changed files with 18 additions and 0 deletions
+2
View File
@@ -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
+16
View File
@@ -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);