HW4: Linux System Calls

Part 1: Building a custom kernel in Arch Linux

Part 2: Reducing kernel build time

In this part, you will reduce your kernel build time drastically.

  1. Go back to the part 1 instruction (and Arch KCT). Regenerate .config so that it contains only those modules that you are currently using. This will cut down the number of modules from something like 3000 to under 100. Here is how.

  2. When you are hacking the kernel code, a lot of times you make simple changes to some .c files. If you didn’t touch any header file, the modules will not be rebuilt when you run make, thus there is no reason to reinstall all modules.

    Make a stripped-down version of your mmk script called mko (for “make kernel only”), which does only the following 3 things:

    Place mko alongside mmk, in your linux-4.4.50 directory.

Now you have mmk to build the kernel, install modules, and rebuild vboxguest, but much, much faster than before thanks to the smaller .config. In addition, you have mko for quick build & reboot cycles when you didn’t recompile any modules. You are ready to add some system calls to your kernel.

Part 3: Making the Linux source tree a sparse git repo

You will make the linux-4.4.50 directory a git repo, but a sparse one. What do I mean by that? You will leave most of the files in the directory untracked. You will track only those files that you modify from the original version.

Part 4: The supermom() System Call

Implement supermom() system call that checks if the parent process of the calling process has a superuser privilege.

You must read LKD chapter 5 in order to understand how adding a system call works in general. Unfortunately, some of the steps described in the LKD book have changed since the book was written.

You are welcome to consult any source for the procedure to add a system call into a recent kernel. Here is a very good one that I verified that it works: http://www.cs.albany.edu/~sdc/CSI500/Fal13/Labs/OwnSyscallV3plus/OwnSyscallFE.html

At the time of this writing, Linux kernel has about 380 system calls. New system calls are constantly being added to the Linux kernel. Let’s leave some room and use 400 for our supermom() system call.

Please put your system call code in kernel/hw4.c. Create a test directory and write a user level test program to call the supermom() system call. Name your test driver hw4-test.c. After you’re done with this part, git ls-files should look like this:

$ git ls-files 
README.txt
mmk
mko
arch/x86/entry/syscalls/syscall_32.tbl
kernel/Makefile
kernel/hw4.c
test/hw4-test.c

The system call works as follows:

Part 5: Moving a system call into a kernel module

By now, you must be tired of rebooting your VM every time you make a small change in system call code. In this part, we will move the code for supermom() into a dynamically loadable kernel module. Our goal is to be able to make modifications to the system call code without having to reboot the machine.

Good luck!


Last updated: 2017–02–20