Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Matthias Schiffer and committed by
Jessica Yu
38b37d63 2eef1399

+11 -1
+5
include/linux/moduleloader.h
··· 29 29 /* Free memory returned from module_alloc. */ 30 30 void module_memfree(void *module_region); 31 31 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 + 32 37 /* 33 38 * Apply the given relocation to the (simplified) ELF. Return -error 34 39 * or 0.
+6 -1
kernel/module.c
··· 2748 2748 return vmalloc_exec(size); 2749 2749 } 2750 2750 2751 + bool __weak module_exit_section(const char *name) 2752 + { 2753 + return strstarts(name, ".exit"); 2754 + } 2755 + 2751 2756 #ifdef CONFIG_DEBUG_KMEMLEAK 2752 2757 static void kmemleak_load_module(const struct module *mod, 2753 2758 const struct load_info *info) ··· 2942 2937 2943 2938 #ifndef CONFIG_MODULE_UNLOAD 2944 2939 /* Don't load .exit sections */ 2945 - if (strstarts(info->secstrings+shdr->sh_name, ".exit")) 2940 + if (module_exit_section(info->secstrings+shdr->sh_name)) 2946 2941 shdr->sh_flags &= ~(unsigned long)SHF_ALLOC; 2947 2942 #endif 2948 2943 }