Skip to content

Introduction

Info

Please read the general instructions first.

Part A of the assignment is due 23:59 on 10 Mar 2026 Part B of the assignment is due 23:59 on 10 Mar 2026 Late submissions will lose 1 mark per hour.

Part A (35 marks)

Info

Please accept the assignment on GitHub Classroom before proceeding, as some code snippets are provided in the repository. The invitation link is available on Canvas.

Info

Throughout this assignment, you will be working with the Linux kernel version 6.18. Please start with the default configuration and make the following two features enabled:

  • Kernel hacking
    • Compile-time checks and compiler options
      • Debug information
        • Rely on the toolchain's implicit default DWARF version (DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT [=y])
      • Provide GDB scripts for kernel debugging (GDB_SCRIPTS [=y])

If you need VirtualBox shared folders, ensure that CONFIG_VBOXGUEST and CONFIG_VBOXSF_FS are enabled in your kernel configuration.

It may require more memory to build the kernel with these features enabled. If you encounter OOM errors during the build process, please increase the memory of your VM to at least 3 GB.

Optional: Get Around in the Source Code Tree

Task 1: Debugging with GDB

Question 1 (2 marks): Which figure in the ABI documentation describes the stack layout for the initial state of a process?

Question 2 (2 marks): Which interrupt line (IRQ) is allocated for this specific interrupt?

Question 3 (4 marks): How does the /init program get executed? Is this procedure similar to how execve works? Does a context switch occur, similar to what happens during a syscall? Please explain your observation briefly.

Task 2: AI-Assisted Interrupt Code Navigation

Question 4 (4 marks): understand exceptions and interrupt.

Question 5 (8 marks): Use AI tools to browse the Linux source tree and recover the interrupt-related function flow for X86_TRAP_NMI, from trap_init() to __handle_irq_event_percpu(). Your answer must include prompt logs, a verified function path, function-level notes, and explicit claim checks with file/line evidence. Please follow the detailed requirements in Task 2.

Task 3: Developing a Kernel Module

Question 6 (2 marks): Identify the file and line number where the module_init macro is defined for our scenario.

Please give your answer in the format file#L1234. For example, if it were defined in kernel/sched/core.c at line 6636, you should refer to it as kernel/sched/core.c#L6636.

Question 7 (2 marks): Why is printk used instead of printf within kernel modules?

Question 8 (2 marks): Did you observe the output "Greetings from xxx" when you loaded the module? If not, is this string compiled into the module? Please explain your observation briefly.

Question 9 (2 marks): Modify the Makefile, if necessary, to make the message compiled into the module.

Question 10 (4 marks): Submit the source code for your kernel module. The module shall accept two parameters and output the process ID and executable name for the given PID. Ensure that the module compiles without errors using the Makefile and that it can be loaded and unloaded without any error.

Question 11 (3 marks): Submit the Makefile that builds and loads the kernel module. The Makefile should include two additional targets beyond those in the previously provided Makefile.

  1. insmod loads the module with the appropriate arguments. The command that uses this target should be:
    $ sudo make insmod tag=xxx pid=yyy
    
  2. rmmod unloads the module. The command that uses this target should be:
    $ sudo make rmmod
    

Submission Guidelines

Please accept the assignment on GitHub Classroom first. The invitation link is available on Canvas. Then, proceed to complete the tasks and push your work to GitHub accordingly.

Refer to the submission guidelines in Assignment 1 for the remaining instructions.

For this assignment:

  1. Questions 1, 2 and 6 shall be answered in the manifest.json file directly.