kernel-module

Linux Kernel Module - Sharing variables between source files

痴心易碎 提交于 2019-12-11 05:24:41
问题 I'm trying to link a kernel module to a non-LKM source file. The problem is, I'm running into some issues. The names of the two files are chardev.c (the LKM) and foo.c. My Makefile: obj-m += chardev.o obj-y += foo.o all: make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules $(CC) test.c -o test clean: make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean rm test Inside of chardev.c I've the following line of code: extern int foo; , and inside foo I've the following line of

Is it possible to communicate between two linux kernel module via netlink?

北慕城南 提交于 2019-12-11 03:56:25
问题 As all know, netlink it's user/kernel space communication mechanism. I want to communicate from my kernel module to an another. Another kernel module already has the netlink interface. Is it possible to make connection from kernel module to netlink, as we do it in user space? 回答1: Short answer: No. If you want to communicate between two kernel modules you should use symbols (global variables or functions) which are exported by the other kernel module. netlink Sockets are used to communicate

Linux kernel module to check memory integrity

心不动则不痛 提交于 2019-12-11 02:43:01
问题 I'm writing a kernel module that checks the integrity of code segments for running tasks by controlling checksums. I ran into a few hurdles: How can I get the module_list variable if it isn't exported by the kernel (there is no such symbol in ksyms )? I can see all modules calling the lsmod command, so how can I get it in my module? While my module is running it shows that some code segments have been changed. It always happens with certain libraries. Why does it happen? I thought that code

understanding LINUX_VERSION_CODE

拜拜、爱过 提交于 2019-12-11 01:04:06
问题 Im wrinting a kernel module and i found a problem testing my LKM again centos 7. uname -a print 3.10.0-123.13.2.el7.x86_64, and i'm compiling my KM with this kernel-headers /usr/src/kernels/3.10.0-123.13.2.el7.x86_64/ and using LINUX_VERSION_CODE to define my code sections. my problem is, the compilation fail because the kernel-headers include code added in more new kernel version but LINUX_VERSION_CODE returns 3.10. for example, nf_hookfn was modify in kernel 3.13 and i have this

Module parameter permission

你说的曾经没有我的故事 提交于 2019-12-11 00:57:11
问题 I'm new to kernel programming. When I was going through module_param , I was confused by the permission value 0. It was explained that it won't get an entry in sysfs, while the others like S_IRUGO would get an entry. I couldn't understand the concept. What does the perm value 0 indicate? When do we need a sysfs entry? What is the need for that? Kindly guide me. Thanks in advance. 回答1: You can module parameters in some ways to a kernel module. Assuming a kernel module foo with a parameter

Listening for netlink broadcasts in a kernel module

℡╲_俬逩灬. 提交于 2019-12-10 17:47:58
问题 The SELinux module sends out a netlink broadcast to any listening sockets. I'm wondering if it's possible to listen for netlink broadcast from within another kernel module? From SELinux netlink code: netlink_broadcast(selnl, skb, 0, SELNLGRP_AVC, GFP_USER); 回答1: I found that you can listen for netlink data through the use of regular sockets. And, yes, it's possible in kernel-space. You basically need to create and bind to a socket: struct sock *sock = NULL; struct sockaddr_nl addr = { 0 }; /*

Get file name/path from a file descriptor from a Linux kernel module?

时光怂恿深爱的人放手 提交于 2019-12-10 17:05:24
问题 In a linux kernel module is there a way to get a file name/path from an unsigned int fd ? I'm aware of this answer: How can I get a filename from a file descriptor inside a kernel module? but if I understand the code right, I need a struct files_struct too. EDIT: Please stop voting as duplicated as it isn't. I'm asking for a way to get file's name/path in plain C from a kernel module, not using system tools. Said in another way: running readlink on /procself/fd/ is not a good answer. EDIT 2:

How to use exported symbols optionally only if they are present in an insmoded Linux Kernel module?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 14:15:40
问题 I am modifying a Linux Kernel to add some functionality to the Linux Virtual Server (LVS). I developed a module (which I called net/netfilter/ipvs/ip_vs_utils.c ) with some functions to be used when load-balancing. All the functions here are exported using EXPORT_SYMBOL() . This module, logically is not loaded all the time. My intention is to allow the user to decide if he want to use this additional functionality or not (loading or unloading the module). My question is how could I invoke

How to find the version of a compiled kernel module?

旧巷老猫 提交于 2019-12-10 12:55:40
问题 I am in a situation where it would be very convenient to find the version of a loaded kernel module by querying the loaded module or .ko file. Is there a standard way to do this without digging into the source code? 回答1: $ apropos modinfo modinfo (8) - display information about a kernel module $ modinfo cpuid.ko filename: cpuid.ko author: H. Peter Anvin <hpa@zytor.com> description: x86 generic CPUID driver license: GPL vermagic: 2.6.37 SMP preempt mod_unload PENTIUM4 gcc-4.4.5 depends: 回答2:

How to put a check in the code to ensure the inter kernel module dependency - Linux Kernel?

半世苍凉 提交于 2019-12-10 12:16:41
问题 I have two modules. I want the modules to be interdependent while doing insmod or rmmod. Currently, my module2 is dependent on module1. If I insert module1 then module2, it works fine. On the other hand, the reverse of it doesn't work. This is logical in explanation. However, I want a neat code to avoid such dependencies. If I do insmod of mod2 then mod1 should automatically be insmod, Or some other decent way to tackle this issue. Here are my two modules. static int multiplyMod1(int a, int b