简体   繁体   中英

how to sign my own kernel module in linux?

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: https://unix.stackexchange.com/questions/560895/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

A workaround is to build the module with that line in Makefile:

#this line fix the problem. tomrtc
CONFIG_MODULE_SIG=n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM