user277465
user277465

Reputation:

"Unknown symbol in module" error while inserting kernel module

I created the following error-prone kernel module for educational purposes.

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
#include <asm/uaccess.h>

void *(my_funptr)(void);

int bug1_write(struct file *file,
               const char *buf,
               unsigned long len) {
        my_funptr();
        return len;
}

int init_module(void) {
        static struct proc_dir_entry *proc;
        proc = create_proc_entry("bug1", 0666, 0);
        proc->write_proc = bug1_write;
        return 0;
}

I compiled it using the following Makefile :-

obj-m += bug1.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Compiling gave me :-

$ make
make -C /lib/modules/3.0.0-13-generic-pae/build M=/home/fusion/kernel_exp modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-13-generic-pae'
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "my_funptr" [/home/fusion/kernel_exp/bug1.ko] undefined!
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-13-generic-pae'

Trying to install the kernel module :-

$ sudo insmod bug1.ko
[sudo] password for fusion:
insmod: error inserting 'bug1.ko': -1 Unknown symbol in module

Given that the code is intentionally buggy, I'd really like to be able to compile and insert the kernel module -- is there any compiler flag I could use to be able to do this? Any documentation you could point me toward, that I could refer? Thanks.

Upvotes: 0

Views: 2235

Answers (1)

CL.
CL.

Reputation: 180060

This is a C problem.

void *(my_funptr)(void);

This declares a function named my_funptr that returns a pointer.

To declare a pointer to a function, use:

void (*my_funptr)(void);

Upvotes: 1

Related Questions