Differences

This shows you the differences between two versions of the page.

Link to this comparison view

isc:labs:kernel:tasks:02 [2021/11/25 12:30]
radu.mantu
isc:labs:kernel:tasks:02 [2022/10/08 22:05] (current)
radu.mantu [02. [??p] Kernel modules]
Line 6: Line 6:
  
 <code bash> <code bash>
-$ lsmod+[student@host]$ lsmod
 ecdh_generic ​          ​16384 ​ 1 bluetooth ecdh_generic ​          ​16384 ​ 1 bluetooth
  
-$ modinfo ecdh_generic | grep description+[student@host]$ modinfo ecdh_generic | grep description
 description: ​   ECDH generic algorithm description: ​   ECDH generic algorithm
  
-$ modinfo bluetooth | grep description ​+[student@host]$ modinfo bluetooth | grep description ​
 description: ​   Bluetooth Core ver 2.22 description: ​   Bluetooth Core ver 2.22
 </​code>​ </​code>​
Line 24: Line 24:
 Now, let's compile our module, upload it into the kernel, and see what happens: Now, let's compile our module, upload it into the kernel, and see what happens:
 <code bash> <code bash>
-$ make+[student@host]$ make
  
-$ sudo insmod test.ko +[student@host]$ sudo insmod test.ko 
-$ sudo dmesg+[student@host]$ sudo dmesg
 ... ...
 [ 6348.461247] my-first-module:​ Hello world! [ 6348.461247] my-first-module:​ Hello world!
  
-$ sudo rmmod test +[student@host]$ sudo rmmod test 
-$ sudo dmesg+[student@host]$ sudo dmesg
 ... ...
 [ 6348.461247] my-first-module:​ Hello world! [ 6348.461247] my-first-module:​ Hello world!
Line 40: Line 40:
 Here, we used **insmod** to upload a //%%.ko%%// kernel object file into the kernel proper and **rmmod** to remove it. **dmesg** is a tool that prints the kernel message buffer. Note that there are multiple [[https://​www.kernel.org/​doc/​html/​latest/​core-api/​printk-basics.html|log levels]] ranging from **debug** to **emergency**. **pr_info()** is the kernel'​s **printf()** variant that corresponds to one of the less urgent levels. **dmesg** can be configured to squelch messages under a certain level but depending on how your kernel was compiled, some of the more important messages will also be echoed to your terminal. Here, we used **insmod** to upload a //%%.ko%%// kernel object file into the kernel proper and **rmmod** to remove it. **dmesg** is a tool that prints the kernel message buffer. Note that there are multiple [[https://​www.kernel.org/​doc/​html/​latest/​core-api/​printk-basics.html|log levels]] ranging from **debug** to **emergency**. **pr_info()** is the kernel'​s **printf()** variant that corresponds to one of the less urgent levels. **dmesg** can be configured to squelch messages under a certain level but depending on how your kernel was compiled, some of the more important messages will also be echoed to your terminal.
  
-=== [??p] Task B - Debugging ===+=== [??p] Task B - Debugging ​(1) ===
  
 In this task we are going to add a bug to our initial module. We will do this by applying a [[https://​devmanual.gentoo.org/​tools-reference/​diff-and-patch/​index.html|diffpatch]] to our source: In this task we are going to add a bug to our initial module. We will do this by applying a [[https://​devmanual.gentoo.org/​tools-reference/​diff-and-patch/​index.html|diffpatch]] to our source:
Line 176: Line 176:
 [root@guest]$ cat /​proc/​modules [root@guest]$ cat /​proc/​modules
 test 20480 1 - Loading 0xffffffffc0304000 (O+) test 20480 1 - Loading 0xffffffffc0304000 (O+)
 +</​code>​
 +
 +In this case, the best course of action is to simply reboot, but if you want to risk it, just run ''​rmmod -f''​ to force unloading the module. Be warned that this is very dangerous. Also, if the module is still there after using the ''​-f''​ flag, make sure that //​CONFIG_MODULE_FORCE_UNLOAD//​ was set at compile time.
 +
 +<code bash>
 +# check if force unloading the module is an option
 +[root@guest]$ zcat /​proc/​config.gz | grep CONFIG_MODULE_FORCE_UNLOAD
 +CONFIG_MODULE_FORCE_UNLOAD=y
 +
 +# force unload the kernel module
 +[root@guest]$ rmmod -f test
 </​code>​ </​code>​
 </​note>​ </​note>​
 +
 +
isc/labs/kernel/tasks/02.1637836225.txt.gz · Last modified: 2021/11/25 12:30 by radu.mantu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0