Hi,
Here are a few small patches to fix kernel module loading in the PCuABI kernel [1]. (Sorry about the delay!) There are some notes on testing in the third patch.
Thanks, Kristina
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/41
Kristina Martsenko (3): module: Allow arch overrides for ELF arch check arm64: elf: Enable module loading for PCuABI kernels arm64: morello: Add test modules to defconfig
.../configs/morello_transitional_pcuabi_defconfig | 6 ++++++ arch/arm64/include/asm/elf.h | 10 ++-------- include/linux/moduleloader.h | 4 ++++ kernel/module/main.c | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-)
base-commit: 7f84d159d4eb989bf2f42d2e3b27a204cb3c1ec4
On some architectures modules (and the kernel itself) may have different ELF properties than native userspace executables. In that case elf_check_arch() can't be used for both. Add a new helper module_elf_check_arch() which architectures can override if they need to check different ELF properties on modules. In a subsequent patch this will be used for PCuABI kernels. No functional change at this point.
Signed-off-by: Kristina Martsenko kristina.martsenko@arm.com --- include/linux/moduleloader.h | 4 ++++ kernel/module/main.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 9e09d11ffe5b..56f8d8dd0f6b 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -13,6 +13,10 @@ * must be implemented by each architecture. */
+#ifndef module_elf_check_arch +#define module_elf_check_arch(x) elf_check_arch(x) +#endif + /* Adjust arch-specific sections. Return 0 on success. */ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, diff --git a/kernel/module/main.c b/kernel/module/main.c index d02d39c7174e..792ae226af5d 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1669,7 +1669,7 @@ static int elf_validity_check(struct load_info *info) info->hdr->e_type, ET_REL); goto no_exec; } - if (!elf_check_arch(info->hdr)) { + if (!module_elf_check_arch(info->hdr)) { pr_err("Invalid architecture in ELF header: %u\n", info->hdr->e_machine); goto no_exec;
As elf_check_arch() is used for native userspace executables, it checks the purecap EF_AARCH64_CHERI_PURECAP ELF flag when CONFIG_CHERI_PURECAP_UABI=y. This doesn't work for kernel modules which are not purecap binaries and don't have the flag. Use the newly defined module_elf_check_arch() helper to not require the flag for modules. This enables modules to be loaded on a PCuABI kernel.
Signed-off-by: Kristina Martsenko kristina.martsenko@arm.com --- arch/arm64/include/asm/elf.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h index 6189c8614dd6..73b3d9ef6a32 100644 --- a/arch/arm64/include/asm/elf.h +++ b/arch/arm64/include/asm/elf.h @@ -95,16 +95,10 @@ * This is used to ensure we don't load something for the wrong architecture. */ #ifdef CONFIG_CHERI_PURECAP_UABI -/* - * TODO [PCuABI] - elf_check_arch() is also used by the kernel module loader to - * verify the ELF headers. However, kernel modules, just like the kernel, are - * currently hybrid binaries and therefore do not have the - * EF_AARCH64_CHERI_PURECAP flag. As a result elf_check_arch() currently fails - * for kernel modules. This could be solved by introducing a new macro to check - * kernel modules. - */ #define elf_check_arch(x) ((x)->e_machine == EM_AARCH64 && \ (x)->e_flags & EF_AARCH64_CHERI_PURECAP) +#define module_elf_check_arch(x) ((x)->e_machine == EM_AARCH64 && \ + !((x)->e_flags & EF_AARCH64_CHERI_PURECAP)) #else #define elf_check_arch(x) ((x)->e_machine == EM_AARCH64) #endif
Add a few module test options to the Morello transitional defconfig, to enable kernel module loading to be tested. These are the modules used by the tests in tools/testing/selftests/lib/.
Signed-off-by: Kristina Martsenko kristina.martsenko@arm.com ---
LTP has more comprehensive module tests than kselftest but the LTP module tests are a bit limited at the moment: - they don't work with out-of-tree LTP builds (which Morello LTP uses) - they can't cross-build modules - they can't build modules with LLVM
From what I understand, there would also be problems with integrating the LTP module builds in the Morello CI. So using kselftest seems simpler for now. FWIW, I did manage to hack LTP enough to manually build and run the module tests and they all pass with this series.
To use kselftest, the steps are: make ARCH=arm64 LLVM=1 modules make INSTALL_MOD_PATH=/path/to/rootfs/ modules_install make -C tools/testing/selftests TARGETS="arm64 lib" ARM64_SUBTARGETS=morello ARCH=arm64 CC=clang install
Note, /sbin/modprobe needs to be present in the rootfs.
Also note, we don't really need to build all 6 modules, for example CONFIG_TEST_PRINTF alone would be enough, in that case run_kselftest.sh will just report SKIP for the others. Building them all may be simpler for the CI to handle, I'm not sure.
arch/arm64/configs/morello_transitional_pcuabi_defconfig | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/arch/arm64/configs/morello_transitional_pcuabi_defconfig b/arch/arm64/configs/morello_transitional_pcuabi_defconfig index 856806652bac..725360446392 100644 --- a/arch/arm64/configs/morello_transitional_pcuabi_defconfig +++ b/arch/arm64/configs/morello_transitional_pcuabi_defconfig @@ -153,6 +153,7 @@ CONFIG_KEYS=y CONFIG_SECURITY=y CONFIG_SECURITY_NETWORK=y CONFIG_SECURITY_SELINUX=y +CONFIG_PRIME_NUMBERS=m CONFIG_PRINTK_TIME=y CONFIG_DEBUG_KERNEL=y CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y @@ -162,4 +163,9 @@ CONFIG_DEBUG_FS=y # CONFIG_DEBUG_PREEMPT is not set # CONFIG_FTRACE is not set CONFIG_CORESIGHT=y +CONFIG_TEST_STRSCPY=m +CONFIG_TEST_PRINTF=m +CONFIG_TEST_SCANF=m +CONFIG_TEST_BITMAP=m +CONFIG_TEST_BITOPS=m CONFIG_MEMTEST=y
Hi Kristina,
On 10/05/2023 11:34, Kristina Martsenko wrote:
Hi,
Here are a few small patches to fix kernel module loading in the PCuABI kernel [1]. (Sorry about the delay!) There are some notes on testing in the third patch.
Thanks, Kristina
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/41
Kristina Martsenko (3): module: Allow arch overrides for ELF arch check arm64: elf: Enable module loading for PCuABI kernels
Works for me. Some of the eBPF kselftests use a kernel module as part of the tests. I was able to load and use that module with the above patches. Thanks for the fix.
Reviewed-by: Zachary Leaf zachary.leaf@arm.com Tested-by: Zachary Leaf zachary.leaf@arm.com
Thanks, Zach
arm64: morello: Add test modules to defconfig
note: I haven't run these test modules from patch 3
.../configs/morello_transitional_pcuabi_defconfig | 6 ++++++ arch/arm64/include/asm/elf.h | 10 ++-------- include/linux/moduleloader.h | 4 ++++ kernel/module/main.c | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-)
base-commit: 7f84d159d4eb989bf2f42d2e3b27a204cb3c1ec4
On 22/05/2023 20:01, Zachary Leaf wrote:
Hi Kristina,
On 10/05/2023 11:34, Kristina Martsenko wrote:
Hi,
Here are a few small patches to fix kernel module loading in the PCuABI kernel [1]. (Sorry about the delay!) There are some notes on testing in the third patch.
Thanks, Kristina
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/41
Kristina Martsenko (3): module: Allow arch overrides for ELF arch check arm64: elf: Enable module loading for PCuABI kernels
Works for me. Some of the eBPF kselftests use a kernel module as part of the tests. I was able to load and use that module with the above patches. Thanks for the fix.
Reviewed-by: Zachary Leaf zachary.leaf@arm.com Tested-by: Zachary Leaf zachary.leaf@arm.com
Sorry it took me so long to get to this. Thanks Kristina for the patches, they look good to me, and thanks Zach for the testing.
I tested LTP with the instructions provided in patch 3 and that worked just fine. I have now applied patch 1 and 2 on next.
I don't think we need patch 3, as this is for testing purposes only and these options are already available as a separate fragment (tools/testing/selftests/lib/config). The plan is now to get the CI to build the kernel + modules with this fragment and the additional kselftests.
Kevin
Thanks, Zach
arm64: morello: Add test modules to defconfig
note: I haven't run these test modules from patch 3
.../configs/morello_transitional_pcuabi_defconfig | 6 ++++++ arch/arm64/include/asm/elf.h | 10 ++-------- include/linux/moduleloader.h | 4 ++++ kernel/module/main.c | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-)
base-commit: 7f84d159d4eb989bf2f42d2e3b27a204cb3c1ec4
linux-morello mailing list -- linux-morello@op-lists.linaro.org To unsubscribe send an email to linux-morello-leave@op-lists.linaro.org
On 14/06/2023 15:31, Kevin Brodsky wrote:
On 22/05/2023 20:01, Zachary Leaf wrote:
Hi Kristina,
On 10/05/2023 11:34, Kristina Martsenko wrote:
Hi,
Here are a few small patches to fix kernel module loading in the PCuABI kernel [1]. (Sorry about the delay!) There are some notes on testing in the third patch.
Thanks, Kristina
[1] https://git.morello-project.org/morello/kernel/linux/-/issues/41
Kristina Martsenko (3): module: Allow arch overrides for ELF arch check arm64: elf: Enable module loading for PCuABI kernels
Works for me. Some of the eBPF kselftests use a kernel module as part of the tests. I was able to load and use that module with the above patches. Thanks for the fix.
Reviewed-by: Zachary Leaf zachary.leaf@arm.com Tested-by: Zachary Leaf zachary.leaf@arm.com
Sorry it took me so long to get to this. Thanks Kristina for the patches, they look good to me, and thanks Zach for the testing.
I tested LTP with the instructions provided in patch 3 and that worked just fine. I have now applied patch 1 and 2 on next.
I don't think we need patch 3, as this is for testing purposes only and these options are already available as a separate fragment (tools/testing/selftests/lib/config). The plan is now to get the CI to build the kernel + modules with this fragment and the additional kselftests.
Makes sense to me. Thank you!
Kristina
linux-morello@op-lists.linaro.org