Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to start with Linux Kernel Modules?

A little background, I'm a CMPE Student currently in an Operating Systems class. I have some basic knowledge of C coding but am more comfortable with C++ (taken about 3 semesters of that). Other than that, never had any other formal training in coding. Also, I've got a basic understanding of the linux environment.

I am working on a project that requires me and my team to code a linux kernel module that can do the following:

  • echoes data passed from user-level processes by printing the data received to the kernel log
  • is able to pass data from one user process to another.
  • must be possible to use the kernel module as an inter-process communication abstraction. module should provide for situations where a sender posts data to it but no receiver is waiting.module must cover the situation where a receiver asks for data but there is no data available.
  • module must cover the situation where a receiver asks for data but there is no data available.
  • must be a limit in the buffer capacity in your module.

Now I don't know how difficult this seems to those with a background in programming, but this seems like an impossibly complicated task for someone in my position.

Here's what I've done so far:

  1. Coded, Compiled, Inserted, and Removed the basic "hello world" linux kernel module successfully
  2. Read through about the first 4 or 5 chapters of The Linux Kernel Module Programming Guide
  3. Read through a few stackoverflow posts, none of which seem to be able to direct me to where I need to go.

So finally here's my question: Can someone please point me in the direction that I need to go with this? I don't even know where to being to find commands to use for reading in user-level process data and I need somewhere to start me off. TLPD was great for insight on the topic but isn't helping me get to the point where I will have a workable project to turn in. In the past, I would learn off of reading source code and reverse engineering, is there anywhere I can find something like that? Any and all help is appreciated.

-Will

like image 417
thewill2live Avatar asked Oct 29 '13 19:10

thewill2live


People also ask

Where can I find kernel module?

Select a kernel module you want to load during the boot process. The modules are located in the /lib/modules/$(uname -r)/kernel/<SUBSYSTEM>/ directory.

Where are the kernel modules located in Linux?

Loadable kernel modules in Linux are loaded (and unloaded) by the modprobe command. They are located in /lib/modules or /usr/lib/modules and have had the extension . ko ("kernel object") since version 2.6 (previous versions used the .o extension). The lsmod command lists the loaded kernel modules.

How can a module be used with a kernel?

Modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. For example, one type of module is the device driver, which allows the kernel to access hardware connected to the system.


1 Answers

I've found that the Linux Kernel Module Programming Guide is a pretty good resource. From the sounds of it, something like a character device might work best for your purposes, but I'm not sure if you have other constraints.

Another direction I might consider (though this could be a bad path) is to look at examples in the Linux kernel for a kernel module that has similar functionality. I don't have a good example offhand, but perhaps look through /drivers/char/.

like image 189
Michael Avatar answered Oct 26 '22 04:10

Michael