powerpc module arch checks
Subsystems (2)
Nicholas Piggin
reviewerv5 cover powerpc module arch checks
These slipped through the cracks. Picking them up again...
The story so far is that Jessica gave us the new scheme in patch 1, now slightly rebased. Patch 2 implements the additional check that powerpc wants which originally came from Michael, and has been updated to the new approach.
This was previously attached to the ELFv2 build option for big-endian kernels, but it can go ahead of that option.
Just checking everybody is still okay with the code and their SOBs, and Luis if you would be okay for patch 1 to be merged via powerpc or prefer to take it in the module tree (or maybe you object to the code in the first place).
Thanks,
Nick
Nicholas Piggin (2):
module: add module_elf_check_arch for module-specific checks powerpc/64: Add module check for ELF ABI version
arch/powerpc/kernel/module.c | 17 +++++++++++++++++ include/linux/moduleloader.h | 3 +++ kernel/module/main.c | 10 ++++++++++ 3 files changed, 30 insertions(+)
Signature · 1 line
2.37.2
Nicholas Piggin
reviewerPATCH v5 1/2 module: add module_elf_check_arch for module-specific checks
The elf_check_arch() function is also used to test compatibility of usermode binaries. Kernel modules may have more specific requirements, for example powerpc would like to test for ABI version compatibility.
Add a weak module_elf_check_arch() that defaults to true, and call it from elf_validity_check().
--- include/linux/moduleloader.h | 3 +++ kernel/module/main.c | 10 ++++++++++ 2 files changed, 13 insertions(+)
include/linux/moduleloader.h +3 -0
@@ -13,6 +13,9 @@* must be implemented by each architecture. */ +/* arch may override to do additional checking of ELF header architecture */ +bool module_elf_check_arch (Elf_Ehdr *hdr); +/* Adjust arch-specific sections. Return 0 on success. */ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
kernel/module/main.c +10 -0
@@ -1674,6 +1674,11 @@ static int elf_validity_check(struct load_info *info) info->hdr->e_machine); goto no_exec; } +if (!module_elf_check_arch (info->hdr)) { +pr_err ("Invalid module architecture in ELF header: %u\n" , + info->hdr->e_machine); + goto no_exec; + }if (info->hdr->e_shentsize !=sizeof (Elf_Shdr)) {pr_err ("Invalid ELF section header size\n" ); goto no_exec;
@@ -2247,6 +2252,11 @@ static void flush_module_icache(const struct module *mod) (unsigned long)mod->core_layout.base + mod->core_layout.size); } +bool __weak module_elf_check_arch (Elf_Ehdr *hdr) +{ +return true; +} + int __weak module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, char *secstrings,
Signature · 1 line
2.37.2
Re: [PATCH v5 1/2] module: add module_elf_check_arch for module-specific checks
Quoted 11 lines · Nicholas Piggin
The
elf_check_arch()function is also used to test compatibility of usermode binaries. Kernel modules may have more specific requirements, for example powerpc would like to test for ABI version compatibility.Add a weak
module_elf_check_arch()that defaults to true, and call it fromelf_validity_check().Cc Michael Ellerman <[email protected]>Signed-off-by Jessica Yu <[email protected]>[np: added changelog, adjust name, rebase]Signed-off-by Nicholas Piggin <[email protected]>
Luis
Nicholas Piggin
reviewerPATCH v5 2/2 powerpc/64: Add module check for ELF ABI version
In reply to Nicholas PigginOverride the generic module ELF check to provide a check for the ELF ABI version. This becomes important if we allow big-endian ELF ABI V2 builds but it doesn't hurt to check now.
--- arch/powerpc/kernel/module.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/powerpc/kernel/module.c +17 -0
@@ -19,6 +19,23 @@static LIST_HEAD (module_bug_list); +#ifdef CONFIG_PPC64 +bool module_elf_check_arch (Elf_Ehdr *hdr) +{ +unsigned long abi_level = hdr->e_flags &0x3 ; + +if (IS_ENABLED (CONFIG_PPC64_ELF_ABI_V2 )) { +if (abi_level !=2 ) +return false; + }else { +if (abi_level >=2 ) +return false; + } + +return true; +} +#endif +static const Elf_Shdr *find_section (const Elf_Ehdr *hdr,const Elf_Shdr *sechdrs,const char *name)
Signature · 1 line
2.37.2
Re: [PATCH v5 2/2] powerpc/64: Add module check for ELF ABI version
Le 31/10/2022 à 13:07, Nicholas Piggin a écrit :
Quoted 17 lines
Override the generic module ELF check to provide a check for the ELF ABI version. This becomes important if we allow big-endian ELF ABI V2 builds but it doesn't hurt to check now.
Cc Jessica Yu <[email protected]>Signed-off-by Michael Ellerman <[email protected]>[np: split patch, added changelog, adjust to Jessica's proposal]Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/kernel/module.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)arch/powerpc/kernel/module.c +0
-0
arch/powerpc/kernel/module.c line 22
Quoted 4 lines
arch/powerpc/kernel/module.c +1
-0@@ -19,6 +19,23 @@static LIST_HEAD (module_bug_list); +#ifdef CONFIG_PPC64
Can it go in arch/powerpc/kernel/module_64.c instead ?
arch/powerpc/kernel/module.c line 35
Quoted 13 lines
arch/powerpc/kernel/module.c +13
-0+bool module_elf_check_arch (Elf_Ehdr *hdr) +{ +unsigned long abi_level = hdr->e_flags &0x3 ; + +if (IS_ENABLED (CONFIG_PPC64_ELF_ABI_V2 )) { +if (abi_level !=2 ) +return false; + }else { +if (abi_level >=2 ) +return false; + } + +return true;
Can be simpler:
if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2)) return abi_level == 2; else return abi_level < 2;
Quoted 6 lines
arch/powerpc/kernel/module.c +3
-0+} +#endif +static const Elf_Shdr *find_section (const Elf_Ehdr *hdr,const Elf_Shdr *sechdrs,const char *name)
Nicholas Piggin
reviewerRe: [PATCH v5 2/2] powerpc/64: Add module check for ELF ABI version
Quoted 43 lines · Christophe Leroy
Le 31/10/2022 à 13:07, Nicholas Piggin a écrit :
Quoted 17 lines
Override the generic module ELF check to provide a check for the ELF ABI version. This becomes important if we allow big-endian ELF ABI V2 builds but it doesn't hurt to check now.
Cc Jessica Yu <[email protected]>Signed-off-by Michael Ellerman <[email protected]>[np: split patch, added changelog, adjust to Jessica's proposal]Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/kernel/module.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)arch/powerpc/kernel/module.c +0
-0arch/powerpc/kernel/module.c line 22
Quoted 4 lines
arch/powerpc/kernel/module.c +1
-0@@ -19,6 +19,23 @@static LIST_HEAD (module_bug_list); +#ifdef CONFIG_PPC64 Can it go in
arch/powerpc/kernel/module_64.cinstead ?arch/powerpc/kernel/module.c line 35
Quoted 13 lines
arch/powerpc/kernel/module.c +13
-0+bool module_elf_check_arch (Elf_Ehdr *hdr) +{ +unsigned long abi_level = hdr->e_flags &0x3 ; + +if (IS_ENABLED (CONFIG_PPC64_ELF_ABI_V2 )) { +if (abi_level !=2 ) +return false; + }else { +if (abi_level >=2 ) +return false; + } + +return true;Can be simpler:
Quoted 4 lines
if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2)) return abi_level == 2; else return abi_level < 2;
Yes I think both of those can be done. Good suggestions.
Thanks,
Nick
Luis Chamberlain
maintainerQuoted 3 lines · Nicholas Piggin
Luis if you would be okay for patch 1 to be merged via powerpc or prefer to take it in the module tree (or maybe you object to the code in the first place).
Looks good to me, and nothing on my radar which would cause a conflict so happy for you to take it via powerpc or I can take it and apply it right away to tricke / get tested on linux-next by tomorrow.
Let me know.
Luis
Michael Ellerman
reviewerQuoted 10 lines · Luis Chamberlain
Quoted 3 lines · Nicholas Piggin
Luis if you would be okay for patch 1 to be merged via powerpc or prefer to take it in the module tree (or maybe you object to the code in the first place).
Looks good to me, and nothing on my radar which would cause a conflict so happy for you to take it via powerpc or I can take it and apply it right away to tricke / get tested on linux-next by tomorrow.
Let me know.
Thanks. I guess it's mostly a nop on other architectures, so probably makes sense for me to take it.
cheers