haunteddevil619
haunteddevil619

Reputation: 141

unable to handle kernel null pointer dereference

I am getting the unable to handle kernel null pointer dereference error while using my kernel module. Here is what I am trying to do

inputfile = filp_open(kernel_args->infile, O_RDONLY, 0); //Open a file

if(inputfile == NULL) //Check if the file exists
{
    printk("\nInput file not found on drive\n");
    error = -ENOENT;
    goto quit;
}

But the kernel gives me an "oops" when checking for null. I dont know how to avoid it since I am checking for null and doing what I am supposed to do.

Upvotes: 0

Views: 2374

Answers (3)

sakura
sakura

Reputation: 1

Since filp_open will not return NULL while something went wrong, you should use IS_ERR to check error occurrence.

Like:

if(IS_ERR(inputfile))
    goto quit;

Upvotes: 0

LIUB
LIUB

Reputation: 364

Looks like you suspected the wrong pointer, the only pointer that may generate such oops in your code is kernel_args.

few more tips: - kernel is trusted code, you shouldn't check NULL pointers (unless you are writing kernel module test etc) - your printk usage is wrong, you are missing the printk log level, for example: printk(KERN_ALERT "Hello world\n");

Upvotes: 1

Azumi
Azumi

Reputation: 7

Check the validity of kernel space arguments.

Like :

if (!kargs)
    if(kargs->infile == NULL)

Upvotes: 0

Related Questions