Skip to content

Commit

Permalink
module: treat exit sections the same as init sections when !CONFIG_MO…
Browse files Browse the repository at this point in the history
…DULE_UNLOAD

commit 3312134 upstream.

Dynamic code patching (alternatives, jump_label and static_call) can
have sites in __exit code, even it __exit is never executed. Therefore
__exit must be present at runtime, at least for as long as __init code
is.

Additionally, for jump_label and static_call, the __exit sites must also
identify as within_module_init(), such that the infrastructure is aware
to never touch them after module init -- alternatives are only ran once
at init and hence don't have this particular constraint.

By making __exit identify as __init for MODULE_UNLOAD, the above is
satisfied.

So, when !CONFIG_MODULE_UNLOAD, the section ordering should look like the
following, with the .exit sections moved to the init region of the module.

Core section allocation order:
 	.text
 	.rodata
 	__ksymtab_gpl
 	__ksymtab_strings
 	.note.* sections
 	.bss
 	.data
 	.gnu.linkonce.this_module
 Init section allocation order:
 	.init.text
 	.exit.text
 	.symtab
 	.strtab

[jeyu: thanks to Peter Zijlstra for most of changelog]

Link: https://lore.kernel.org/lkml/YFiuphGw0RKehWsQ@gunter/
Link: https://lore.kernel.org/r/20210323142756.11443-1-jeyu@kernel.org
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
Cc: Joerg Vehlow <lkml@jv-coder.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
flaming-toast authored and gregkh committed May 25, 2022
1 parent 355141f commit 030de84
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -2861,7 +2861,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)
Expand Down Expand Up @@ -3171,11 +3175,6 @@ static int rewrite_section_headers(struct load_info *info, int flags)
temporary image. */
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. */
Expand Down

0 comments on commit 030de84

Please sign in to comment.