Skip to content

serious-engineer/Loadable_Kernel_Module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# First LKM (Loadable Kernel Module)

This repository contains a simple example of a Loadable Kernel Module (LKM) for Linux, demonstrating basic interactions with the `/proc` filesystem through custom read and write handlers. It is designed for learning and experimenting with Linux kernel programming concepts.

---

## Features

- **Custom `/proc` entry**: Creates a `/proc/driver_name` node.
- **Read functionality**: Returns the contents of a kernel buffer or a default message ("Acknowledge\n") when read.
- **Write functionality**: Updates the kernel buffer with data from user space.
- **Kernel logging**: Logs actions to the kernel message buffer using `printk`.

---

## Files

- **Source Code**: `ldd.c`
  - Implements the LKM, including initialization, cleanup, and `/proc` entry operations.

---

## Installation

### Prerequisites

- A Linux system with kernel development tools installed.
- Kernel headers for the currently running kernel.

### Steps

1. **Clone the Repository**:
   ```bash
   git clone <repository_url>
   cd <repository_directory>
  1. Build the Module:

    make
  2. Insert the Module:

    sudo insmod driver_name.ko
  3. Verify Installation: Check the kernel message log for initialization messages:

    dmesg | tail -n 20

Usage

Read Data from /proc/driver_name:

cat /proc/driver_name

Write Data to /proc/driver_name:

echo "Your message" > /proc/driver_name

Cleanup

  1. Remove the Module:

    sudo rmmod driver_name
  2. Verify Removal: Check the kernel message log for cleanup messages:

    dmesg | tail -n 20

Development Notes

Kernel Logs

Use dmesg to view logs generated by printk statements in the module.

Permissions

The /proc/driver_name node is created with 0666 permissions, allowing both read and write access to all users.


License

This module is licensed under the GNU General Public License (GPL). See the LICENSE file for details.


Author

Developed by Krishnaprasad Sreekumar Nair.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published