kernel-module

How do I use ioctl() to manipulate my kernel module?

♀尐吖头ヾ 提交于 2019-11-28 05:06:31
So I'm trying to write a kernel module that uses the linux/timer.h file. I got it to work inside just the module, and now I am trying to get it to work from a user program. Here is my kernel module: //Necessary Includes For Device Drivers. #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/proc_fs.h> #include <asm/uaccess.h> #include <linux/timer.h> #include <linux/ioctl.h> #define DEVICE_NAME "mytimer" #define DEVICE_FILE_NAME "mytimer" #define MAJOR_NUM 61 #define MINOR_NUM 0 MODULE_LICENSE("Dual BSD/GPL"

How to make one Linux kernel module depend on another external module with depmod?

痴心易碎 提交于 2019-11-28 04:29:32
问题 I'm writing a kernel module which depends on one existing kernel module. I'm building my module out of the tree (as an external module). How can I declare the dependency, so that it is recognized by depmod? 回答1: While not entirely satisfying, the best I've come up with to make modprobe work is either adding an entry to modules.dep # tail -1 modules.dep ../../../../home/ctuffli/mymod/mymod.ko: kernel/drivers/scsi/libsas/libsas.ko kernel/drivers/scsi/scsi_transport_sas.ko or alternatively,

Cross compiling a kernel module

佐手、 提交于 2019-11-28 04:22:20
I'm trying to cross compile a helloworld kernel (2.6.x) module for ARM architecture on my intel x86 host. The codesourcery tool chain for ARM is located at: /home/ravi/workspace/hawk/arm-2009q3 The kernel source is located at : /home/ravi/workspace/hawk/linux-omapl1 My Makefile: ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi obj-m := Hello.o KDIR := /home/ravi/workspace/hawk/linux-omapl1 PWD := $(shell pwd) default: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules clean: $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) clean When i run make , the .ko produced is that of my host machine which means the makefile is

How do I use a Linux System call from a Linux Kernel Module

て烟熏妆下的殇ゞ 提交于 2019-11-28 04:14:41
问题 I am having some difficulty calling a system call from inside a Linux Kernel Module. The system calls have been tested and work properly from a standard c user space program but I can't seem to get the kernel module to compile and run them. In my user program I include the following code and the system call works: #include <linux/unistd.h> #define __NR_sys_mycall 343 extern long int _syscall(long int_sysno,...)__THROW; //and then a simple call is done as such long value = syscall(__NR_sys

Memory Isolation in new Linux Kernels, or what?

落爺英雄遲暮 提交于 2019-11-28 01:44:58
问题 This my module perfectly hijacks user's console: https://pastebin.com/99YJFnaq And it was Linux kernel 4.12, Kali 2018.1. Now, I've installed the latest version of Kali - 2019.1. It uses kernel 4.19: Linux kali 4.19.0-kali1-amd64 #1 SMP Debian 4.19.13-1kali1 (2019-01-03) x86_64 GNU/Linux I'm trying to catch anything, but nothing with fd == 0 exists in flow. I've googled for a long long time, tried to read changelogs on different resources... I've found such module kpti , which probably would

Getting kernel version from linux kernel module at runtime

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 01:16:47
how can I obtain runtime information about which version of kernel is running from inside linux kernel module code (kernel mode)? By convention, Linux kernel module loading mechanism doesn't allow loading modules that were not compiled against the running kernel, so the "running kernel" you are referring to is most likely is already known at kernel module compilation time. For retrieving the version string constant, older versions require you to include <linux/version.h> , others <linux/utsrelease.h> , and newer ones <generated/utsrelease.h> . If you really want to get more information at run

Implementing Linux System Call using LKM

让人想犯罪 __ 提交于 2019-11-27 22:38:33
问题 I was trying to add a new System Call to linux kernel 3.2.x. While searching for useful reference material over the internet i had an impression that implementing system call as a loadable module is not possible as in SO question Is it possible to add a system call via a LKM? I found another link which says this "There is a way to add system calls without recompiling the kernel using modules as a wrapper, but that is beyond the scope of this document". source http://hekimian-williams.com/?p

How to load Linux kernel modules from C code?

眉间皱痕 提交于 2019-11-27 21:16:13
I have an application that has both two external kernel modules and a userspace daemon. I want to load the modules from the daemon code, written in C, at startup, and unload them on clean exit. Can I load them in a cleaner way than doing system("modprobe module"); and unload them using the corresponding rmmod ? Minimal runnable example Tested on a QEMU + Buildroot VM and Ubuntu 16.04 host with this simple parameter printer module . We use the init_module / finit_module and remove_module Linux system calls . The Linux kernel offers two system calls for module insertion: init_module finit_module

Docker loading kernel modules

走远了吗. 提交于 2019-11-27 16:15:55
问题 I tried to install a kernel module, xfsprogs . It was successfully installed inside a container. It is really surprising, but lsmod doesn't list this module inside container or in the host system. How can a new kernel module loaded in a container?( CentOS container, Ubuntu host) 回答1: Containers interact with the kernel through system calls and don't include any part of the kernel or the kernel modules inside the container. This is one of the reasons why containers designed to be light weight

Compiling out-of-tree kernel module against any kernel source tree on the filesystem

混江龙づ霸主 提交于 2019-11-27 15:19:07
问题 I am trying to compile a module against any source tree on the file system but I am having trouble with the Makefile. This was the original Makefile I had against the kernel specified: obj-m += new-mod.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean This Makefile would compile correctly, but goal is to have it compile against any source tree. I have tried just: obj-m += new-mod.o I thought that "all:" is