本文共 4230 字,大约阅读时间需要 14 分钟。
hello.c
#include/*Needed by all modules*/#include /*Needed for KERN_* */#include /* Needed for the macros */#include #include MODULE_LICENSE("GPL");static int hello_init(void){printk(KERN_WARNING "the process is\"%d\"(pid %i)\n",current->comm, current->pid); return 0;}static void hello_exit(void){ printk("Bye, kernel!\n");}/* main module function*/module_init(hello_init);module_exit(hello_exit);
root@ubuntu:~/Desktop# insmod ./hello.koroot@ubuntu:~/Desktop# tail /var/log/kern.logAug 26 07:05:06 ubuntu kernel: [ 38.280651] audit: type=1400 audit(1535292306.730:64): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="/usr/sbin/cupsd" pid=2130 comm="apparmor_parser"Aug 26 07:19:41 ubuntu kernel: [ 913.186836] e1000: eth0 NIC Link is DownAug 26 07:19:45 ubuntu kernel: [ 917.188835] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: NoneAug 26 07:22:25 ubuntu kernel: [ 1076.499433] e1000: eth0 NIC Link is DownAug 26 07:22:29 ubuntu kernel: [ 1080.499470] e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: NoneAug 26 07:31:10 ubuntu kernel: [ 1602.402400] hello: module verification failed: signature and/or required key missing - tainting kernelAug 26 07:31:10 ubuntu kernel: [ 1602.408784] Hello kernel, it's 2018!Aug 26 07:31:10 ubuntu kernel: [ 1602.408792] the process is"1383225440"(pid 3571)Aug 26 07:32:39 ubuntu kernel: [ 1691.260987] Bye, kernel!Aug 26 07:33:50 ubuntu kernel: [ 1762.382921] the process is"1656784352"(pid 3890)root@ubuntu:~/Desktop#
lsmod
root@ubuntu:~/Desktop# lsmodModule Size Used byhello 16384 0 coretemp 16384 0 crct10dif_pclmul 16384 0 crc32_pclmul 16384 0 aesni_intel 167936 0 snd_ens1371 28672 0 snd_ac97_codec 131072 1 snd_ens1371aes_x86_64 20480 1 aesni_intelgameport 16384 1 snd_ens1371ac97_bus 16384 1 snd_ac97_codecvmw_balloon 16384 0 lrw 16384 1 aesni_intelgf128mul 16384 1 lrwglue_helper 16384 1 aesni_intelablk_helper 16384 1 aesni_intelsnd_pcm 102400 2 snd_ac97_codec,snd_ens1371cryptd 20480 2 aesni_intel,ablk_helpersnd_seq_midi 16384 0 snd_seq_midi_event 16384 1 snd_seq_midiinput_leds 16384 0 joydev 20480 0 serio_raw 16384 0 snd_rawmidi 32768 2 snd_ens1371,snd_seq_midisnd_seq 69632 2 snd_seq_midi_event,snd_seq_midivmwgfx 172032 3 snd_seq_device 16384 3 snd_seq,snd_rawmidi,snd_seq_midittm 94208 1 vmwgfxsnd_timer 32768 2 snd_pcm,snd_seqbtusb 45056 0 drm_kms_helper 126976 1 vmwgfxsnd 81920 7 snd_ac97_codec,snd_timer,snd_pcm,snd_seq,snd_rawmidi,snd_ens1371,snd_seq_devicebtrtl 16384 1 btusbbtbcm 16384 1 btusbbtintel 16384 1 btusbdrm 360448 6 ttm,drm_kms_helper,vmwgfxsoundcore 16384 1 sndvmw_vmci 65536 0 i2c_piix4 24576 0 shpchp 36864 0 nfit 32768 0 rfcomm 69632 8 bnep 20480 2 8250_fintek 16384 0 bluetooth 512000 25 bnep,btbcm,btrtl,btusb,rfcomm,btintelbinfmt_misc 20480 1 mac_hid 16384 0 parport_pc 32768 0 ppdev 20480 0 lp 20480 0 parport 49152 3 lp,ppdev,parport_pchid_generic 16384 0 usbhid 49152 0 hid 118784 2 hid_generic,usbhidpsmouse 126976 0 mptspi 24576 2 mptscsih 40960 1 mptspimptbase 98304 2 mptspi,mptscsihahci 36864 0 libahci 32768 1 ahcie1000 131072 0 scsi_transport_spi 32768 1 mptspipata_acpi 16384 0 root@ubuntu:~/Desktop#
转载于:https://blog.51cto.com/haidragon/2165107