This project involves modifying the Linux 2.6.38.1 kernel to implement two new system calls: set_task_params and get_task_params. The goal is to gain hands-on experience with:
- Kernel source code exploration and modification
- Adding custom system calls to Linux
- Compiling and booting a modified kernel using QEMU
- User-space interaction with custom kernel functionality
These system calls allow setting and retrieving custom task-specific parameters (group_name and member_id) for processes, demonstrating low-level OS development, memory-safe user-kernel communication, and kernel data structure manipulation.
-
New System Calls
set_param_sys: Sets task-specific parameters (group name, member ID) for the current process.get_param_sys: Retrieves these parameters for a given task.dummy_sys: A placeholder system call for testing kernel modifications.
-
Kernel Modifications
include/linux/sched.h: Addedgroup_nameandmember_idfields totask_struct.arch/x86/include/asm/unistd_32.h: Defined system call numbers for new calls.arch/x86/kernel/syscall_table_32.S: Linked new system calls to kernel syscall table.include/asm-generic/syscalls.h: Declared prototypes for new system calls.kernel/Makefile: Included new.ofiles for compilation.- New files:
dummy_sys.c,get_param_sys.c,set_param_sys.c. kernel/d_params.h: Definedstruct d_params { char group_name; int member_id; }.
-
User-Space Integration
- Modified
/usr/include/unistd.hin QEMU to includestruct d_paramsfor testing. - Demonstrates safe access to kernel memory using
get_current()andcopy_to_user().
- Modified
-
Testing Environment
- Compiled the modified kernel on the host OS.
- Loaded and ran the kernel in QEMU, verifying that the new system calls work correctly.
- Example user programs can call
set_param_sysandget_param_systo manipulate and retrieve task parameters.
- Set Params: Accesses the current task (
get_current()) and setsgroup_nameandmember_idaccording to the function parameters. - Get Params: Copies the values from the task struct to a user-space
struct d_paramsusingcopy_to_user(). - Compilation & Configuration: Used the provided
.configfile, modifyingCONFIG_LOCALVERSIONto include the username, ensuring the custom kernel can be distinguished in QEMU. - QEMU Testing: Verified functionality by running multiple user-space test programs that set and get task parameters.
- Copy and extract the kernel source:
cp ~hy345/qemu-linux/linux-2.6.38.1-patched.tar.bz2 /spare/[username]/ tar xvjf linux-2.6.38.1-patched.tar.bz2 cd linux-2.6.38.1 cp /path/to/provided/config .config # Use the provided .config file and modify CONFIG_LOCALVERSION: # Edit CONFIG_LOCALVERSION += "_username" # Compile the Kernel make # Boot QEMU with the new kernel image and test using user-level programs that call set_param_sys and get_param_sys.