Skip to content

Commit bd8b21d

Browse files
committed
arm64: module: rework special section handling
When we load a module, we have to perform some special work for a couple of named sections. To do this, we iterate over all of the module's sections, and perform work for each section we recognize. To make it easier to handle the unexpected absence of a section, and to make the section-specific logic easer to read, let's factor the section search into a helper. Similar is already done in the core module loader, and other architectures (and ideally we'd unify these in future). If we expect a module to have an ftrace trampoline section, but it doesn't have one, we'll now reject loading the module. When ARM64_MODULE_PLTS is selected, any correctly built module should have one (and this is assumed by arm64's ftrace PLT code) and the absence of such a section implies something has gone wrong at build time. Subsequent patches will make use of the new helper. Signed-off-by: Mark Rutland <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: Torsten Duwe <[email protected]> Tested-by: Amit Daniel Kachhap <[email protected]> Tested-by: Torsten Duwe <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: James Morse <[email protected]> Cc: Will Deacon <[email protected]>
1 parent a1326b1 commit bd8b21d

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

arch/arm64/kernel/module.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -470,22 +470,39 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
470470
return -ENOEXEC;
471471
}
472472

473-
int module_finalize(const Elf_Ehdr *hdr,
474-
const Elf_Shdr *sechdrs,
475-
struct module *me)
473+
static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
474+
const Elf_Shdr *sechdrs,
475+
const char *name)
476476
{
477477
const Elf_Shdr *s, *se;
478478
const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
479479

480480
for (s = sechdrs, se = sechdrs + hdr->e_shnum; s < se; s++) {
481-
if (strcmp(".altinstructions", secstrs + s->sh_name) == 0)
482-
apply_alternatives_module((void *)s->sh_addr, s->sh_size);
481+
if (strcmp(name, secstrs + s->sh_name) == 0)
482+
return s;
483+
}
484+
485+
return NULL;
486+
}
487+
488+
int module_finalize(const Elf_Ehdr *hdr,
489+
const Elf_Shdr *sechdrs,
490+
struct module *me)
491+
{
492+
const Elf_Shdr *s;
493+
494+
s = find_section(hdr, sechdrs, ".altinstructions");
495+
if (s)
496+
apply_alternatives_module((void *)s->sh_addr, s->sh_size);
497+
483498
#ifdef CONFIG_ARM64_MODULE_PLTS
484-
if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE) &&
485-
!strcmp(".text.ftrace_trampoline", secstrs + s->sh_name))
486-
me->arch.ftrace_trampoline = (void *)s->sh_addr;
487-
#endif
499+
if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE)) {
500+
s = find_section(hdr, sechdrs, ".text.ftrace_trampoline");
501+
if (!s)
502+
return -ENOEXEC;
503+
me->arch.ftrace_trampoline = (void *)s->sh_addr;
488504
}
505+
#endif
489506

490507
return 0;
491508
}

0 commit comments

Comments
 (0)