kernel-module

Linux Kernel Threads : How to pass the Linux module write function as the function that the thread has to execute?

為{幸葍}努か 提交于 2019-12-11 18:39:02
问题 I am developing Linux kernel module that communicate with user space program. This module waits for a message which is being sent from user space in order to print it in kernel mode. This is the module : #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/uaccess.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("Gaston"); MODULE_DESCRIPTION("A simple Linux char driver"); MODULE_VERSION("0.1"); #define MAX 256

Compile a kernel module as a position independant executable

爱⌒轻易说出口 提交于 2019-12-11 17:18:32
问题 For a PoC (context), I’m trying to build a kernel module as a position independent executable. Currently, I compile my module using mcmodel=small -fpie -mno-red-zone -mnosse to my Makefile ( /lib/modules/$(uname -r)fixed/build/Makefile ) and then I resolve my symbols by parsing /proc/kallsyms and patching my binary using ld ’s option --defsym symbol=address But this is not satisfactory. I get a rip-relative addressing but no got/plt. Below an example of function in the generated module before

Insmod is not working

我只是一个虾纸丫 提交于 2019-12-11 16:27:44
问题 insmod / rmmod doesn't recognize the arguments. Even insmod without any argument also gets executed. It looks like only command is recognized by the system. Through insmod command kernel module can be inserted dynamically but when I do insmod testStub.ko , nothing is happening. Neither do I see my module in lsmod result nor any printk messages that I have written in my testStub.c , in dmesg . lsmod / modprobe -l also don't show any output. lsmod command is supposed to show all running modules

kernel module build fails: sys/types.h: No such file or directory

江枫思渺然 提交于 2019-12-11 12:48:03
问题 I'm unable to build a kernel module due to a missing .h file. I'm building the module on Ubuntu 14.04. This is the make file I use: $ cat Makefile obj-m += my_module.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 And this is the output of 'make': $ make make -C /lib/modules/3.13.0-34-generic/build M=/home/user/location modules make[1]: Entering directory `/usr/src/linux-headers-3.13.0-34-generic' CC [M]

NetFilterHook: Displaly Interface Name

安稳与你 提交于 2019-12-11 12:03:29
问题 How can filter and/or display the name of the interface the packet has arrived from in the Kernel space ? More specifcally I want the name of the interfacen e.g eth0, wlan1 etc to be printed out in the kernel. Secondly how can I filter packets only from a specific interface e.g eth0 only? 回答1: In the hook function, there is parameters const struct net_device *in and const struct net_device *out . You can print it by: printk(KERN_INFO "%s\n", out->name); or: printk(KERN_INFO "%s\n", in->name);

How to create a directory in user space in a Linux kernel module

℡╲_俬逩灬. 提交于 2019-12-11 11:44:15
问题 The following will create a file in user space but how can I create a directory? struct file *filp = filp_open("/home/myuser/Desktop/newfile", O_CREAT, S_IRWXU); 回答1: The best way I know how is to use: mkdir("your/directory", 0700); David Heffernan's comment shows the specifics. Edit: This page will show you the different mode parameters you can give for your directory and what they do. http://osdir.com/ml/linux.c-programming/2002-06/msg00069.html 回答2: Just set O_DIRECTORY in filp_open flags.

“Unable to handle kernel NULL pointer dereference at Virtual Address.” - On signalling the Kernel Module | OOPS

穿精又带淫゛_ 提交于 2019-12-11 10:47:41
问题 I was learning some basics of kernel modules and threads. And so i tried to make a example module and test it. Now, it loads successfully. Module code: #include <linux/module.h> #include <linux/kernel.h> #include <linux/kthread.h> #include <linux/delay.h> #include <linux/version.h> static struct task_struct *thread_st; // Function called by thread static int thread_fun(void *unused) { allow_signal(SIGKILL); while(!kthread_should_stop()) { printk(KERN_INFO "Thread Running\n"); ssleep(5); if

lkm func hijacking BUG

本小妞迷上赌 提交于 2019-12-11 08:52:53
问题 I've written a little linux kernel module, to see, how nowadays implement kernel function hijacking. https://pastebin.com/99YJFnaq #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/string.h> #include <linux/syscalls.h> #include <linux/version.h> #include <linux/unistd.h> #include <linux/time.h> #include <linux/preempt.h> #include <asm/uaccess.h> #include <asm/paravirt.h> #include <asm-generic/bug.h> #include <asm/segment.h>

Generic Netlink unicast from kernel to user fails (-111)

谁说我不能喝 提交于 2019-12-11 06:14:23
问题 (Linux 4.4) I am trying to get a kernel module to send information to a user process over a Generic Netlink. It seems that the message is not successfully received by the user process - the nlmsg_unicast function returns with -111. Here is what I know: The kernel module successfully registers a Generic Netlink family - it prints a message in the syslog indicating the (autogenerated) family ID (which is always 26). The user process successfully discovers the family ID (26). The user process

Iterate over all modules in a kernel module

你离开我真会死。 提交于 2019-12-11 05:54:46
问题 I'm a bit confused by the variables available inside the Kernel. How would I go about iterating over all modules inside my own kernel module? I found modules being used in the kernel code. Can I do something along the lines of struct module *mod; list_for_each_entry(mod, &modules, list) { printk(KERN_INFO "%s\n", mod->name); } 回答1: There is no direct way for iterate over list of modules. Head of the module's list is modules variable, which is statically defined in kernel/module.c, so it is