Linux insmod:init_module 失败(Exec 格式错误)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16562102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:56:33  来源:igfitidea点击:

insmod: init_module failed (Exec format error)

androidlinuxmodulekernel

提问by user12295

I'm able to compile kernel module for Galaxy S4 Kernel 3.4.xx but I get following errors during module insertion. could someone please shed some light on what's missing here.

我能够为 Galaxy S4 Kernel 3.4.xx 编译内核模块,但在模块插入过程中出现以下错误。有人可以解释一下这里缺少什么吗?

The kernel module is a plain helloworld module with basic init and cleanup functions.

内核模块是一个普通的 helloworld 模块,具有基本的初始化和清理功能。

insmod error:

insmod 错误:

   insmod /data/local/tmp/testHello.ko
   insmod: init_module '/data/local/tmp/testHello.ko' failed (Exec format error)

Dmesg logs

消息日志

   <4>[ 2127.554107] TIMA: lkmauth--launch the tzapp to check kernel module; module  len  is 71334
   <4>[ 2127.554168] TIMA: lkmauth -- hdr before kreq is : e337b000
   <4>[ 2127.554199] TIMA: lkmauth--send cmd (lkmauth) cmdlen(304:320), rsplen(264:320)   id 0x00050000,                 req (0xE352A000), rsp(0xE352A140),  module_start_addr(0xE337B000) module_len 71334
   <3>[ 2127.581909] TIMA: lkmauth--verification failed -1
   <4>[ 2127.582183] TIMA: MSG=lkm_modified; result (TIMA_RESULT=MSG=lkm_modified;) 
   <6>[2129.417541] [debug_wake_locks]active wake lock msm_otg

回答by Technologeeks

Your answer is right there in the dmesg log: The S4 kernel is hardened to only accept modules which are authenticated (i.e. digitally signed). Your compiled module is not thus signed, so init_module failed (though arguably the return code could have been better - exec format error usually means the ELF is malformed, which it technically isn't).

您的答案就在 dmesg 日志中:S4 内核被强化为仅接受经过身份验证(即数字签名)的模块。您编译的模块未因此签名,因此 init_module 失败(尽管可以说返回代码可能会更好 - exec 格式错误通常意味着 ELF 格式错误,从技术上讲并非如此)。

Check the modules that came with the S4 (/system/lib/modules or /vendor/lib/modules) with mod info (on Linux), and you'll see the ELF section with the signature. This is a feature that mainstream Linux has also added, in 3.7.

检查 S4 附带的模块(/system/lib/modules 或 /vendor/lib/modules)和 mod info(在 Linux 上),您将看到带有签名的 ELF 部分。这是主流 Linux 在 3.7 中也添加的功能。