kernel-module

Interchangeability of compiled LKMs

萝らか妹 提交于 2019-12-22 10:17:30
问题 Is it possible, to use a Loadable Kernel Module, compiled for 3.0.8+ mod_unload ARMv5 (my self-make'd kernel) in a kernel with version 3.0.31-gd5a18e0 SMP preempt mod_unload ARMv7 (android stock-kernel)? The module itself contains nearly nothing, just // Defining __KERNEL__ and MODULE allows us to access kernel-level code not usually available to userspace programs. #undef __KERNEL__ #define __KERNEL__ #undef MODULE #define MODULE // Linux Kernel/LKM headers: module.h is needed by all modules

How to access data/payload from tcphdr (sk_buff) struct on debian 64 bits?

為{幸葍}努か 提交于 2019-12-22 08:46:32
问题 I'm working on a small firewall, i had to retrieve the datas from each tcp packet from port 80 (http) for parsing them. This code works well on a debian 32 bits virtual machine, i'm able to print the headers of each web page, but when i try to load my kernel module and to transfer some datas through the http port, it prints no datas. When i compile, it shows those warnings only on my 64bits computer : /home/dev3/C/FIREWALL/firewall.c: In function ‘hook_func’: /home/dev3/C/FIREWALL/firewall.c

ccflag option in Makefile

痴心易碎 提交于 2019-12-22 01:29:14
问题 I want to compile my c code (in kernel) which needs to include some header files from another directory. Instead of specifying the complete path to header files in c file, I would like to specify the include path in Makefile. My c file gets complied when the config option CONFIG_FEATURE_X is enabled. I have written the following in Makefile: obj-$(CONFIG_FEATURE_X) += my_file.o ccflags-$(CONFIG_FEATURE_X) += -I$(obj)/../../path When the CONFIG_FEATURE_X is enabled (Y) in .config using make

How to dump/list all kernel symbols with addresses from Linux kernel module?

三世轮回 提交于 2019-12-22 00:23:23
问题 In a kernel module, how to list all the kernel symbols with their addresses? The kernel should not be re-compiled. I know "cat /proc/kallsyms" in an interface, but how to get them directly from kernel data structures, using functions like kallsyms_lookup_name . 回答1: Example Working module code: #include <linux/module.h> #include <linux/kallsyms.h> static int prsyms_print_symbol(void *data, const char *namebuf, struct module *module, unsigned long address) { pr_info("### %lx\t%s\n", address,

Using stdlib.h within a device driver

心不动则不痛 提交于 2019-12-21 23:19:10
问题 I am trying to write a device driver and I need to use system() function in the driver. To use system() we need to include <stdlib.h> , which dosnt seem to work from a driver. It says no such file or directory found. Is there an alternative to stdlib.h for device drivers? Or an alternative to system() ? 回答1: stdlib.h is a user space header. User space is that set of memory locations in which user processes (i.e., everything other than the kernel) run. A process is an executing instance of a

Reading kernel memory using a module

家住魔仙堡 提交于 2019-12-21 19:25:56
问题 As part of my project I need to read the kernel to get the memory address of system call table and system call address. Or in effect i need to extract the contents of the system call table and all the system calls. Till now I use GDB for this purpose. Is there any way so that I could do it using a kernel module. I am new the kernel module programming. Looking for advice from experts here. 回答1: Let me first start by saying reading arbitrary kernel memory is tricky business! And there are many

How do I use performance counters inside of the kernel?

血红的双手。 提交于 2019-12-21 17:37:35
问题 I want to access performance counters inside the kernel. I found many ways to use performance counters in user space, but can you tell me some way to use those in kernel space. Please don't specify tool name , I want to write my own code, preferably a kernel module. I am using Ubuntu with kernel 3.18.1. 回答1: http://www.cise.ufl.edu/~sb3/files/pmc.pdf http://www.cs.inf.ethz.ch/stricker/lab/doc/intel-part4.pdf The first pdf contains description on how to use pmc. The second contains the address

How to create proc entry under /proc/driver?

限于喜欢 提交于 2019-12-21 13:23:03
问题 I want to create a file under a /proc/driver directory. I would like to use a macro like proc_root_driver (or something else provided) rather than use "driver/MODULE_NAME" explicitly. I use create_proc_entry : struct proc_dir_entry *simpleproc_fops_entry; simpleproc_fops_entry = create_proc_entry(MODULE_NAME, 0400, NULL /* proc_root_dir */); After googling, I found suggestion to use proc_root_driver , but when I use it, I get the error proc_root_driver undeclared in this function And also,

Netlink Multicast Kernel Group

泪湿孤枕 提交于 2019-12-21 05:41:32
问题 The task I am trying to achieve is actually quite simple (multicast the string "TEST" to a userland daemon), but the kernel module doesn't compile. It stops with the error: passing argument 4 of ‘genlmsg_multicast_allns’ makes integer from pointer without a cast [enabled by default] But shouldn't it just be the multicast group I defined? Here is the code for "clarification": #include <linux/module.h> #include <net/sock.h> #include <linux/netlink.h> #include <linux/skbuff.h> #include <linux

How to find the list of processes using a particular kernel module?

二次信任 提交于 2019-12-20 17:47:24
问题 When I try to rmmod a module I get the error message "Error: Module in use" , lsmod | grep <module name> shows the count. Is there a way that would tell me which processes are using this particular kernel module/driver? 回答1: This was asked before, but there was no great answer, probably because there is no good way to accomplish to find what is using what. The best suggestion is to dmesg and look for any indication of what loaded the module. You might also try using the --force parameter to