Lab 4 Kernel Module Operating System Lab.

Slides:



Advertisements
Similar presentations
DEVICE DRIVER VINOD KAMATH CS691X PROJECT WORK. Introduction How to write/install device drivers Systems, Kernel Programming Character, Block and Network.
Advertisements

Drivers and the kernel1-1 Drivers and the kernel UNIX system has three layers: m The hardware m The operating system kernel m The user-level programs Kernel.
Computer System Laboratory
Building and Running Modules Sarah Diesburg COP 5641.
Building and Running Modules Linux Kernel Programming CIS 4930/COP 5641.
CIS238/DL1 Chapter 15 Rebuilding the Linux Kernel Preparing the Source Code Locating the Source Code Installing the Source Code Read the Documentation.
Building and Running Modules Ted Baker  Andy Wang CIS 4930 / COP 5641.
52 Advanced Operating Systems Writing Device Drivers.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
Embedded System Programming Introduction to Device Drivers.
Add a New System Call to Linux. Hw1 Add a New System Call to Linux and Compile Kernel Add a New System Call to Linux by Kernel Module.
Tutorial and Demos on Linux Virtual Machine
1 Netfilter in Linux Bing Qi Department of Computer Science and Engineering Auburn university.
Loadable Kernel Modules Dzintars Lepešs The University of Latvia.
1 Week 6 Intro to Kernel Modules, Project 2 Sarah Diesburg Florida State University.
Kernel module programming Nezer J. Zaidenberg. reference This guide is built on top of The Linux Kernel Module Programming Guide The guide is available.
NCHU System & Network Lab Lab 3 System Call Operating System Lab.
Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux.
For OS Experiments. What Do We Need? A Computer &
Kernel Modules Giving your Linux more pop since 1995.
Sogang University Advanced Operating Systems (Linux Module Programming) Sang Gue Oh, Ph.D.
1 What is a Kernel The kernel of any operating system is the core of all the system’s software. The only thing more fundamental than the kernel is the.
Troubleshooting and Performance
Guide to Linux Installation and Administration1 Chapter 4 Running a Linux System.
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Memory Addressing / Kernel Modules.
Implementation of Embedded OS Lab3 Linux Kernel Modules.
Linux Kernel Management. Module 9 – Kernel Administration ♦ Overview The innermost layer of Linux operating system is the kernel, which is a thin layer.
System Calls. The Linux we use is: Linux-Mandrake 7.0. In this project, you are going to change some kernel files and recompile the kernel. After you.
Linux Routing. Why use Linux as a router? Its cheap. Linux has low hardware requirements. A properly configured P166 Mhz computer would have no problems.
LOGO System Call. Introduction System call is the mechanism used by an application program to request service from the OS. Users use it to communicate.
Interfacing Device Drivers with the Kernel
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Networks Lab, RPI 1 Experimental Networking: Linux Kernel Modules and MIT Click Router By Vijay Subramanian Oct
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Linux Kernel Programming (LKP). LKP New sub-course New sub-course We will learn together We will learn together Evaluation of this part of course will.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Kernel Modules – Introduction CSC/ECE 573, Sections 001 Fall, 2012.
1 Intro to Kernel Modules and /proc Sarah Diesburg CS 3430 Operating Systems.
Lecture 3 Module Programming and Device Driver (Homework#1 included) Kyu Ho Park Sept. 15, 2015.
Virtual Memory Mohammad H. Mofrad February 23, 2016
Add a New System Call to Linux
Operating System Kernel Compilation
OS – Ex 1 Nezer J. Zaidenberg.
Exercise #1: Exploring Open-Source Operating Systems with Virtual Machines J. H. Wang Sep. 20, 2016.
Lecture 3 Module Programming and Device Driver (Homework#1 included)
Linux Kernel Module Programming
Chapter 12: File System Implementation
Computer System Laboratory
Drivers and the kernel UNIX system has three layers: Kernel
Linux Kernel Module Programming
Exercise #1: Exploring Open-Source Operating Systems with Virtual Machines J. H. Wang Sep. 19, 2017.
Operating System Kernel Compilation
Intro to Kernel Modules and /proc
Exercise #1: Exploring Open-Source Operating Systems with Virtual Machines J. H. Wang Sep. 21, 2018.
chapter 2 - Hello World Model
Govt. Polytechnic,Dhangar
COP 4343 Unix System Administration
CS 6560 Operating System Design
Operation System Program 1
Kernel – Device Drivers (part 2)
CS 6560 Operating System Design Kernel Loadable Modules
Kernel Structure and Infrastructure
Implementation of Embedded OS
Using screens and adding two numbers - addda.cbl
Computer System Laboratory
Loadable Kernel Modules
Operating System Kernel Compilation
In Today’s Class.. General Kernel Responsibilities Kernel Organization
Presentation transcript:

Lab 4 Kernel Module Operating System Lab

NCHU System & Network Lab What is a Kernel Module? 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 recompile and reboot the system. Example One type of module is the device driver, which allows the kernel to access hardware connected to the system. Without modules, we would have to build monolithic kernels and add new functionality directly into the kernel image. NCHU System & Network Lab

Files relate to modules /etc/modprobe.conf Kernel will mount modules according to this file when boot on. /lib/modules/2.6.22.***/modules.dep If other modules must be loaded before the requested module may be loaded. /lib/modules/2.6.22.***/kernel All modules of a kernel are in it. /proc/modules what modules are already loaded into the kernel by reading this file NCHU System & Network Lab

How Do Modules Get Into The Kernel? (1/4) lsmod what modules are already loaded into the kernel by reading the file /proc/modules. [root@localhost~ ]#lsmod NCHU System & Network Lab

How Do Modules Get Into The Kernel? (2/4) modprobe This instruction can load the designated specific module , or a group of interdependent module . according to /lib/modules/2.6.22.***/modules.dep. [root@localhost~ ]#modprobe [-lcfr] modules_name NCHU System & Network Lab

How Do Modules Get Into The Kernel? (3/4) depmod [-aens] the file /lib/modules/version/modules.dep is created by depmod −a. modinfo show the information of a module. [root@localhost~ ]#depmod -a [root@localhost~ ]#modinfo module_name NCHU System & Network Lab

How Do Modules Get Into The Kernel? (4/4) insmod similar to modprobe, but it can load the modules that aren’t in /lib/modules/2.6.22.***/kernel rmmod remove modules [root@localhost~ ]#insmod module_name.ko [root@localhost~ ]#rmmod module_name NCHU System & Network Lab

Hello, World: The Simplest Module /* * hello.c − The simplest kernel module. */ #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ int init_module(void) { printk("Hello world 1.\n"); return 0; } void cleanup_module(void) printk("Goodbye world 1.\n"); MODULE_LICENSE(“GPL") NCHU System & Network Lab

Makefile for a Basic Kernel Module (1/2) obj-m +=testfunction.o all: make –C /lib/modules/linux-2.6.22.6/build M=$(PWD) modules clean: make –C /lib/modules/linux-2.6.22.6/build M=$(PWD) clean NCHU System & Network Lab

Makefile for a Basic Kernel Module (2/2) [root@localhost~ ]#make make −C /lib/modules/2.6.22.6/build M=/root/Desktop/ make[1]: Entering directory `/usr/src/2.6.22.6 CC [M] /root/Desktop/hello.o Building modules, stage 2. MODPOS CC /root/Desktop/hello.mod.o LD [M] /root/Desktop/hello.ko make[1]: Leaving directory `/usr/src/2.6.22.6' NCHU System & Network Lab

NCHU System & Network Lab Exercise We want to `spy' on a certain user, and to printk() a message whenever that user opens a file. Towards this end, we replace the system call to open a file with our own function, called our_sys_open. This function checks the uid (user's id) of the current process, and if it's equal to the uid we spy on, it calls printk() to display the name of the file to be opened. Then, either way, it calls the original open() function with the same parameters, to actually open the file. NCHU System & Network Lab

NCHU System & Network Lab Reference The Linux Kernel Module Programming Guide http://www.faqs.org/docs/kernel/ Google Keyword “kernel module” Linux kernel module and TCP/IP program design NCHU System & Network Lab

NCHU System & Network Lab

NCHU System & Network Lab Exercise (1/8) NCHU System & Network Lab

NCHU System & Network Lab Exercise(2/8) [root@localhost~ ]#vim /usr/src/linux2.6.22.***/net/core/dev.c NCHU System & Network Lab

NCHU System & Network Lab Exercise (3/8) From previous two slides, we can use command “ping” to show some message. If we want to change the message showed, we should re-edit the kernel, re-compile it, and reboot each times. There is no efficiency. NCHU System & Network Lab

NCHU System & Network Lab Exercise(4/8) Use kernel module to avoid recompiling kernel when we edit the kernel each times. So, we define a back door procedure in the kernel. In other words, we make a hole in the kernel, and we can put the kernel module in it. Write a kernel module that can make the “ping” instruction show “hello world” NCHU System & Network Lab

NCHU System & Network Lab Exercise(5/8) [root@localhost~ ]#vim /usr/src/linux2.6.22.***/net/core/dev.c dev_queue_xmit() int (*testfunction)(struct sk_buff *)=0; if(testfunction){ testfunction(skb); } NCHU System & Network Lab

NCHU System & Network Lab Exercise(6/8) EXPORT_SYMBOL(testfunction); NCHU System & Network Lab

NCHU System & Network Lab Exercise(7/8) Include file <linux/module.h> <linux/kernel.h> <linux/skbuff.h> <linux/ip.h> NCHU System & Network Lab

NCHU System & Network Lab Exercise(8/8) NCHU System & Network Lab

NCHU System & Network Lab Reference The Linux Kernel Module Programming Guide http://www.faqs.org/docs/kernel/ Google Keyword “kernel module” Linux kernel module and TCP/IP program design NCHU System & Network Lab