I am trying to create a kernel module that changes the PID of a process. I searched in google and came across many articles that references this github
https://github.com/gravit0/changepid/blob/master/module/main.c
For the above github i took the following parts that should be responsible for the PID change.
static void* find_sym( const char *sym ) { // find address kernel symbol sym
static unsigned long faddr = 0; // static !!!
// ----------- nested functions are a GCC extension ---------
int symb_fn( void* data, const char* sym, struct module* mod, unsigned long addr ) {
if( 0 == strcmp( (char*)data, sym ) ) {
faddr = addr;
return 1;
}
else return 0;
};
// --------------------------------------------------------
kallsyms_on_each_symbol( symb_fn, (void*)sym );
return (void*)faddr;
}
static asmlinkage void (*change_pidR)(struct task_struct *task, enum pid_type type,
struct pid *pid);
static asmlinkage struct pid* (*alloc_pidR)(struct pid_namespace *ns);
change_pidR = find_sym("change_pid");
alloc_pidR = find_sym("alloc_pid");
On compilation i get the following error on the kallsyms_on_each_symbol() function
MODPOST /home/anastasis/projects/Module.symvers
ERROR: modpost: "kallsyms_on_each_symbol" [home/anastasis/projects/change_pid.ko] undefined!
How do i fix this?
PS. As a potential fix i installed a new kernel on a vm and i made sure that the option about kallsyms is enabled, but i still get the same ERROR.