Re: [PATCH 2/4] module: Convert module_finalize() to load_info
From: Kees Cook
Date: Tue Apr 07 2020 - 12:53:13 EST
On Tue, Apr 07, 2020 at 01:02:38PM +0200, Peter Zijlstra wrote:
> Provide load_info to module_finalize(), such that architectures might,
> for example, use get_modinfo() in their implementation.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
-Kees
> ---
> arch/arc/kernel/module.c | 4 ++--
> arch/arm/kernel/module.c | 5 +++--
> arch/arm64/kernel/module.c | 6 +++---
> arch/ia64/kernel/module.c | 3 +--
> arch/m68k/kernel/module.c | 4 +---
> arch/microblaze/kernel/module.c | 3 +--
> arch/mips/kernel/module.c | 6 +++---
> arch/nds32/kernel/module.c | 4 +---
> arch/nios2/kernel/module.c | 3 +--
> arch/parisc/kernel/module.c | 6 +++---
> arch/powerpc/kernel/module.c | 5 +++--
> arch/s390/kernel/module.c | 6 +++---
> arch/sh/kernel/module.c | 6 +++---
> arch/sparc/kernel/module.c | 7 ++++---
> arch/x86/kernel/module.c | 6 +++---
> include/linux/moduleloader.h | 4 +---
> kernel/module.c | 6 ++----
> 17 files changed, 38 insertions(+), 46 deletions(-)
>
> --- a/arch/arc/kernel/module.c
> +++ b/arch/arc/kernel/module.c
> @@ -129,10 +129,10 @@ int apply_relocate_add(Elf32_Shdr *sechd
> * This couldn't be done in module_frob_arch_sections() because
> * relocations had not been applied by then
> */
> -int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
> - struct module *mod)
> +int module_finalize(const struct load_info *info, struct module *mod)
> {
> #ifdef CONFIG_ARC_DW2_UNWIND
> + const Elf_Shdr *sechdrs = info->sechdrs;
> void *unw;
> int unwsec = mod->arch.unw_sec_idx;
>
> --- a/arch/arm/kernel/module.c
> +++ b/arch/arm/kernel/module.c
> @@ -340,9 +340,10 @@ static const Elf_Shdr *find_mod_section(
> extern void fixup_pv_table(const void *, unsigned long);
> extern void fixup_smp(const void *, unsigned long);
>
> -int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
> - struct module *mod)
> +int module_finalize(const struct load_info *info, struct module *mod)
> {
> + const Elf32_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> const Elf_Shdr *s = NULL;
> #ifdef CONFIG_ARM_UNWIND
> const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
> --- a/arch/arm64/kernel/module.c
> +++ b/arch/arm64/kernel/module.c
> @@ -515,10 +515,10 @@ static int module_init_ftrace_plt(const
> return 0;
> }
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> const Elf_Shdr *s;
> s = find_section(hdr, sechdrs, ".altinstructions");
> if (s)
> --- a/arch/ia64/kernel/module.c
> +++ b/arch/ia64/kernel/module.c
> @@ -902,8 +902,7 @@ register_unwind_table (struct module *mo
> }
> }
>
> -int
> -module_finalize (const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, struct module *mod)
> +int module_finalize(const struct load_info *info, struct module *mod)
> {
> DEBUGP("%s: init: entry=%p\n", __func__, mod->init);
> if (mod->arch.unwind)
> --- a/arch/m68k/kernel/module.c
> +++ b/arch/m68k/kernel/module.c
> @@ -99,9 +99,7 @@ int apply_relocate_add(Elf32_Shdr *sechd
> return 0;
> }
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *mod)
> +int module_finalize(const struct load_info *info, struct module *mod)
> {
> module_fixup(mod, mod->arch.fixup_start, mod->arch.fixup_end);
> return 0;
> --- a/arch/microblaze/kernel/module.c
> +++ b/arch/microblaze/kernel/module.c
> @@ -114,8 +114,7 @@ int apply_relocate_add(Elf32_Shdr *sechd
> return 0;
> }
>
> -int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
> - struct module *module)
> +int module_finalize(const struct load_info *info, struct module *module)
> {
> flush_dcache();
> return 0;
> --- a/arch/mips/kernel/module.c
> +++ b/arch/mips/kernel/module.c
> @@ -427,10 +427,10 @@ const struct exception_table_entry *sear
> }
>
> /* Put in dbe list if necessary. */
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> const Elf_Shdr *s;
> char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
>
> --- a/arch/nds32/kernel/module.c
> +++ b/arch/nds32/kernel/module.c
> @@ -266,9 +266,7 @@ apply_relocate_add(Elf32_Shdr * sechdrs,
> return 0;
> }
>
> -int
> -module_finalize(const Elf32_Ehdr * hdr, const Elf_Shdr * sechdrs,
> - struct module *module)
> +int module_finalize(const struct load_info *info, struct module *module)
> {
> return 0;
> }
> --- a/arch/nios2/kernel/module.c
> +++ b/arch/nios2/kernel/module.c
> @@ -130,8 +130,7 @@ int apply_relocate_add(Elf32_Shdr *sechd
> return 0;
> }
>
> -int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> flush_cache_all();
> return 0;
> --- a/arch/parisc/kernel/module.c
> +++ b/arch/parisc/kernel/module.c
> @@ -854,10 +854,10 @@ deregister_unwind_table(struct module *m
> unwind_table_remove(me->arch.unwind);
> }
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> int i;
> unsigned long nsyms;
> const char *strtab = NULL;
> --- a/arch/powerpc/kernel/module.c
> +++ b/arch/powerpc/kernel/module.c
> @@ -31,9 +31,10 @@ static const Elf_Shdr *find_section(cons
> return NULL;
> }
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs, struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> const Elf_Shdr *sect;
> int rc;
>
> --- a/arch/s390/kernel/module.c
> +++ b/arch/s390/kernel/module.c
> @@ -437,10 +437,10 @@ int apply_relocate_add(Elf_Shdr *sechdrs
> return 0;
> }
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> const Elf_Shdr *s;
> char *secstrings, *secname;
> void *aseg;
> --- a/arch/sh/kernel/module.c
> +++ b/arch/sh/kernel/module.c
> @@ -96,10 +96,10 @@ int apply_relocate_add(Elf32_Shdr *sechd
> return 0;
> }
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> int ret = 0;
>
> ret |= module_dwarf_finalize(hdr, sechdrs, me);
> --- a/arch/sparc/kernel/module.c
> +++ b/arch/sparc/kernel/module.c
> @@ -204,10 +204,11 @@ static void do_patch_sections(const Elf_
> }
> }
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> +
> /* make jump label nops */
> jump_label_apply_nops(me);
>
> --- a/arch/x86/kernel/module.c
> +++ b/arch/x86/kernel/module.c
> @@ -217,10 +217,10 @@ int apply_relocate_add(Elf64_Shdr *sechd
> }
> #endif
>
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int module_finalize(const struct load_info *info, struct module *me)
> {
> + const Elf_Ehdr *hdr = info->hdr;
> + const Elf_Shdr *sechdrs = info->sechdrs;
> const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL,
> *para = NULL, *orc = NULL, *orc_ip = NULL;
> char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
> --- a/include/linux/moduleloader.h
> +++ b/include/linux/moduleloader.h
> @@ -101,9 +101,7 @@ static inline int apply_relocate_add(Elf
> #endif
>
> /* Any final processing of module before access. Return -error or 0. */
> -int module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *mod);
> +int module_finalize(const struct load_info *info, struct module *mod);
>
> /* Any cleanup needed when module leaves. */
> void module_arch_cleanup(struct module *mod);
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -3425,9 +3425,7 @@ static void module_deallocate(struct mod
> module_memfree(mod->core_layout.base);
> }
>
> -int __weak module_finalize(const Elf_Ehdr *hdr,
> - const Elf_Shdr *sechdrs,
> - struct module *me)
> +int __weak module_finalize(const struct load_info *info, struct module *me)
> {
> return 0;
> }
> @@ -3445,7 +3443,7 @@ static int post_relocation(struct module
> add_kallsyms(mod, info);
>
> /* Arch-specific module finalizing. */
> - return module_finalize(info->hdr, info->sechdrs, mod);
> + return module_finalize(info, mod);
> }
>
> /* Is this module of this name done loading? No locks held. */
>
>
--
Kees Cook