mirror of
https://github.com/apache/nuttx.git
synced 2026-10-10 07:40:27 +00:00
libs/libc/machine/arm64: Do not dereference a NULL symbol in up_relocateadd().
libelf_relocateadd() passes sym as NULL for a relocation against symbol index 0, such as R_AARCH64_NONE. up_relocateadd() read sym->st_value first, so loading a module with such a relocation faulted in the kernel. Accept a NULL symbol for R_AARCH64_NONE and fail any other type, as the other architectures do. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
This commit is contained in:
parent
fe34a3ee78
commit
3515e44845
1 changed files with 10 additions and 1 deletions
|
|
@ -485,11 +485,20 @@ int up_relocateadd(const Elf64_Rela *rel, const Elf64_Sym *sym,
|
|||
uint64_t val;
|
||||
int ret = 0;
|
||||
|
||||
/* Only R_AARCH64_NONE may come without a symbol (symbol index 0) */
|
||||
|
||||
if (sym == NULL && ELF64_R_TYPE(rel->r_info) != R_AARCH64_NONE)
|
||||
{
|
||||
berr("ERROR: Relocation type %d has no symbol\n",
|
||||
(int)ELF64_R_TYPE(rel->r_info));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* addr corresponds to P in the AArch64 ELF document. */
|
||||
|
||||
/* val corresponds to (S + A) in the AArch64 ELF document. */
|
||||
|
||||
val = sym->st_value + rel->r_addend;
|
||||
val = (sym != NULL ? sym->st_value : 0) + rel->r_addend;
|
||||
|
||||
/* Handle the relocation by relocation type */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue