【问题标题】:Unable to insert kernel module: Unknown symbol net_namespace_list无法插入内核模块:未知符号 net_namespace_list
【发布时间】:2018-02-07 09:50:15
【问题描述】:

我正在编写一个内核模块,它使用 for_each_net 列出网络命名空间,并编写了以下可以正常编译的 sn-p:

rtnl_lock();
for_each_net(net)
   printk("network ns: %p\n",  net);
rtnl_unlock();

但是,当我尝试插入内核模块时,出现以下错误:

insmod: ERROR: could not insert module kerNotification.ko: Unknown symbol in module

dmesg 给出了额外的错误信息:

[3561461.418499] kerNotification: Unknown symbol net_namespace_list (err 0)

kallsyms 表明它有这个核函数的符号:

[josh@dev kernel_prog(keystone_admin)]# cat /proc/kallsyms | grep net_namespace_list
ffffffff81a203e0 R __ksymtab_net_namespace_list
ffffffff81a32bc0 r __kcrctab_net_namespace_list
ffffffff81a55452 r __kstrtab_net_namespace_list
ffffffff81b6b000 D net_namespace_lis

Module.symvers 作为 KBUILD_EXTRA_SYMBOLS 包含在 makefile 中。这是 Makefile:

obj-m += kerNotification.o

SYMBOLA=/usr/src/kernels/4.4.57-1.el7.elrepo.x86_64/Module.symvers
KBUILD_EXTRA_SYMBOLS= $(SYMBOLA)

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

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

这是使用 V=1 构建 make 文件时的完整日志:

make -C /lib/modules/4.4.57-1.el7.elrepo.x86_64/build /usr/src/kernels/4.4.57-1.el7.elrepo.x86_64/Module.symvers M=/home/cmmdocker/kernel_prog modules
make[1]: Entering directory `/usr/src/kernels/4.4.57-1.el7.elrepo.x86_64'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || (                \
echo >&2;                                                       \
echo >&2 "  ERROR: Kernel configuration is invalid.";           \
echo >&2 "         include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";      \
echo >&2 ;                                                      \
/bin/false)
make[1]: Nothing to be done for `/usr/src/kernels/4.4.57-1.el7.elrepo.x86_64/Module.symvers'.
mkdir -p /home/cmmdocker/kernel_prog/.tmp_versions ; rm -f /home/cmmdocker/kernel_prog/.tmp_versions/*
make -f ./scripts/Makefile.build obj=/home/cmmdocker/kernel_prog
   rm -f /home/cmmdocker/kernel_prog/built-in.o; ar rcsD /home/cmmdocker/kernel_prog/built-in.o
  gcc -Wp,-MD,/home/cmmdocker/kernel_prog/.kerNotification.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include -I./arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated  -Iinclude -I./arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -fno-delete-null-pointer-checks -Wno-maybe-uninitialized -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -pg -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO  -DMODULE  -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(kerNotification)"  -D"KBUILD_MODNAME=KBUILD_STR(kerNotification)" -c -o /home/cmmdocker/kernel_prog/.tmp_kerNotification.o /home/cmmdocker/kernel_prog/kerNotification.c
/home/cmmdocker/kernel_prog/kerNotification.c: In function ‘kerNotification_init’:
/home/cmmdocker/kernel_prog/kerNotification.c:37:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     struct net *net;
     ^
  if [ "-pg" = "-pg" ]; then if [ /home/cmmdocker/kernel_prog/kerNotification.o != "scripts/mod/empty.o" ]; then ./scripts/recordmcount  "/home/cmmdocker/kernel_prog/kerNotification.o"; fi; fi;
(cat /dev/null;   echo kernel//home/cmmdocker/kernel_prog/kerNotification.ko;) > /home/cmmdocker/kernel_prog/modules.order
make -f ./scripts/Makefile.modpost
  find /home/cmmdocker/kernel_prog/.tmp_versions -name '*.mod' | xargs -r grep -h '\.ko$' | sort -u | sed 's/\.ko$/.o/' | scripts/mod/modpost -m -a -i ./Module.symvers -I /home/cmmdocker/kernel_prog/Module.symvers   -e /usr/src/kernels/4.4.57-1.el7.elrepo.x86_64/Module.symvers -o /home/cmmdocker/kernel_prog/Module.symvers   -w  -s -T -
  gcc -Wp,-MD,/home/cmmdocker/kernel_prog/.kerNotification.mod.o.d  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/4.8.5/include -I./arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated  -Iinclude -I./arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -fno-PIE -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -fno-delete-null-pointer-checks -Wno-maybe-uninitialized -O2 --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -pg -mfentry -DCC_USING_FENTRY -fno-inline-functions-called-once -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -DCC_HAVE_ASM_GOTO  -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(kerNotification.mod)"  -D"KBUILD_MODNAME=KBUILD_STR(kerNotification)" -DMODULE  -c -o /home/cmmdocker/kernel_prog/kerNotification.mod.o /home/cmmdocker/kernel_prog/kerNotification.mod.c
  ld -r -m elf_x86_64 -T ./scripts/module-common.lds --build-id  -o /home/cmmdocker/kernel_prog/kerNotification.ko /home/cmmdocker/kernel_prog/kerNotification.o /home/cmmdocker/kernel_prog/kerNotification.mod.o
make[1]: Leaving directory `/usr/src/kernels/4.4.57-1.el7.elrepo.x86_64'

知道如何解决这个问题吗?

【问题讨论】:

标签: linux-kernel kernel-module


【解决方案1】:

问题是缺少许可证。添加以下内容以获得预期结果:

MODULE_LICENSE("GPL");

为此从另一个关于 stackoverflow 的查询中引用了以下答案:unknown-symbol-class-create-err-0

【讨论】:

    【解决方案2】:

    insmod:错误:无法插入模块 kerNotification.ko:未知 模块中的符号

    您收到上述错误是因为内核中缺少 net_namespace_list。所以你需要确保插入它定义的模块。查看它在net_namespace.c 中声明的源代码并查看Makefile 它会在启用 CONFIG_NET 时。此外,当您构建内核映像时,System.map 文件应该告诉您它是否在您构建的内核映像中声明,如下所示:

    猫系统.map | grep net_namespace_list

    8041a888 r __ksymtab_net_namespace_list

    8042b80c r __kstrtab_net_namespace_list

    80464c08 D net_namespace_list

    【讨论】:

    • 如果定义的模块被插入并验证在构建的内核映像的 System.map 中,则可能的原因之一可能是在这种情况下缺少许可证。参考:stackoverflow.com/questions/29578931/…
    猜你喜欢
    • 1970-01-01
    • 2012-09-27
    • 2012-08-06
    • 2015-01-15
    • 1970-01-01
    • 2020-09-30
    • 2012-02-26
    • 2017-03-31
    • 2012-12-21
    相关资源
    最近更新 更多