Kernel Panic after trying to add a system call to Linux

659 views Asked by At

I was following this tutorial to try to add a system call to Linux, and I finished the section titled "Install the kernel", then rebooted the system. When it started back up, I got this message:

enter image description here

I am running Lubuntu 16.04 on VirtualBox. The only possible reason I could imagine in that the tutorial uses the linux 4.2.0 kernel, and I was using 4.4.0, but everything went fine until I rebooted the VM.

Could something as simple as using the 4.4.0 kernel instead of the 4.2.0 kernel done this? If so, what would I need to different from the tutorial to fix this?

Here is the steps the tutorial says to do (of course, I replaced 4.2.0 with 4.4.0 depending on the kernel I was using):

Install requirements:

sudo apt-get source linux-image-$(uname -r)
sudo cp -r linux-4.2.0 /usr/src
sudo apt-get update
sudo apt-get build-dep linux-image-$(uname -r)
sudo apt-get install kernel-package
sudo apt-get install libncurses-dev

Adding the system call:

cd /usr/src/linux-4.2.0
mkdir hello

Put the following in ./hello/hello.c:

#include <linux/kernel.h>

asmlinkage long sys_hello(void) {
        printk(“Hello World!\n”);  // printk prints the message to the kernels logs
        return 0; 
}

Put the following in ./hello/Makefile:

obj-y := hello.o

Update line 900 (line 916 for 4.4.0) of ./Makefile to look like this:

core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/

Edit ./arch/x86/entry/syscalls/syscall_64.tbl and add this line after the last 64 bit syscall (on 4.4.0 it was call 326 not 323):

323         64            hello             sys_hello

Add this line before the #endif in include/linux/syscalls.h:

asmlinkage long sys_hello(void);

Compile and install the kernel:

make menuconfig # accept default values
sudo make modules_install install

And finally, reboot, which is what causes the kernel panic on 4.4.0, but not 4.2.0.

Update:

I redid the tutorial on Lubuntu 15.10 which uses the 4.2.0 linux kernel, and it worked fine. So my question now is why does that tutorial crash the 4.4.0 kernel, but it works fine on 4.2.0?

0

There are 0 answers