strangerRidingCaml
2. Development of Kernel Module 본문
728x90
Development of Kernel Module
Basics of kernel module development
Kernel modules are pieces of code that can be dynamically loaded and unloaded into the Linux kernel without rebooting the system.
- Module structure: A kernel module typically consists of initialization and cleanup functions along with the necessary code to perform its intended functionality.
- Module compilation: Kernel modules are usually written in C and compiled separately from the kernel source code using appropriate build tools.
- Module dependencies: Modules can depend on other modules or kernel features and must be compiled accordingly to ensure proper functionality.
Kernel module loading and unloading
Loading and unloading kernel modules is a fundamental aspect of kernel module development.
- Loading modules: Modules can be loaded into the kernel using the
insmod
command or automatically at system boot through configuration files. - Unloading modules: Modules can be unloaded from the kernel using the
rmmod
command, freeing up system resources and memory.
Simple kernel module examples
Here are some simple examples of kernel modules:
Example 1: Hello World Kernel Module
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void) {
printk(KERN_INFO "Hello world!\n");
return 0;
}
void cleanup_module(void) {
printk(KERN_INFO "Goodbye world!\n");
}
Example 2: Parameterized Kernel Module
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/moduleparam.h>
static char *name = "world";
module_param(name, charp, S_IRUGO);
int init_module(void) {
printk(KERN_INFO "Hello %s!\n", name);
return 0;
}
void cleanup_module(void) {
printk(KERN_INFO "Goodbye %s!\n", name);
}
'Linux kernel exploit' 카테고리의 다른 글
6. Return-Oriented Programming (ROP) (0) | 2024.05.12 |
---|---|
5. Return-to-User (ret2usr) Attacks (0) | 2024.05.12 |
4. Stack Smashing (32-bit and 64-bit) (0) | 2024.05.12 |
3. Debugging Kernel and Modules (0) | 2024.05.12 |
1. Introduction to Linux Kernel Exploitation (0) | 2024.05.12 |