第一次通过insmod kernel_test.ko,并rmmod kernel_test成功
第二次加载并删除的时候提示模块在使用
rmmod kernel_test
rmmod: ERROR: Module kernel_test is in use
lsmod查看确实kernel_test 使用次数为1.
lsmod | grep test
kernel_test 16384 1
那么现在该如何卸载这个模块呢, rmmod -f 用过了也不行
rmmod -f kernel_test
rmmod: ERROR: ../libkmod/libkmod-module.c:793 kmod_module_remove_module() could not remove 'kernel_test': Device or resource busy
rmmod: ERROR: could not remove module kernel_test: Device or resource busy
源代码如下:
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
static int pid;
module_param(pid,int,0644);
static int __init memtest_init(void)
{
struct task_struct *p;
struct vm_area_struct *temp;
printk("The virtual memory areas(VMA) are:\n");
p=pid_task(find_vpid(pid),PIDTYPE_PID);
// p=find_task_by_vpid(pid);
temp=p->mm->mmap;
while(temp)
{
printk("start:%p\tend:%p\n",(unsigned long *)temp->vm_start,(unsigned long *)temp->vm_end);
temp=temp->vm_next;
}
return 0;
}
static void __exit memtest_exit(void)
{
printk("Unloading my module.\n");
return;
}
module_init(memtest_init);
module_exit(memtest_exit);
MODULE_LICENSE("GPL");
内核模块删除失败
-
- 帖子: 11
- 注册时间: 2018-12-29 14:13
- 系统: ubuntu
- astolia
- 论坛版主
- 帖子: 6703
- 注册时间: 2008-09-18 13:11
Re: 内核模块删除失败
我怀疑是你的模块出错挂掉了,这种情况下只能重启。
第二次insmod时没有报错吗?dmesg中有没有什么错误内容?
第二次insmod时没有报错吗?dmesg中有没有什么错误内容?
-
- 帖子: 11
- 注册时间: 2018-12-29 14:13
- 系统: ubuntu
Re: 内核模块删除失败
Unloading my module.
第一次卸载成功,然后第二次加载的时候,没有打印出具体的虚拟地址。可能是我的pid输出了导致的
[1535943.288485] The virtual memory areas(VMA) are:
[1535943.288499] BUG: unable to handle kernel NULL pointer dereference at 00000000000007f8
[1535943.288520] IP: memtest_init+0x34/0x1000 [kernel_test]
[1535943.288526] PGD 0 P4D 0
[1535943.288537] Oops: 0000 [#1] SMP PTI
[1535943.288542] Modules linked in: kernel_test(OE+) uas usb_storage btrfs zstd_compress xor raid6_pq ufs qnx4 hfsplus hfs minix ntfs msdos jfs xfs libcrc32c cpuid nfnetlink_queue nfnetlink_log nfnetlink pl2303 usbserial rfcomm appletalk ipx p8023 psnap p8022 aufs overlay cmac bnep binfmt_misc nls_iso8859_1 snd_soc_skl snd_soc_skl_ipc snd_hda_ext_core snd_soc_sst_dsp snd_soc_sst_ipc snd_soc_acpi uvcvideo videobuf2_vmalloc videobuf2_memops snd_soc_core videobuf2_v4l2 snd_compress ac97_bus snd_pcm_dmaengine videobuf2_core videodev media rtsx_usb_ms snd_hda_codec_hdmi hid_multitouch intel_rapl wmi_bmof dell_wmi snd_hda_codec_realtek snd_hda_codec_generic memstick x86_pkg_temp_thermal intel_powerclamp coretemp dell_laptop kvm_intel kvm dell_smbios btusb dell_wmi_descriptor arc4 irqbypass snd_hda_intel dcdbas
[1535943.288655] btrtl btbcm dell_smm_hwmon crct10dif_pclmul crc32_pclmul ghash_clmulni_intel btintel pcbc snd_hda_codec snd_hda_core snd_hwdep snd_pcm bluetooth i915 ecdh_generic ath10k_pci ath10k_core snd_seq_midi aesni_intel snd_seq_midi_event nouveau snd_rawmidi ath mac80211 aes_x86_64 mxm_wmi crypto_simd snd_seq snd_seq_device cfg80211 ttm drm_kms_helper joydev input_leds snd_timer glue_helper drm cryptd idma64 virt_dma intel_lpss_pci snd soundcore shpchp mac_hid i2c_algo_bit fb_sys_fops syscopyarea mei_me mei intel_cstate intel_rapl_perf serio_raw sysfillrect sysimgblt intel_lpss processor_thermal_device int3400_thermal int3402_thermal intel_pch_thermal intel_soc_dts_iosf int3403_thermal video acpi_thermal_rel int340x_thermal_zone intel_hid wmi acpi_pad sparse_keymap sch_fq_codel iptable_filter
出现这种情况只能重启?没有其他办法?
第一次卸载成功,然后第二次加载的时候,没有打印出具体的虚拟地址。可能是我的pid输出了导致的
[1535943.288485] The virtual memory areas(VMA) are:
[1535943.288499] BUG: unable to handle kernel NULL pointer dereference at 00000000000007f8
[1535943.288520] IP: memtest_init+0x34/0x1000 [kernel_test]
[1535943.288526] PGD 0 P4D 0
[1535943.288537] Oops: 0000 [#1] SMP PTI
[1535943.288542] Modules linked in: kernel_test(OE+) uas usb_storage btrfs zstd_compress xor raid6_pq ufs qnx4 hfsplus hfs minix ntfs msdos jfs xfs libcrc32c cpuid nfnetlink_queue nfnetlink_log nfnetlink pl2303 usbserial rfcomm appletalk ipx p8023 psnap p8022 aufs overlay cmac bnep binfmt_misc nls_iso8859_1 snd_soc_skl snd_soc_skl_ipc snd_hda_ext_core snd_soc_sst_dsp snd_soc_sst_ipc snd_soc_acpi uvcvideo videobuf2_vmalloc videobuf2_memops snd_soc_core videobuf2_v4l2 snd_compress ac97_bus snd_pcm_dmaengine videobuf2_core videodev media rtsx_usb_ms snd_hda_codec_hdmi hid_multitouch intel_rapl wmi_bmof dell_wmi snd_hda_codec_realtek snd_hda_codec_generic memstick x86_pkg_temp_thermal intel_powerclamp coretemp dell_laptop kvm_intel kvm dell_smbios btusb dell_wmi_descriptor arc4 irqbypass snd_hda_intel dcdbas
[1535943.288655] btrtl btbcm dell_smm_hwmon crct10dif_pclmul crc32_pclmul ghash_clmulni_intel btintel pcbc snd_hda_codec snd_hda_core snd_hwdep snd_pcm bluetooth i915 ecdh_generic ath10k_pci ath10k_core snd_seq_midi aesni_intel snd_seq_midi_event nouveau snd_rawmidi ath mac80211 aes_x86_64 mxm_wmi crypto_simd snd_seq snd_seq_device cfg80211 ttm drm_kms_helper joydev input_leds snd_timer glue_helper drm cryptd idma64 virt_dma intel_lpss_pci snd soundcore shpchp mac_hid i2c_algo_bit fb_sys_fops syscopyarea mei_me mei intel_cstate intel_rapl_perf serio_raw sysfillrect sysimgblt intel_lpss processor_thermal_device int3400_thermal int3402_thermal intel_pch_thermal intel_soc_dts_iosf int3403_thermal video acpi_thermal_rel int340x_thermal_zone intel_hid wmi acpi_pad sparse_keymap sch_fq_codel iptable_filter
出现这种情况只能重启?没有其他办法?
- astolia
- 论坛版主
- 帖子: 6703
- 注册时间: 2008-09-18 13:11
Re: 内核模块删除失败
显然是由于你没有检查pid_task的返回值是否为NULL,导致后面使用了空指针。maple_169324 写了: ↑2019-07-05 16:13 [1535943.288499] BUG: unable to handle kernel NULL pointer dereference at 00000000000007f8
不检查函数返回值的坏习惯你一定要改
是的。这种低级错误根本不应该发生在内核空间
-
- 帖子: 11
- 注册时间: 2018-12-29 14:13
- 系统: ubuntu
Re: 内核模块删除失败
还有个问题。怎么虚拟空间地址,内核打印出来的和进程信息里面记录的不一样呢astolia 写了: ↑2019-07-05 18:08显然是由于你没有检查pid_task的返回值是否为NULL,导致后面使用了空指针。maple_169324 写了: ↑2019-07-05 16:13 [1535943.288499] BUG: unable to handle kernel NULL pointer dereference at 00000000000007f8
不检查函数返回值的坏习惯你一定要改
是的。这种低级错误根本不应该发生在内核空间
dmesg打印消息
[112915.124655] The virtual memory areas(VMA) are:
[112915.124666] start:00000000d169318f end:0000000007ee3a45
[112915.124669] start:00000000aacfc2d9 end:000000002ea70550
[112915.124671] start:000000002ea70550 end:00000000a98c052e
[112915.124674] start:00000000a7f20ccd end:00000000c60364f8
[112915.124676] start:00000000e9fe2468 end:00000000aa97b07b
[112915.124679] start:00000000aa97b07b end:000000008cb124f1
[112915.124681] start:000000008cb124f1 end:0000000015f30b6d
[112915.124684] start:0000000015f30b6d end:000000006484b277
[112915.124686] start:000000006484b277 end:000000009f1c0100
[112915.124688] start:000000009f1c0100 end:00000000f49f4d03
[112915.124691] start:00000000cdb9847d end:00000000abc48099
[112915.124693] start:00000000b0f46c4b end:000000001ec4d87b
[112915.124696] start:000000001ec4d87b end:000000001165af8e
[112915.124698] start:000000001165af8e end:00000000c9d2b88a
[112915.124701] start:0000000076c470de end:000000008716dfe2
[112915.124703] start:0000000072ed6763 end:0000000054306655
[112915.124706] start:0000000054306655 end:0000000045885e23
进程中的地址
cat /proc/3638/maps
55807106c000-55807106d000 r-xp 00000000 08:02 51380262 /home/wuqi/c_prj/linux/chapter4_5/test/exam
55807126c000-55807126d000 r--p 00000000 08:02 51380262 /home/wuqi/c_prj/linux/chapter4_5/test/exam
55807126d000-55807126e000 rw-p 00001000 08:02 51380262 /home/wuqi/c_prj/linux/chapter4_5/test/exam
5580721a1000-5580721c2000 rw-p 00000000 00:00 0 [heap]
7f9b71f6c000-7f9b72153000 r-xp 00000000 08:02 51380520 /lib/x86_64-linux-gnu/libc-2.27.so
7f9b72153000-7f9b72353000 ---p 001e7000 08:02 51380520 /lib/x86_64-linux-gnu/libc-2.27.so
7f9b72353000-7f9b72357000 r--p 001e7000 08:02 51380520 /lib/x86_64-linux-gnu/libc-2.27.so
7f9b72357000-7f9b72359000 rw-p 001eb000 08:02 51380520 /lib/x86_64-linux-gnu/libc-2.27.so
7f9b72359000-7f9b7235d000 rw-p 00000000 00:00 0
7f9b7235d000-7f9b72384000 r-xp 00000000 08:02 51380516 /lib/x86_64-linux-gnu/ld-2.27.so
7f9b72566000-7f9b72568000 rw-p 00000000 00:00 0
7f9b72584000-7f9b72585000 r--p 00027000 08:02 51380516 /lib/x86_64-linux-gnu/ld-2.27.so
7f9b72585000-7f9b72586000 rw-p 00028000 08:02 51380516 /lib/x86_64-linux-gnu/ld-2.27.so
7f9b72586000-7f9b72587000 rw-p 00000000 00:00 0
7ffc13aa8000-7ffc13ac9000 rw-p 00000000 00:00 0 [stack]
7ffc13b89000-7ffc13b8c000 r--p 00000000 00:00 0 [vvar]
7ffc13b8c000-7ffc13b8e000 r-xp 00000000 00:00 0 [vdso]
- astolia
- 论坛版主
- 帖子: 6703
- 注册时间: 2008-09-18 13:11