Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross-built kernel cannot load externally-built modules #51005

Closed
classabbyamp opened this issue Jun 26, 2024 · 0 comments
Closed

cross-built kernel cannot load externally-built modules #51005

classabbyamp opened this issue Jun 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@classabbyamp
Copy link
Member

classabbyamp commented Jun 26, 2024

System Info

Void 6.8.12_2 aarch64-glibc

Package(s) Affected

linux6.8 at minimum, probably other linux6.* kernels (rpi-kernel is not affected)

if the kernel is built natively, this issue does not occur

Expected behaviour

externally-built (dkms or other mechanism) modules load successfully

nm --print-size --size-sort hello.ko | grep __this_module       
0000000000000000 0000000000000500 D __this_module

Actual behaviour

# modprobe ./hello.ko
modprobe: ERROR: could not insert 'hello': Exec format error

dmesg:

[...] module hello: .gnu.linkonce.this_module section size must match the kernel's built struct module size at run time
nm --print-size --size-sort hello.ko | grep __this_module
0000000000000000 00000000000004c0 D __this_module

Steps to reproduce

mkdir -p hello-mod && cd hello-mod

cat <<EOF > Makefile 
obj-m += hello.o

PWD := $(CURDIR)

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
EOF

cat <<EOF > hello.c
#include <linux/module.h>
#include <linux/printk.h>

int init_module(void) {
    pr_info("hello");
    return 0;
}

void cleanup_module(void) {
    pr_info("goodbye");
}

MODULE_LICENSE("GPL");
EOF

make
sudo modprobe ./hello.ko

Notes

Error message introduced by https://lore.kernel.org/lkml/[email protected]/T/

@classabbyamp classabbyamp added the bug Something isn't working label Jun 26, 2024
atweiden added a commit to atweiden/voidpkgs that referenced this issue Jun 26, 2024
CONFIG_DEBUG_INFO_BTF_MODULES is enabled on most/all void kernels, and
thus pahole is used when generating BTF information during compilation of
external modules. on cross-built kernels, the absence of pahole will
remove CONFIG_DEBUG_INFO_BTF_MODULES from
/usr/src/kernel-headers-$version/include/generated/autoconf.h when
the dkms kernel.d hook runs for the first time (because cross-built
kernels have their host tools removed).

When this is removed, part of the module struct in include/linux/module.h
is missing, resulting in a mismatch in the size of the __this_module
struct (.gnu.link_once.this_module section of the .ko) in external
modules of exactly 64 bytes.

	struct module {
	// ...
	#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
	 unsigned int btf_data_size;
	 void *btf_data;
	#endif
	// ...
	}

fixes void-linux/void-packages#51005

void-linux/void-packages@98f0d74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant