This repository contains the source code and documentation for our CS3500 Operating Systems project.
The core focus is on creating system call wrappers and kernel-level customizations for advanced resource management, security, and debugging in Linux systems.
Our work is divided into three main areas:
- File I/O Wrappers
- Memory Management Wrappers
- Process Management and Kernel Extensions
- Logger: Intercepts file operations, logs actions and results for debugging and monitoring.
- Safe Read: Validates file read operations, prevents out-of-bound reads, robust error handling.
- Safe Open: Checks file existence, validates flags, and prevents typical open errors.
- Access Control: Enforces user permission checks before file access.
- Rate Limiting: Limits frequency of file operations to prevent abuse or DoS attacks.
- Buffering: Retains data in-memory before writing for performance boosts.
- Master Wrapper: Uses
LD_PRELOADto transparently intercept all major file syscalls.
- mmap Allocation Tracking: Linked-list tracking for all memory allocation events and error logging.
- Safe munmap: Checks validity before unmapping, detailed error reporting.
- Leak Detection: Automatic logging and detection of dynamic memory leaks.
- Thread-safe brk: Ensures robust heap management across threads, falls back to mmap when necessary.
- File Descriptor Management: Tracks open descriptors, prevents leaks/zombies.
- Memory Pool: Preallocates a pool for efficient frequent small allocations.
- Aligned Allocation: Ensures hardware- or SIMD-compatible memory address alignment.
- Process Pool Manager: Efficiently manages tasks across child processes, reusing them to maximize CPU utilization.
- Deadlock Detection: Dynamically builds a process-resource graph, detects cycles, resolves by killing the latest process.
- Process Cloaking: Hides chosen child processes from listing utilities (
ps,top). - Wait-for-All-Children: Blocks parent until all child processes exit, preventing zombies.
- IPC Logging: Logs and audits all major IPC operations (pipes, queues, shared memory, semaphores).
- Priority Enforcement: Sets CPU and IO priorities post-fork, ensuring predictable resource usage.
- Process Monitoring: Tracks run stats (time, memory, context switches), logs abnormal events.
- Custom waitpid: Adds timeouts and non-blocking monitoring for child processes.
- Zombie Logger: Logs all zombie events upon kill/waitpid.
- Custom Kernel Syscalls: Examples include
hellosyscall, resource management calls like disabling fork, closing all files, etc.
- Download and extract Linux kernel (e.g., 6.0.7).
- Add/modify syscall or kernel module source code in
kernel_compilation/. - Update
syscalls.h, syscall tables, andMakefileas needed. - Recompile and install kernel:
make menuconfig # Configure kernel, or copy old .config make -jn # Build (n = CPU cores for speed) make modules_install make install - Reboot and select the new kernel in GRUB.
- File wrappers:
LD_PRELOAD=./filewrp.so cat myfile.txt
text
-
Memory leak checker:
Run with memory wrapper preload, check terminal/logs for leaks after execution. -
Kernel syscalls:
Write and compile a minimal C program using your custom syscall number, e.g.,
syscall(549); // fork_if_not_disable
text
- Access Control Policy: Edit
check_permissionincontrol_permission.c - Rate Limiting: Set constants in
rate_limiting.h - Buffer Size: Update
BUFFER_SIZEinbuffer.h - Log File Location: Set
LOG_FILEinlogger.h - Kernel Compilation: Carefully follow instructions for your kernel version!
- Some kernel versions have different syscall interfaces; update code and Makefile accordingly.
- Compilation times for the full kernel are long (often >2 hours).
- Bugs like frame buffer errors or system call registration issues may occur; refer to the referenced resources for fixes.
- PhoenixNAP: Build Linux Kernel
- Medium: Adding Hello World System Call
- Medium: Custom Syscall on Linux 6.x
- Kernel.org: Linux 6.x Release
- Many wrappers use
LD_PRELOADwithdlsym()for user-space syscall interception. - Kernel wrappers use updated APIs (
filp_open,vfs_read, etc.)—be careful with direct syscall invocation in kernel space due to security constraints. - Process wrappers include robust resource tracking and logging to aid debugging/monitoring.
- All work was tested on Ubuntu 22.04.5; see notes for compatibility issues.