Skip to content

Commit 38b37d6

Browse files
tq-schiffernJessica Yu
authored andcommitted
module: allow arch overrides for .exit section names
Some archs like ARM store unwind information for .exit.text in sections with unusual names. As this unwind information refers to .exit.text, it must not be loaded when .exit.text is not loaded (when CONFIG_MODULE_UNLOAD is unset); otherwise, loading a module can fail due to relocation failures. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Signed-off-by: Jessica Yu <jeyu@kernel.org>
1 parent 2eef139 commit 38b37d6

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎include/linux/moduleloader.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ void *module_alloc(unsigned long size);
2929
/* Free memory returned from module_alloc. */
3030
void module_memfree(void *module_region);
3131

32+
/* Determines if the section name is an exit section (that is only used during
33+
* module unloading)
34+
*/
35+
bool module_exit_section(const char *name);
36+
3237
/*
3338
* Apply the given relocation to the (simplified) ELF. Return -error
3439
* or 0.

‎kernel/module.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,11 @@ void * __weak module_alloc(unsigned long size)
27482748
return vmalloc_exec(size);
27492749
}
27502750

2751+
bool __weak module_exit_section(const char *name)
2752+
{
2753+
return strstarts(name, ".exit");
2754+
}
2755+
27512756
#ifdef CONFIG_DEBUG_KMEMLEAK
27522757
static void kmemleak_load_module(const struct module *mod,
27532758
const struct load_info *info)
@@ -2937,7 +2942,7 @@ static int rewrite_section_headers(struct load_info *info, int flags)
29372942

29382943
#ifndef CONFIG_MODULE_UNLOAD
29392944
/* Don't load .exit sections */
2940-
if (strstarts(info->secstrings+shdr->sh_name, ".exit"))
2945+
if (module_exit_section(info->secstrings+shdr->sh_name))
29412946
shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;
29422947
#endif
29432948
}

0 commit comments

Comments
 (0)