vidzi
vidzi

Reputation: 183

insmod: error when inserting kernel module

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.

Upvotes: 2

Views: 4019

Answers (2)

shubham
shubham

Reputation: 11

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.

Upvotes: 1

vonbrand
vonbrand

Reputation: 11791

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.

Upvotes: 2

Related Questions