kernel-module

How to stop Linux kernel threads on rmmod?

三世轮回 提交于 2019-12-02 15:54:11
I wrote the following code to create a kernel thread: #include<linux/init.h> #include<linux/module.h> #include<linux/kernel.h> #include<linux/kthread.h> #include<linux/sched.h> struct task_struct *task; int data; int ret; int thread_function(void *data) { int var; var = 10; return var; } static int kernel_init(void) { data = 20; printk(KERN_INFO"--------------------------------------------"); task = kthread_create(&thread_function,(void *)data,"pradeep"); task = kthread_run(&thread_function,(void *)data,"pradeep"); printk(KERN_INFO"Kernel Thread : %s\n",task->comm); return 0; } static void

ARM Cortex A8 PMNC read gives 0 after enabling also.. Any Idea/Suggestions?

跟風遠走 提交于 2019-12-02 15:03:25
问题 MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("user-mode access to performance registers"); int __init arm_init(void) { unsigned int value; /* enable user-mode access */ printk(KERN_INFO "enable user-mode access\n"); asm ("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(1)); /* Reading the value here--just to check */ asm ("MRC p15, 0, %0, c9, c14, 0\t\n": "=r"(value)); printk("value: %d\n", value); /* disable counter overflow interrupts (just in case)*/ printk(KERN_INFO "disable counter overflow

modinfo() equivalent INSIDE kernel?

孤街浪徒 提交于 2019-12-02 08:48:29
I have two modules A, B. A has a function f() that is globally acessible, i.e. the f() symbol is exported. B may want to call f() occasionally. But B should only call f() if module A is loaded. What is the best way for B to tell if A is loaded? Part b to this question is there is a way to check if f() is exported? I'm not sure which method is more effecient. I assume you load module B first, then optionally module A. My strategy would be to have A register a set of functions with B when A first initializes. B keeps a statically allocated function pointer (or a pointer to a struct full of

Cross Compiling Linux Arm Kernel with new driver module

六眼飞鱼酱① 提交于 2019-12-02 03:53:15
I am trying to include a driver for use on my arch linux arm machine. I tried using these steps to include the driver module, but my cross-compiled kernel with the added driver doesn't load. 1) Include the driver I want to add by making it have < M > beside it's name in make ARCH=arm menuconfig 2) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- (the path for my cross-compiling toolchain) 3) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- modules 4) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- install 5) run: make ARCH=arm CROSS_COMPILE=/home/z3/bin/arm- modules_install 6) copy my

Kernel module crash when reading system call table function address

≯℡__Kan透↙ 提交于 2019-12-01 23:00:13
问题 I am studying rootkits and trying to hook the system call table. As i can already dynamically retrieve the table's address from /boot/System.map-$(uname -r), i traced and isolated the problematic part of the code into an independent, simpler module, shown below. It tries to retrieve and display the address of the kill system call, but insmod returns "Killed" on module load, which is an error provoked specifically on the emphasized line. Kernel version : 5.2.0-3-amd64 Module : #include <linux

Multiple kernel modules intercepting same system call and crash during unload

大城市里の小女人 提交于 2019-12-01 22:52:41
I'm working on system call interception (for open() system call) and I got one problem: I have two kernel modules ( mod1 and mod2 ) and both of them are trying to intercept open() syscall. I've loaded mod1 first and then mod2 . The mod1 intercepted open() by: original_open1 = sys_call_table[__NR_open]; sys_call_table[__NR_open] = mod1_open; Here original_open1 would be sys_open . After this, mod2 intercepted open() by: original_open2 = sys_call_table[__NR_open]; sys_call_table[__NR_open] = mod2_open; Here, original_open2 would be mod1_open() since mod1 was loaded first. Now, the problem is:

get filesystem mount point in kernel module

痞子三分冷 提交于 2019-12-01 21:06:39
问题 I want to get the filesystem mount point for a file system in my kernel module, which is a stackable filesystem. Eg. if /home/ab/abc is a file and /home is mounted on a different filesystem I want to have a dentry or path struct to /home. I want to do this in a module without modifying kernel code. e.g. there is a file in /home/user/ and now I want to know in which partition this file is. For example this file might be in the partition same as "/" or this file might be in another partition

get filesystem mount point in kernel module

僤鯓⒐⒋嵵緔 提交于 2019-12-01 19:16:18
I want to get the filesystem mount point for a file system in my kernel module, which is a stackable filesystem. Eg. if /home/ab/abc is a file and /home is mounted on a different filesystem I want to have a dentry or path struct to /home. I want to do this in a module without modifying kernel code. e.g. there is a file in /home/user/ and now I want to know in which partition this file is. For example this file might be in the partition same as "/" or this file might be in another partition mounted on /home or /home/user. ugoren You can get the list of file systems from current->namespace . By

How to get details of all modules / drivers that were initialized / probed during the Linux kernel boot?

青春壹個敷衍的年華 提交于 2019-12-01 17:57:14
I need the sequence of modules/drivers that are invoked|initialized|probed during the kernl boot. Can you please let me know if any flash command-line option available to get this sequence ? Passing the option "initcall_debug" on the kernel command line will cause timing information to be printed to the console for each init routine of built-in drivers. The initcalls are used to initialize statically linked kernel drivers and subsystems and contribute a significant amount of time to the Linux boot process. (Loadable modules are not available until after the root filesystem has been mounted.)

How to get details of all modules / drivers that were initialized / probed during the Linux kernel boot?

被刻印的时光 ゝ 提交于 2019-12-01 17:32:10
问题 I need the sequence of modules/drivers that are invoked|initialized|probed during the kernl boot. Can you please let me know if any flash command-line option available to get this sequence ? 回答1: Passing the option "initcall_debug" on the kernel command line will cause timing information to be printed to the console for each init routine of built-in drivers. The initcalls are used to initialize statically linked kernel drivers and subsystems and contribute a significant amount of time to the