≡ Menu

linux kernel modules

Programming Tutorial: How To Write a FreeBSD Kernel Module ( Driver )

Nice short guide for writing a kernel module for FreeBSD operating system. From the article:

FreeBSD 7.0 has already been released. If you are a real hacker, the best way to jump in and learn it is hacking together an introductory kernel module. In this article I’ll implement a very basic module that prints a message when it is loaded, and another when it is unloaded. I’ll also cover the mechanics of compiling our module using standard tools and rebuilding the stock FreeBSD kernel.

=> Writing a kernel module for FreeBSD

Related: How To Compile a Linux Kernel Modules

How to display or show information about a Linux Kernel module or drivers

I was just browsing our forum and come across the following question:

How do I find out detailed information about a Linux Kernel module or device drivers?

You need to use modinfo command to display or show information about a Linux Kernel loaded modules. Use lsmod command to obtain list of loaded modules.

modinfo extracts information from the Linux Kernel modules given on the command line. This is not just useful to find out about information about loaded modules but it can be used to identify modules inserted by crackers/hackers (try less /proc/modules). Also following is a good way to verify output reported by ps ax :
# ps ax | wc -l
# ls -d /proc/* | grep [0-9]|wc -l

Usually rootkit will install their own ps command, which hides kernel modules. If second output is larger than the first (ps ax) command output take a closer look at your server.

Back to our main question, the modinfo command outputs following information for each module:
=> Module Author
=> Module description
=> License
=> Parameter and filename

Task: Display list of modules

$ lsmod
$ less /proc/modules

Task: Display information about ide-cd module

$ /sbin/modinfo ide-cd

filename:       /lib/modules/2.6.8-2-686/kernel/drivers/ide/ide-cd.ko
description:    ATAPI CD-ROM Driver
license:        GPL
vermagic:       2.6.8-2-686 preempt 686 gcc-3.3
depends:        ide-core,cdrom

Task: Display information about rt61 module

$ /sbin/modinfo rt61

filename:       /lib/modules/2.6.8-2-686/kernel/net/wireless/rt61.ko
author:         Paul Lin 
description:    RT61 Wireless Lan Linux Driver
vermagic:       2.6.8-2-686 preempt 686 gcc-3.3
alias:          pci:v00001814d00000301sv*sd*bc*sc*i*
alias:          pci:v00001814d00000302sv*sd*bc*sc*i*
alias:          pci:v00001814d00000401sv*sd*bc*sc*i*

You can load modules automatically during Linux system boot sequence by adding a module name to /etc/modules.conf (Red Hat and friends) or /etc/modules (Debian / Ubuntu Linux) file.