hello-1.ko segfaults when ran
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 56/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c, linux
- Domain
- operating-systems
Research direction
Start by reading the hello-1 and spinlock module examples and the devtools/test-modules.sh output; the trace reports “Missing ENDBR” while loading hello-1.ko on kernel 6.12.6. Reproduce with the provided VM setup and compare why those two modules fail while the others pass. Done means identifying and documenting a fix or supported setup that lets both modules load successfully.
Written by the indexing model from the issue text.
Description
first I'd have to say this looks like an amazing project and really useful for me as I've been trying to get into kmod programming recently.
I have an artix linux system with QEMU is installed from libvirt (and virt-manager) and the tools needed for a kernel build already installed (as I did build a kernel previously on this device)
following at the webpage (at github.io) I've cloned the repo, ran devtools/setup.sh (which downloaded prebuilt kernel 6.12.6) then devtools/build-modules.sh and devtools/boot.sh
in the vm it suggested i insmod /mnt/lkmpg/examples/hello-1.ko but running it produced a trace complaining of a segfault
same when running devtools/test-modules.sh which had hello-1 and startstop both fail (all other modules passed)
here is the trace from test-modules.sh:
[ 16.968514] Missing ENDBR: init_module+0x0/0x20 [hello_1]
[ 16.969024] ------------[ cut here ]------------
[ 16.969424] kernel BUG at arch/x86/kernel/cet.c:102!
[ 16.969848] Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
[ 16.970399] CPU: 0 UID: 0 PID: 171 Comm: insmod Tainted: G O 6.12.6 #1
[ 16.971356] Tainted: [O]=OOT_MODULE
[ 16.971860] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.14
[ 16.972688] RIP: 0010:exc_control_protection+0xb8/0xc0
[ 16.973136] Code: 00 74 0f 90 89 ee 48 89 df 5b 5d 41 5c e9 40 07 00 00 4c 89 e6 48 890
[ 16.974736] RSP: 0018:ffffc90000193d18 EFLAGS: 00010002
[ 16.975180] RAX: 000000000000002d RBX: ffffc90000193d38 RCX: 0000000000000000
[ 16.976783] RDX: 0000000000000000 RSI: ffffc90000193bd0 RDI: 0000000000000001
[ 16.977387] RBP: 0000000000000000 R08: 00000000ffffdfff R09: 0000000000000001
[ 16.978120] R10: 00000000ffffdfff R11: ffffffff82658920 R12: 0000000000000003
[ 16.979158] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[ 16.980053] FS: 000000000d4643c0(0000) GS:ffff88801f400000(0000) knlGS:000000000000000
[ 16.980852] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 16.981473] CR2: 00007f0ceb58d000 CR3: 00000000041f6000 CR4: 0000000000f50ef0
[ 16.982877] PKRU: 55555554
[ 16.983422] Call Trace:
[ 16.983810] <TASK>
[ 16.984004] ? die+0x31/0x80
[ 16.984273] ? do_trap+0xd8/0x100
[ 16.984607] ? exc_control_protection+0xb8/0xc0
[ 16.985005] ? do_error_trap+0x60/0x80
[ 16.985392] ? exc_control_protection+0xb8/0xc0
[ 16.986304] ? exc_invalid_op+0x51/0x70
[ 16.986906] ? exc_control_protection+0xb8/0xc0
[ 16.987314] ? asm_exc_invalid_op+0x1a/0x20
[ 16.987727] ? exc_control_protection+0xb8/0xc0
[ 16.988244] ? exc_control_protection+0x4e/0xc0
[ 16.989117] asm_exc_control_protection+0x26/0x40
[ 16.989796] RIP: 0010:init_module+0x0/0x20 [hello_1]
[ 16.990267] Code: Unable to access opcode bytes at 0xffffffff9fffffe6.
[ 16.990920] RSP: 0018:ffffc90000193de0 EFLAGS: 00010246
[ 16.991621] RAX: 0000000000000000 RBX: ffffffffa0000010 RCX: 0000000000000000
[ 16.992671] RDX: 0000000000000000 RSI: ffffffffa0000010 RDI: ffffc90000193dc8
[ 16.993353] RBP: 0000000000000000 R08: 0000000000000020 R09: 0000000000000000
[ 16.993966] R10: ffffc90000193e58 R11: 0000000000000000 R12: 00007f0ceb5b3710
[ 16.994763] R13: ffffc90000193de8 R14: 00000000006281bf R15: ffffc90000193e80
[ 16.995671] ? __pfx_init_module+0x10/0x10 [hello_1]
[ 16.996155] ? __pfx_init_module+0x10/0x10 [hello_1]
[ 16.996627] do_one_initcall+0x53/0x220
[ 16.996975] do_init_module+0x5b/0x200
[ 16.997328] __do_sys_init_module+0x152/0x180
[ 16.997919] ? __rseq_handle_notify_resume+0x297/0x4d0
[ 16.998703] do_syscall_64+0x9e/0x1a0
[ 16.999249] entry_SYSCALL_64_after_hwframe+0x77/0x7f
[ 17.000044] RIP: 0033:0x48c56d
[ 17.000642] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f78
[ 17.002835] RSP: 002b:00007ffc826eabd8 EFLAGS: 00000246 ORIG_RAX: 00000000000000af
[ 17.003862] RAX: ffffffffffffffda RBX: 00000000006281bf RCX: 000000000048c56d
[ 17.004646] RDX: 00000000006281bf RSI: 0000000000026700 RDI: 00007f0ceb58d010
[ 17.005651] RBP: 00007ffc826eaf70 R08: 0000000000000007 R09: 0000000000000000
[ 17.006542] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffc826eaf78
[ 17.007168] R13: 00007ffc826eaf80 R14: 00000000006281bf R15: 0000000000000001
[ 17.007832] </TASK>
[ 17.008102] Modules linked in: hello_1(O+) [last unloaded: example_tasklet(O)]
[ 17.008925] ---[ end trace 0000000000000000 ]---
[ 17.009447] RIP: 0010:exc_control_protection+0xb8/0xc0
[ 17.010014] Code: 00 74 0f 90 89 ee 48 89 df 5b 5d 41 5c e9 40 07 00 00 4c 89 e6 48 890
[ 17.012146] RSP: 0018:ffffc90000193d18 EFLAGS: 00010002
[ 17.012857] RAX: 000000000000002d RBX: ffffc90000193d38 RCX: 0000000000000000
[ 17.013837] RDX: 0000000000000000 RSI: ffffc90000193bd0 RDI: 0000000000000001
[ 17.014872] RBP: 0000000000000000 R08: 00000000ffffdfff R09: 0000000000000001
[ 17.015911] R10: 00000000ffffdfff R11: ffffffff82658920 R12: 0000000000000003
[ 17.016960] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[ 17.018033] FS: 000000000d4643c0(0000) GS:ffff88801f400000(0000) knlGS:000000000000000
[ 17.019150] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 17.020067] CR2: ffffffff9fffffe6 CR3: 00000000041f6000 CR4: 0000000000f50ef0
[ 17.021223] PKRU: 55555554
[ 17.021725] note: insmod[171] exited with irqs disabled
[ 17.022781] insmod (171) used greatest stack depth: 13264 bytes left
Segmentation fault
LKMPG:FAIL hello-1
(I assume this doesn't matter and is just a product of busybox being the init but it may be relevant to say that poweroff -d 0 or -d 1 does not power off the VM and poweroff -f is needed)
if the problem is on my part please tell me and if any other info is needed I'd be happy to provide it.
regards
EDIT:
replicated on a newer version
error seems to be fixed when lifecycle functions are migrated from int init_module(void) to static int __init init_func_name(void) that gets called by module_init(init_func_name)
guess this means these two and the book are a bit outdated, let me know if you want me to open a pr about hello-1 and maybe the book, as startstop already has #390
- Dominant language
- TeX
- Stars
- 8.7k
- Forks
- 625
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sysprog21/lkmpg
-
4.6 Modules Spanning Multiple Files examples should be updated with new init syntaxPossibly taken @RehanChalana claimed this 38 days ago. Open
Difficulty 1/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 4/5 1-2 days Newbie friendliness 52/100
-
generated HTML book have many disarragement.Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
New firmware
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
MControlSuite/msi-ec#905 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
OpenXiangShan/NEMU#1314 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
riscv-software-src/riscv-isa-sim#2622 ·
Maintainers usually reply within 1 day
-
autofs: close file descriptor on error in autofs_find_read_fd()Possibly taken @muskan-creates352 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
checkpoint-restore/criu#3402 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
CachyOS/distribution#648 ·