I was referring:
http://www-users.cs.umn.edu/~boutcher/kprobes/kprobes.txt.html to understand kprobe. I used kprobe_example.c as given in the doc.
I compiled it using the makefile (code taken from the same document)
I got compilation errors because my kernel version is 4.2 and some fields were changed in struct pt_regs. So I replaced eip with ip and eflag with flag in kprobe_example.c which is https://gist.github.com/murlee417/87c2eb43a6afa1954b05404a07813e81. Then I was able to compile it successfully.
Now, as a root user, I did:
#insmod kprobe_example.ko
and I got:
insmod: ERROR: could not insert module kprobe_example.ko: Operation not permitted
My message buffer has:
#dmesg
[ 4537.478408] Couldn't find do_fork to plant kprobe
Please help me to resolve this error and make insmod work.
In x86 do_fork() is known as sys_fork(), so change the code as below
/* For each probe you need to allocate a kprobe structure */
static struct kprobe kp = {
//.symbol_name = "do_fork",
.symbol_name = "sys_fork",
};
Related
I am trying to build custom Micropython firmware with ethernet support for STM32F407VE. I've forked working board without ethernet support and trying to modify it with ethernet support.
Things I have done:
defined MICROPY_HW_ETH_* variables in mpconfigboard.h
added MICROPY_PY_LWIP = 1 to mpconfigboard.mk
added ETH_* pins to pins.csv
added additional pins from Port F, G, H, I to pins.csv
Here is my modified board: https://github.com/untitledlt/BLACK_F407VE
Now when I'm trying to build it, i get:
In file included from eth.c:31:
eth.c: In function 'eth_mac_init':
eth.c:163:106: error: implicit declaration of function 'STATIC_AF_ETH_RMII_REF_CLK'; did you mean 'STATIC_AF_ETH_RMII__REF_CLK'? [-Werror=implicit-function-declaration]
mp_hal_pin_config_alt_static(MICROPY_HW_ETH_RMII_REF_CLK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, STATIC_AF_ETH_RMII_REF_CLK);
^~~~~~~~~~~~~~~~~~~~~~~~~~
pin_static_af.h:42:48: note: in definition of macro 'mp_hal_pin_config_alt_static'
mp_hal_pin_config(pin_obj, mode, pull, fn_type(pin_obj)) /* Overflow Error => alt func not found */
^~~~~~~
cc1: all warnings being treated as errors
make: *** [build-BLACK_F407VE/eth.o] Error 1
What am I doing wrong here?
There was a bug (typo) in Micropython branch.
ETH_RMII__REF_CLK should be replaced with ETH_RMII_REF_CLK in ports/stm32/boards/stm32f405_af.csv file.
It's already fixed by https://github.com/micropython/micropython/pull/5308.
All Credit goes to Mike Causer.
Thanks, Mike!
I am new to kernel module programming and got some problem while compiling some old kernel code.
The code is trying to get tty for the current task using current->tty, but when I compile, I get following an error
error: ‘struct task_struct’ has no member named ‘tty’
my_tty = current->tty;
I checked the linux source code , tty is not there any more.
The 'current' is of task_struct,but tty not in struct task_struct any more.
How can I access them in version 3.13.0-24?
I need to directly write to and read from physical memory for my research and the only way I can think of doing it is with a kernel module. I found this generic device driver called phram that I've been trying to use to map memory and then write to and read from it but I'm having trouble mapping more than ~1.5GB. In my 16GB system, I have the OS usage constrained to 500MB at 0x0. Here are my kernel parameters: mem=500M memmap=500M#0. When I try to load the phram module with more than ~1.5GB like this:
sudo modprobe phram phram=test,500Mi,15Gi
I get this error message:
modprobe: ERROR: could not insert 'phram': Input/output error
And this in dmesg:
[ 247.303346] modprobe:1402 conflicting memory types 1f400000-3df400000 write-back<->write-combining
[ 247.303350] reserve_memtype failed [mem 0x1f400000-0x3df3fffff], track uncached-minus, req uncached-minus
[ 247.303352] ioremap reserve_memtype failed -16
[ 247.303376] phram: ioremap failed
[ 247.303393] phram: `test,500Mi,15Gi' invalid for parameter `phram'
I can't find any documentation on phram other than the source code. From what I have researched ioremap() (the mapping call in phram) shouldn't have a max size so I don't know where the issue could be. The dmesg output is a little too cryptic for me so if somebody could at least translate it that would also be a significant help.
Thanks!
I'm implementing the ad hoc AODV routing protocol on ARM based system Sabrelite http://boundarydevices.com/products/sabre-lite-imx6-sbc/ ......... After configuring and building the kernel that match to the one used on the board. I get the following errors:
error: unknown type name '__kernel_ulong_t'
__kernel_ulong_t loads[3]; /* 1, 5, and 15 minute load averages */
error: unknown type name '__kernel_ulong_t'
__kernel_ulong_t totalram; /* Total usable main memory size */
^
/usr/local/oecore-x86_64/sysroots/cortexa9hf-vfp-neon-oe-linux-gnueabi/usr/include/linux/sysinfo.h:18:2: error: unknown type name '__kernel_ulong_t'
__kernel_ulong_t freeram; /* Available memory size */
^
error: unknown type name '__kernel_ulong_t'
__kernel_ulong_t sharedram; /* Amount of shared memory */
^
/usr/local/oecore-x86_64/sysroots/cortexa9hf-vfp-neon-oe-linux-gnueabi/usr/include/linux/sysinfo.h:28:22: error: '__kernel_ulong_t' undeclared here (not in a function)
char _f[20-2*sizeof(__kernel_ulong_t)-sizeof(__u32)]; /* Padding: libc5 uses this.. */
^
make: * [nl-arm.o] Error 1
As the errors suggested, it is something along with the cross compilation source tree but i don't know how on earth i get those errors because the used SDK works perfectly.
I followed the tutorial cited in the README file provided by AODV packages..
Has anyone ever experienced implementing AODV on ARM ? and did they got these errors
How can i resolve these issues ?
Thanks
well, the solution was to properly upgrade the makefile to work for post 2.6 kernel. If you happen to read this page: write your makefile like this:http://lwn.net/Articles/21823/
I am trying to implement a kernel module, which can access the task_struct of a user process, whose Process ID is already known to me. I am using find_get_pid and pid_task to get the task_struct of the process:
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/pid.h>
#include <linux/pid_namespace.h>
int init_module( void )
{
//Declaring the variables
int p_id = 6980; //6980 is the process ID of my user process
struct pid *pid_struct;
struct task_struct *task;
// Trying to access the variables of the p_id
pid_struct = find_get_pid(p_id);
task = pid_task(pid_struct, PIDTYPE_PID);
//Printing the info from the task_struct
printk( KERN_INFO "*** [%d]\n",task->pid);
return 0;
}
void cleanup_module( void )
{
return;
}
It is getting compiled successfully and I am getting *.ko file, but when I am trying to insert it in the kernel, it is giving me an error:
insmod: error inserting 'main.ko': -1 Unknown symbol in module
Dmesg is giving me the following output:
main: Unknown symbol find_get_pid (err 0)
I dont know how to proceed, it would be really appreciated if anyone can help me.
Check carefully what the functions you want to use are called.
Also remember that much of what is "core kernel" (that presumably includes frob_task_by_pid_hardand its ilk) is GPL-only, so unless you declare your module's licence as GPL you won't go anywhere. Also be so kind to fill in the other boilerplate data on the module: MODULE_AUTHOR, MODULE_DESCRIPTION, MODULE_LICENSE at least.
There could be another reason for failure while loading kernel module like if it shows error as "insmod :ERROR: .ko operation not permitted". your kernel is booting with secure boot option on latest PC which must be disabled to avoid failure in loading/inserting a kernel module.this can be done by using below commands.
sudo apt install mokutil
sudo mokutil --disable-validation
or you can search for How to disable secure boot option for your specific OS.