kernel-module

How to get current hour (time of day) in linux kernel space

a 夏天 提交于 2019-11-28 20:27:06
I'm writing a kernel module that checks to see if the time is between two specified hours, and disables input if it is. This has to do with me wanting to make sure I go to bed early. (I know I could also use any number of different techniques including cron etc, but I wanted to learn kernel programming...) As a first version, I therefore check if the current hour is between start and end, which are set via parameters to the module. My question is therefore : How do I get the current hour? I have no access to the usual time functions in the standard library because I am in kernel space. I'm

How do I configure modprobe to find my module?

邮差的信 提交于 2019-11-28 15:43:25
I'm trying to get a kernel module to load at boot. If I run insmod /path/to/module.ko , it works fine. But this has to be repeated every time I reboot. If I run modprobe /path/to/module.ko , it can't find the module. I know modprobe uses a configuration file, but I can't get it to load the module even after adding /path/to/module.ko to /etc/modules. What is the proper configuration? You can make a symbolic link of your module to the standard path, so depmod will see it and you'll be able load it as any other module. sudo ln -s /path/to/module.ko /lib/modules/`uname -r` sudo depmod -a sudo

Is there a way to figure out what is using a Linux kernel module?

空扰寡人 提交于 2019-11-28 15:27:33
If I load a kernel module and list the loaded modules with lsmod , I can get the "use count" of the module (number of other modules with a reference to the module). Is there a way to figure out what is using a module, though? The issue is that a module I am developing insists its use count is 1 and thus I cannot use rmmod to unload it, but its "by" column is empty. This means that every time I want to re-compile and re-load the module, I have to reboot the machine (or, at least, I can't figure out any other way to unload it). sdaau Actually, there seems to be a way to list processes that claim

netfilter-like kernel module to get source and destination address

旧巷老猫 提交于 2019-11-28 14:28:07
I read this guide to write a kernel module to do simple network filtering. First, I have no idea of what below text this means, and what's the difference between inbound and outbound data packet(by transportation layer)? When a packet goes in from wire, it travels from physical layer, data link layer, network layer upwards, therefore it might not go through the functions defined in netfilter for skb_transport_header to work. Second, I hate magic numbers, and I want to replace the 20 (the length of typical IP header) with any function from the linux kernel's utilities( source file ). Any help

kvm: module verification failed: signature and/or required key missing - tainting kernel

家住魔仙堡 提交于 2019-11-28 11:53:44
I'm using Ubuntu 14.04 LTS and kernel version 3.13.11.4 . I'm trying to load patched KVM modules kvm and kvm-intel and I'm getting the following errors kvm: module verification failed: signature and/or required key missing - tainting kernel and kvm: module has bad taint, not creating trace events . The source used is the same source that created the image that I am currently running. I've check the symbols and made sure to the error isn't cause by not including EXPORT_SYMBOL_GPL() in the patched files where I exported functions. I've also seen some stuff about different kernel versions causing

Get current time in seconds in kernel module

房东的猫 提交于 2019-11-28 11:09:40
What is the standard way to get the current time in seconds (since the epoch) in a kernel module? I have seen techniques involving getting xtime which are very long-winded and involve while-loops and locks. There must be a better way. [This is not a duplicate. I have looked through previous questions on SO. The answers to many of these either don't specify the function used, or incorrectly refer to time.h which is not allowed in the kernel] cnicutar You can use getnstimeofday for that. /* getnstimeofday - Returns the time of day in a timespec */ void getnstimeofday(struct timespec *ts) where

Why does call_usermodehelper fail most of the times?

Deadly 提交于 2019-11-28 09:52:14
问题 From a kernel module, I am trying to use call_usermodehelper function to execute an executable sha1 which takes a file as argument and writes the SHA1 hash sum of the file to another file (named output). The executable works perfectly. int result=-1; name = "/home/file" char *hargv[] = {"/home/sha1", name,NULL }; char *henvp[] = {"HOME=/", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL }; result = call_usermodehelper("/home/sha1", hargv, henvp, 1); But most of the times call_usermodehelper

Why printk doesn't print message in kernel log(dmesg)

不问归期 提交于 2019-11-28 08:25:30
问题 I wrote small kernel module code as mentioned below, I am testing it in ubuntu 14.04 #include <linux/module.h> #include <linux/version.h> #include <linux/kernel.h> #include <linux/init.h> int init_mod_func(void) { printk(KERN_INFO "My module inserted\n "); return 0; } void cleanup_mod_func(void) { printk(KERN_INFO "My module removed\n "); } module_init(init_mod_func); module_exit(cleanup_mod_func); MODULE_AUTHOR("Ankur"); MODULE_DESCRIPTION("TEST MODULE"); MODULE_LICENSE("GPL"); Now when I

How to append data on a packet from kernel space?

半城伤御伤魂 提交于 2019-11-28 07:52:05
I am trying to append some data on a packet from kernel space. I have an echo client and server. I type in the command line like: ./client "message" and the server just echoes it back. The server was run with ./server . Now, the client and server are on two different machines (may be VMs). I am writing a kernel module which runs on the client machine. Its work is to append "12345" after "message" while the packet goes out of the machine. I am presenting the code below. /* * This is ibss_obsf_cat.c */ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h> #include

Linux: modpost does not build anything

扶醉桌前 提交于 2019-11-28 07:35:39
问题 I am having problems getting any kernel modules to build on my machine. Whenever I build a module, modpost always says there are zero modules: MODPOST 0 modules To troubleshoot the problem, I wrote a test module (hello.c): #include <linux/module.h> /* Needed by all modules */ #include <linux/kernel.h> /* Needed for KERN_INFO */ #include <linux/init.h> /* Needed for the macros */ static int __init hello_start(void) { printk(KERN_INFO "Loading hello module...\n"); printk(KERN_INFO "Hello world