Skip to main content

Linux Kernel Module - Kernel Edited

Linux kernels are monolithic by nature. They have a set of drivers already preinstalled on dispatch. 

However there can be new devices such as a WiFi Adapter or  Bluetooth Speaker which cannot be paired to the operating system. Now we have two solutions for this. 

Either start from scratch, edit and compile the entire kernel. This can be time consuming as even a high configuration system can take 15 to 18 minutes just to debug. For a business this is not viable, unless paid by the hour. 

The other is to write a specific module (driver) which can be inserted into the kernel, during runtime. The whole process will take less than 5 minutes. This module is known as Linux Kernel Modules or LKM.

 

Uses

LKM are used for creating new device drivers or file systems and network packet tracking. The latter is particularly useful in developing firewalls, Intrusion detection system (IDS) or Intrusion prevention system (IPS).

 

Prerequisite

To create a module, we need to install the Kmod package. This contains the needed libraries to execute 

  • make (compilation)
  • insmod/modprobe (module insertion)
  • rmmod (module removal).


All these commands run in privileged mode 


Hello World

The beginner program is hello world. Open the text editor and save the file as .c extension. The code is as follows:

 

#include <linux/init.h>

#include <linux/module.h>

 

MODULE_LICENSE ("GPL");

MODULE_AUTHOR("Your Name");

MODULE_DESCRIPTION("This is a test module");


static int start_init (void)

{

    printk(KERN_INFO "Hello World\n");

    return 0; 

static void end_exit (void)

{

    printk(KERN_INFO "Exiting module"); 

} 

 

module_init(start_init);

module_exit(end_init);  

 

Explanation

Here there are two functions. The start_init is used to insert the module while end_init remove the same from the kernelThe topmost code contains the header files and developer details. 

The make command is used to compile the code and insmod to insert the same. 

 

End Note 

Another advantage of LKM is that even if there is an error within the module, we can separate it from the kernel. This prevents the whole system from shutting down due to a glitch. 

  

Comments

Popular posts from this blog

Virtual Private Network (VPN) - Browsing Anonymous

  Privacy is a major concern when browsing the internet. Your data could be eavesdropped by hackers, companies targeting ads or even rogue state actors. What gets revealed would be personal browsing history, location monitoring, IP addresses to name a few. Enter the tech... Virtual Private Network or simply known as VPN is a technology used to prevent unauthorized access of your private data. Even if a hacker penetrates the network and get hold of data packets, all that is revealed is gibberish.  This is because all the information that passes through your device is encrypted and can be only revealed through a personal key.  Internet Service Provider Before going further, a knowledge of Internet Service Provider (ISP) is needed. They are the backbone of the World Wide Web. ISP provides each device with a unique IP (Internet Protocol) address, bandwidth allocation and network security. When a website is searched, first it goes from your device to the Router or Modem which...

Cyber Stalking - Unwanted Attention

With the advent of digital age, we are more connected than ever. Social media has transcended geographical locations, and no place is out of reach. But with this type of connectivity, there is a rise in the number of antisocial players. Cyber stalking cases has reportedly gone high in recent years.  Stalking is considered as any form of unwanted attention, contact or harassment directed towards an individual. This results in victim's personal space being encroached or taken for granted.  The preparator perform stalking through fake profiles, monitoring social media sites, messages or chat history. They initiate a volley of hate speech or try to tarnish their victim's reputation. Here stalking can be also a form of love addiction. An unrequited love can cause the stalker to perform the above steps as an act of revenge. Mode of Operation Installing a piece of code in the victim's computer for accessing the webcam. The spyware comes bundled with a software which could be do...

Ransomware - Trojan in Disguise

  You log into the computer, and it boots up. But instead of seeing the welcome screen, you get a dialog box.  "Your data has been encrypted. To recover, pay $$ of Bitcoin." The message also has a countdown timer, which indicates a payment deadline.  Passwords, credit card details, personal videos/pictures all have been compromised. The hacker even threatens to leak everything online. What happened...... Ransomware is a type of malware that encrypts personal data and blocks access to a computer/network. To regain control, a ransom needs to be paid. Usually this is through Bitcoin, or other crypto currencies. On payment, a key is given, which decrypts everything, and returns access to the system.  However, you could be placed in a "Sucker's list" which is sold in the dark web. This can attract more ransomware attacks, in future. History.... Originating in the 90s, the attacks were first recorded in Russia. Since then, it has crossed into Europe and North America...