kernel-module

Why the number of minor devices are not listed here in this program in /dev?

大兔子大兔子 提交于 2019-12-24 16:25:26
问题 I want to create the number of minor character drivers for my module. I want to see it at the /dev/ . However, I see only one driver. What is the problem in my code? What should be the right code? #include <linux/init.h> #include <linux/module.h> /** needed by all modules **/ #include <linux/kernel.h> /** This is for KERN_ALERT **/ #include <linux/fs.h> /** for file operations **/ #include <linux/cdev.h> /** character device **/ #include <linux/device.h> /** for sys device registration in

Syscall table hacking toy-example does not work on 64 bit

馋奶兔 提交于 2019-12-24 10:11:33
问题 This is a very simple module I'm working on. It simply replaces a sys_ni_syscall with my new syscall log_message . Here the source file template_syscall_hacking.c : #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/unistd.h> #include <asm/cacheflush.h> #include <asm/page.h> #include <asm/current.h> #include <linux/sched.h> #include <linux/kallsyms.h> #define MODNAME "SYSCALL HACKING TEMPLATE" MODULE

Nf_hook_ops returns incompatible pointer when assigning to hook_func -C -Linux -Netfilter

蓝咒 提交于 2019-12-24 09:31:18
问题 I am trying to write my own Netfilter kernel module on Ubuntu 16.04 LTS, I am trying to assign hook_func to nfho.hook but I get the following error: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types] nfho.hook = hook_func; I have looked on other solutions, mostly ended up on double checking parameters including changing *skb to **skb . I have read that the parameters might depend on the kernel version but couldn't find how to find out the right parameters to

kprobe handler not getting triggered for specific function

 ̄綄美尐妖づ 提交于 2019-12-24 09:24:27
问题 Am trying to intercept below function in module using kprobes. "register_kprobe" passed for this function but Kprobe handler is not getting triggered when function is called. Strangely it starts working (kprobe handler gets called) if I print function address inside probing function. It works for other functions in kernel as well. Why is kprobe handler not getting triggered and what difference printing function address is making? system has 3.10 kernel on x86_64 installed. Not working code:

kprobe handler not getting triggered for specific function

故事扮演 提交于 2019-12-24 09:21:13
问题 Am trying to intercept below function in module using kprobes. "register_kprobe" passed for this function but Kprobe handler is not getting triggered when function is called. Strangely it starts working (kprobe handler gets called) if I print function address inside probing function. It works for other functions in kernel as well. Why is kprobe handler not getting triggered and what difference printing function address is making? system has 3.10 kernel on x86_64 installed. Not working code:

Unknown symbol flush_tlb_all (err 0)

霸气de小男生 提交于 2019-12-24 09:16:01
问题 I tried to make a simple kernel module invalidating all tlb entries through user-level ioctl. Below is my example code [flush_tlb.c] /* * flush_tlb.c */ #include <linux/uaccess.h> #include <linux/fs.h> #include <linux/miscdevice.h> #include <linux/module.h> #include <linux/mm.h> #include <asm/tlbflush.h> #include <asm/tlb.h> #include "flush_tlb.h" MODULE_LICENSE("GPL"); static long flush_tlb_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { int ret = 0; unsigned int size = _IOC

Error in reading a file Within linux module

折月煮酒 提交于 2019-12-24 01:16:17
问题 Edit: I have written following module to filter websites.I am able to sniff DNS Packet(question field Domain Name ) requested by User and compare with block[]="www.facebook.com" . If matched, drop the packet.Now I inserted a read code (see after //Read File here in bellow code)to read website list written in a file (instead of Hard coding block[]=) and compare it with DNS question.right Now I am able to compile module successfully but not able to load it properly.Is it because of make Warning

Error checking in a '.read' function in kernel module

只谈情不闲聊 提交于 2019-12-23 23:40:49
问题 What should a .read operation return in a kernel module character device? I know that copy_to_user(...) returns the number of bytes not copied and on success returns 0. I saw examples which make the read() function return -EFAULT if copy_to_user(...) returns anything other than 0. But then upon success this says to return 0 and this says to return the number of bytes read. What should be returning? Also should I check the params of static ssize_t dev_read(struct file *filep, char *buffer,

Cross compile FTDI VCP Driver for embedded linux arm

大憨熊 提交于 2019-12-23 19:24:27
问题 I'm trying to cross compile the FTDI VCP Driver for my embedded arch linux arm machine. I downloaded the source files from http://www.ftdichip.com/Drivers/VCP.htm onto my host machine which is running kernel: 2.6.32-54-generic-pae When running the Makefile, I get errors related to kernel headers, ie: asm/thread_info.h file not found. I realize that this means that my asm symlink is broken, so I tried linking it to linux-headers-2.6.32-54/include/asm-generic but the contents of that directory

Adding new IOCTL's into kernel (number range)

萝らか妹 提交于 2019-12-23 16:41:31
问题 I'm writing new kernel module and I add implement new IOCTL's. Is there any rule that I should follow with IOCTL's numbering ? Maybe there is some "user range" ? I work with kernel 2.6.21 on embedded platform. 回答1: IOCTLs are defined to be device dependent -- if there were "standard" ioctls for people to implement, these would be syscalls like read and write . There are a few conventions for ioctl numbers: the parameter direction (in, out, both) is encoded in the ioctl number in two bits.