Introduction
Info
Please read the general instructions first.
Part A of the assignment is due 17:59 on 10 Mar 2025 Part B of the assignment is due 17:59 on 3 Mar 2025 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.13. 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])
- Rely on the toolchain's implicit default DWARF version (
- Provide GDB scripts for kernel debugging (
GDB_SCRIPTS [=y])
- Debug information
- Compile-time checks and compiler options
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: Developing a Kernel Module
Question 4 (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 5 (2 marks):
Why is printk used instead of printf within kernel modules?
Question 6 (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 7 (2 marks): Modify the Makefile, if necessary, to make the message compiled into the module.
Question 8 (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 9 (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.
insmodloads the module with the appropriate arguments. The command that uses this target should be:rmmodunloads the module. The command that uses this target should be:
Task 3: Creating a New System Call
Question 10 (8 marks):
Please provide the patch file for the changes you made to the kernel source code to create the new system call.
The patch file should have suffix .patch and adhere to the following requirements:
- The patch file must be able to be applied to the v6.13 version of the kernel source code without any errors. If the patch file cannot be applied, you will receive zero marks for this question.
- The patched kernel must be able to compile without any errors. If the patched kernel cannot compile, you will receive zero marks for this question.
Question 11 (4 marks): Please provide the source code for your user-mode program in a C file. This program should take the PID of a process as input, invoke the new system call you created, and output the PIDs of all its children, one per line. Please ensure that the program compiles without error.
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:
- Questions 1, 2 and 4 shall be answered in the
manifest.jsonfile directly.
Part B (15 marks)
Please complete the quiz Assignment 2 (Part B) on Canvas.