0

I write a simple hello world kernel module in Linux and I tried to load it to the kernel. but it was not possible because I get this error while I want to load it.

module verification failed: signature and/or required key missing - tainting kernel

I tried to find a solution for that but all of that found was about VM and not a real system.

my secure boot is disabled and I don't want to change kernel config and rebuild it.

I also tried to create a key with openssl and MOK and enroll it but in the last step that tries to sign module, I stopped because of No such file or directory error. I can't find /scripts/sign-file in /usr/lib/linux-headers-5.11.0-16-generic

I followed the answer to this question: Sign Kernel Modules

I am completely confused! can anyone help me??

my os is ubuntu and the kernel version is 5.11.0-16

UPDATE: now I understand my module seems to be signed via command modinfo hello.ko and this is the result:

$ modinfo hello.ko
filename:       /home/###/Documents/kernel/hello.ko
description:    This is the module description.
author:         ###
license:        Dual BSD/GPL
depends:        
retpoline:      Y
name:           hello
vermagic:       5.11.0-16-generic SMP mod_unload modversions 
sig_id:         PKCS#7
signer:         ###
sig_key:        58:26:4E:F2:6A:5F:2F:DB:F0:21:E0:8C:79:60:E9:C8:78:38:01:3F
sig_hashalgo:   sha256
signature:      67:F2:74:BF:6A:AB:D4:AD:6C:EA:BD:35:D6:7A:9A:94:0F:C7:0F:6B:
        AD:10:18:26:D1:D9:8A:07:DD:89:36:03:D0:C9:AA:10:A1:52:71:A0:
        CF:D0:7D:C6:2E:D7:E2:B1:AF:1D:45:A4:97:13:23:23:C8:B7:99:6D:
        4A:F9:60:B7:64:D0:E4:3C:EE:74:9F:68:D2:C5:EC:C0:C9:F3:09:76:
        EF:B5:C4:46:62:36:1B:95:EC:4A:D3:4D:B7:2F:87:71:E1:D2:D7:ED:
        EE:F3:04:58:3F:F9:EA:16:4C:39:BD:B5:50:60:FC:A7:96:AF:03:74:
        F0:03:76:98:95:91:A9:5A:1B:50:17:8A:71:A2:C0:D6:B4:DD:D3:50:
        FE:2A:05:29:03:D6:E6:A0:69:F4:18:44:2B:EC:F6:41:6D:A3:E7:EF:
        10:3D:98:A8:33:21:56:0E:D6:8E:67:88:18:7F:31:DB:2E:CA:70:F7:
        7E:03:42:04:F5:99:64:BD:EE:0F:04:DA:56:50:B5:2E:7A:B7:AE:D0:
        ED:07:6B:86:89:45:38:B4:7C:FE:B9:B3:F4:5D:17:1B:6F:04:33:52:
        BE:0E:1F:D3:CA:F1:9D:17:AD:EC:A4:DC:84:25:47:73:ED:02:9E:74:
        4C:AD:25:35:2B:E4:C0:BE:15:F2:FF:99:CE:89:82:E6

but still I get error while inserting module:

$ sudo insmod hello.ko
insmod: ERROR: could not insert module hello.ko: Invalid module format
0
2
module verification failed: signature and/or required key missing - tainting kernel

This does not mean your module did not load. All it means is any kernel oops/panic messages will have a bit of information indicating that you have (or had at some point) an unsigned module loaded. This message is just a warning, not an error.

(But if you try to submit a kernel bug report that includes oops/panic messages with a taint mark, you'll very likely get a response "please try and reproduce the bug without any non-standard kernel modules first, or show the source code of your custom module as it might be relevant in troubleshooting the bug". This tends to save the time of kernel developers and distribution maintainers, as people sometimes submit bug reports without mentioning that they are trying something experimental.)

Debian packages the sign-file utility into a linux-kbuild-<kernel version> package. and I believe Ubuntu does the same. So you would need to make sure the package linux-kbuild-5.11 is installed. The path of the sign-file utility would be /usr/lib/linux-kbuild-5.11/scripts/sign-file.

However, when Secure Boot is disabled, the shimx64.efi will just directly load the real grubx64.efi bypassing all the Secure Boot steps, including loading the MOK. With the MOK not loaded, the kernel will have no way to recognize the signature on your module as valid. And with Secure Boot disabled, a signed module with an invalid signature is rejected, while unsigned modules only get a warning and a taint mark on any future oops/panic messages.

insmod: ERROR: could not insert module hello.ko: Invalid module format

After any kernel module loading failure, you should check the dmesg output: it might include a more specific error message. In this case it is likely to indicate that a module signature failed a validity check.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.