hello.c
#include <linux/kernel.h> /*Needed by all modules*/#include <linux/module.h> /*Needed for KERN_* */#include <linux/init.h> /* Needed for the macros */#include <asm/current.h>#include <linux/sched.h>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);
[email protected]:~/desktop# insmod./hello.ko[email protected]:~/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_re Place "profile=" unconfined "name="/usr/sbin/cupsd "pid=2130 comm=" Apparmor_parser "to 07:19:41 Ubuntu kernel: [913.1 86836] E1000:eth0 nic link is downaug-07:19:45 ubuntu kernel: [917.188835] e1000:eth0 nic Link is up Duplex, Flow Control:noneaug 07:22:25 ubuntu kernel: [1076.499433] E1000:eth0 NIC Link is Downaug 07:22:29 ubunt U kernel: [1080.499470] E1000:eth0 NIC Link is up to + Mbps full Duplex, Flow Control:noneaug 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! 07:31:10 ubuntu kernel: [1602.408792] The process is "1383225440" (PID 3571), 07:32:39 UbuNTU kernel: [1691.260987] Bye, kernel! 07:33:50 ubuntu kernel: [1762.382921] The process is "1656784352" (PID 3890) [email protected]:~/desktop#
Lsmod
[email protected]:~/desktop# lsmodmodule Size used byhello 16384 0 coretemp 16384 0 Crct10dif_pclmul 16384 0 crc32_pclmul 16384 0 Aesni_intel 167936 0 snd_ens1 371 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 AES Ni_intel,ablk_helpersnd_seq_midi 16384 0 snd_seq_midi_event 16384 1 snd_seq_midiinput_leds 163 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_raw Midi,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 SNDVM W_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 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_gener IC 16384 0 usbhid 49152 0 hid 118784 2 hid_generic,usbhidpsmouse 126976 0 Mptspi 24576 2 mptscsih 40960 1 mptspimptbase 98304 2 mptsp I,MPTSCSIHAHCI 36864 0 libahci 32768 1 ahcie1000 131072 0 SCSI_TRANSPO Rt_spi 32768 1 mptspipata_acpi 16384 0 [email protected]:~/desktop#
Linux driver Prints the current process name command and PID