A kernel module is a run-time loadable object file that is loaded into operating system kernel to add functionality to a running kernel. Examples include device drivers and other kernel items.
Questions tagged [kernel-module]
2228 questions
6
votes
1 answer
Patching and compiling Ext4 as a kernel module
I'm currently patching Ext4 for academic purposes (only linux/fs/ext4/*, like file.c, ioctl.c, ext4.h) . I'm working on the QEMU virtual machine, and to speed up the whole process I've selected Ext4 to compile as a kernel module. The problem occurs…

Tomek Falkiewicz
- 165
- 1
- 8
6
votes
1 answer
How to rename a kernel module name without renaming the .ko passed to insmod?
I need to rename a kernel module (the name that get displayed with lsmod) of an already existing driver without changing the name of the source file.
e.g.
# insmod xxx.ko
<>
# lsmod
Module Size Used by …

Pradeep
- 73
- 1
- 5
6
votes
1 answer
Why doesn't my hello world driver module print anything?
I'm very new to kernel module programming and right now I'm trying to run the most basic hello world module program, however I could not get any output.
I have written the hello world program introduced in Linux Device Drivers 3rd ed and got some…

Varaquilex
- 3,447
- 7
- 40
- 60
6
votes
2 answers
Usage of __init & __exit attributes
What happens if __init & __exit attributes are used in intialization and exit modules & what happens if i don't use them. Example as shown below.
Using Attributes
static __init int myinit(void)
{}
static __exit void myexit(void)
{}
Witout…

Sandy
- 65
- 4
6
votes
1 answer
Sending a struct from kernel to userland via netlink
I'm trying to send a struct from a LKM to userland, based on this answer: Netlink Sockets in C using the 3.X linux kernel
The code from the answer itself is perfectly compilable, but when I try to send a struct instead of a char *, I get segfaults…

alexandernst
- 14,352
- 22
- 97
- 197
6
votes
2 answers
Using ELF section in LKM
I have this POC in C that saves a few structs in a custom section and then iterates over those structs, showing their content.
#include
char a, b, c;
struct counter_info {
int counter;
char *name;
}…

alexandernst
- 14,352
- 22
- 97
- 197
6
votes
1 answer
Send packet with sockets from kernel module
I am writing a kernel module that should receive messages from user-space and send response back via socket.
When program and module are on the same machine and I use IP 127.0.0.1, everything works fine. But when I try it on different machines and…

Mykola Niemtsov
- 540
- 1
- 7
- 23
6
votes
1 answer
sysrq-g wont break kernel
I am trying to setup linux kernel module debugging, using two machines - target and host. On target machine, I have compiled and installed a 3.5.0 kernel with CONFIG_MAGIC_SYSRQ=y flag and other flags for over the serial console debugging.
When I…

Naveen Rawat
- 81
- 2
- 6
6
votes
1 answer
kernel driver reading ok from user space, but writing back is always 0
So I'm working my way through kernel driver programming, and currently I'm trying to build a simple data transfer between application and kernel driver.
I am using simple character device as a link between these two, and I have succeeded to transfer…

julumme
- 2,326
- 2
- 25
- 38
6
votes
3 answers
Simple kernel multithreading
I am new to kernel module programming and for my work I need to write a multithreaded kernel module. So I tried some primary uses of kernel threads. I wrote the following. It is supposed to print 1 in one thread and 2 in another thread, both 10…

taufique
- 2,701
- 1
- 26
- 40
6
votes
2 answers
mapping memory reserved by mmap kernel boot param into user space
As discussed in this question, i am reserving a memory chunk at the boot time using a kernel boot parameter memmap=8G$64G
I have written a character driver kernel module which , during initialization does a ioremap of this reserved memory chunk.
As…

Jay D
- 3,263
- 4
- 32
- 48
6
votes
2 answers
How to append data on a packet from kernel space?
I am trying to append some data on a packet from kernel space. I have an echo client and server. I type in the command line like: ./client "message" and the server just echoes it back. The server was run with ./server .
Now, the client and server…

rr_ovi
- 283
- 4
- 14
6
votes
2 answers
How to determine kernel stack size
I need to determine the stack size of the running Linux kernel inside a kernel module. I do know that the macro THREAD_SIZE gives the stack size for a given architecture but I cannot use that. Since the compile and the run machines are different. Is…

pandaman
- 73
- 1
- 4
6
votes
1 answer
How to set the affinity of a process from a Linux kernel mode?
How can the CPU affinity of a process be set in kernel module? In user mode there is a syscall sched_setaffinity, but I am looking for the kernel mode equivalent.
In the Linux kernel code, there is also a function called sched_setaffinity. It's…

Mike Mu
- 977
- 6
- 10
6
votes
1 answer
How to use exported symbols optionally only if they are present in an insmoded Linux Kernel module?
I am modifying a Linux Kernel to add some functionality to the Linux Virtual Server (LVS).
I developed a module (which I called net/netfilter/ipvs/ip_vs_utils.c) with some functions to be used when load-balancing. All the functions here are exported…

marcocamejo
- 798
- 1
- 7
- 20