kernel-module

Create ProcFS entry in /proc/net

允我心安 提交于 2019-12-10 11:19:27
问题 I try to create an entry inside /proc/net from a kernel module, like this: struct file *filp = filp_open("/proc/net", O_RDONLY, 0); struct proc_dir_entry *parent = PDE(filp->f_dentry->d_inode); filp_close(filp, NULL); proc_file = create_proc_entry("test", 0644, parent); Crudely taken from here Why does it create my entry like /proc/test instead of /proc/net/test ? (Note: I'd like too use create_proc_entry , not proc_create .) 回答1: In recent kernels you won't find create_proc_entry() anymore,

Address mapping of PCI-memory in Kernel space

感情迁移 提交于 2019-12-10 06:59:55
问题 I'm trying to read and write to and PCI-device from a loadable kernel module. Therefore I follow this post: pci_enable_device(dev); pci_request_regions(dev, "expdev"); bar1 = pci_iomap(dev, 1, 0); // void iowrite32(u32 val, void __iomem *addr) iowrite32( 0xaaaaaaaa, bar1 + 0x060000); /* offset from device spec */ But at the end the device doesn't do his work as expected. Then I look to the address behind bar1 and found a very big value ffffbaaaaa004500 . At this point I don't really

kernel driver reading ok from user space, but writing back is always 0

戏子无情 提交于 2019-12-09 17:53:45
问题 So I'm working my way through kernel driver programming, and currently I'm trying to build a simple data transfer between application and kernel driver. I am using simple character device as a link between these two, and I have succeeded to transfer data to driver, but I can't get meaningful data back to user space. Kernel driver looks like this: #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> /* printk() */ #include <linux/errno.h> /* error codes */ #include

Device driver without the device?

故事扮演 提交于 2019-12-09 13:56:14
问题 I'm creating an application that needs to use some kernel level modules, for which I've divided the app into 2: one user-level program and one kernel level program. After reading about device drivers and walking through some tutorials, I'm a little confused. Can there be a device driver without any specific device associated with it? Is there anything other than the device driver (kernel code or something) which works in kernel mode? How do anti-virus programs and other such applications work

UDP packet send with linux-kernel module without using sockets

亡梦爱人 提交于 2019-12-09 07:33:34
问题 I am writing a kernel module which creates a IP packet. Now i want to send this packet but haven't created any socket for it's transmission. is there any way to send it directly with the help of kernel routines. as i have tracked the linux kernel code for packet transmission there is a function defined in net/core/dev.c named as dev_hard_start_xmit() . can we use it? Actually i don't want to use sockets. 回答1: You don't need a socket to send a UDP packet in kernel, you just need to allocate an

Loading a custom kernel module

青春壹個敷衍的年華 提交于 2019-12-08 05:16:14
问题 My company is researching a possible port of our Linux application to Android. One of the key parts of this application is our kernel module. I have no idea about how Android devices work and no device at hand, but i have an extensive Linux kernel experience. I can imagine a way to build an LKM for Android but i have absolutely no idea is it actually possible for an Android application to setup its custom kernel module for loading on an Android device. Do Android devices actually run module

why am I getting an “implicit declaration of function 'ndo_get_stats' ” error?

我的未来我决定 提交于 2019-12-08 05:13:14
问题 I'm building a VERY SIMPLE kernel module for gathering some stats from the network card here's the code, I keep getting an error implicit declaration of function 'ndo_get_stats' . I'm not sure why... #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/netdevice.h> /* Needed for netdevice*/ static int __init hello_start(void) { struct net_device *dev; printk(KERN_INFO "Loading Stats module...\n"); printk(KERN_ALERT "Hello

Hijacking sys calls

馋奶兔 提交于 2019-12-07 12:24:55
问题 I'm writing a kernel module and I need to hijack/wrap some sys calls. I'm brute-forcing the sys_call_table address and I'm using cr0 to disable/enable page protection. So far so good (I'll make public the entire code once it's done, so I can update this question if somebody wants). Anyways, I have noticed that if I hijack __NR_sys_read I get a kernel oops when I unload the kernel module, and also all konsoles (KDE) crash. Note that this doesn't happen with __NR_sys_open or __NR_sys_write . I

casting a pointer to integer issues warning on 64bit arch

天涯浪子 提交于 2019-12-07 09:16:31
问题 I'm writing a linux kernel module that makes use of the exported symbol open_exec struct file *open_exec(const char *name) It returns a pointer, and I can check for an error with the IS_ERR macro: if (IS_ERR(file)) return file; During compile time, I get this warning: warning: return makes integer from pointer without a cast This is because my function here returns an integer. If I try to cast it: return (int) file; I don't get a warning on my 32bit machine, but I do on my 64bit machine:

why am I getting an “implicit declaration of function 'ndo_get_stats' ” error?

拟墨画扇 提交于 2019-12-07 06:57:26
I'm building a VERY SIMPLE kernel module for gathering some stats from the network card here's the code, I keep getting an error implicit declaration of function 'ndo_get_stats' . I'm not sure why... #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/netdevice.h> /* Needed for netdevice*/ static int __init hello_start(void) { struct net_device *dev; printk(KERN_INFO "Loading Stats module...\n"); printk(KERN_ALERT "Hello world\n"); dev = first_net_device(&init_net); while (dev) { printk(KERN_INFO "found [%s] and it's [%d]\n