Linux Kernel Programming: "Unable to handle kernel NULL pointer dereference"

34,518

Solution 1

Sounds like a pointer which currently has the NULL value (zero) is being dereferenced. Assign an address to the pointer before dereferencing it.

e.g.

int x = 5;
int * x_ptr = NULL;

x_ptr = &x; // this line may be missing in your code

*x_ptr += 5; //can't dereference x_ptr here if x_ptr is still NULL

Solution 2

It means the kernel tried to deference a null pointer. This generates a page fault which can't be handled in the kernel- if it's running a user task (but in kernel space), it generally makes an "Oops" which (uncleanly) kills the current task and may leak kernel resources. If it's in some other context, e.g. an interrupt, it generally causes a kernel panic.

Solution 3

The kernel tries to read from address 0, which your kernel apparently treats specially (good thing!). As the kernel has no way to just kill itself like we know from user mode applications (those would have received a Segmentation Fault), this error is fatal. It will have probably panic'ed and displayed that message to you.


http://en.wikipedia.org/wiki/Null_pointer#The_null_pointer

Share:
34,518
Daniel Silveira
Author by

Daniel Silveira

Updated on January 18, 2020

Comments

  • Daniel Silveira
    Daniel Silveira over 4 years

    I'm writing a Linux module and getting:

    Unable to handle kernel NULL pointer dereference
    

    What does it mean?

  • ctuffli
    ctuffli over 15 years
    Your analysis is correct, but the comment in the code is wrong. *x_ptr += 5 is OK because x_ptr now has the address of x (a stack address) and thus can be dereferenced.