summaryrefslogtreecommitdiffstats
path: root/kernel/module.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2021-04-30 12:29:36 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2021-04-30 12:29:36 -0700
commit65c61de9d090edb8a3cfb3f45541e268eb2cdb13 (patch)
treef8298d9571a200b42824929bfd2d679fce162361 /kernel/module.c
parentc70a4be130de333ea079c59da41cc959712bb01c (diff)
parent33121347fb1c359bd6e3e680b9f2c6ced5734a81 (diff)
downloadlinux-65c61de9d090edb8a3cfb3f45541e268eb2cdb13.tar.gz
linux-65c61de9d090edb8a3cfb3f45541e268eb2cdb13.tar.bz2
linux-65c61de9d090edb8a3cfb3f45541e268eb2cdb13.zip
Merge tag 'modules-for-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux
Pull module updates from Jessica Yu: "Fix an age old bug involving jump_calls and static_labels when CONFIG_MODULE_UNLOAD=n. When CONFIG_MODULE_UNLOAD=n, it means you can't unload modules, so normally the __exit sections of a module are not loaded at all. However, dynamic code patching (jump_label, static_call, alternatives) can have sites in __exit sections even if __exit is never executed. Reported by Peter Zijlstra: 'Alternatives, jump_labels and static_call all can have relocations into __exit code. Not loading it at all would be BAD.' Therefore, load the __exit sections even when CONFIG_MODULE_UNLOAD=n, and discard them after init" * tag 'modules-for-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu/linux: module: treat exit sections the same as init sections when !CONFIG_MODULE_UNLOAD
Diffstat (limited to 'kernel/module.c')
-rw-r--r--kernel/module.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/kernel/module.c b/kernel/module.c
index 20fb004e7d8d..b5dd92e35b02 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2807,7 +2807,11 @@ void * __weak module_alloc(unsigned long size)
bool __weak module_init_section(const char *name)
{
+#ifndef CONFIG_MODULE_UNLOAD
+ return strstarts(name, ".init") || module_exit_section(name);
+#else
return strstarts(name, ".init");
+#endif
}
bool __weak module_exit_section(const char *name)
@@ -3121,11 +3125,6 @@ static int rewrite_section_headers(struct load_info *info, int flags)
*/
shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset;
-#ifndef CONFIG_MODULE_UNLOAD
- /* Don't load .exit sections */
- if (module_exit_section(info->secstrings+shdr->sh_name))
- shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;
-#endif
}
/* Track but don't keep modinfo and version sections. */