TL;DR
KernelGPT is the first automated approach to use Large Language Models (LLMs) for generating the complex system call (syscall) specifications required for effective kernel fuzzing. By iteratively analyzing source code and repairing errors based on validation feedback, it discovered 24 new bugs in the Linux kernel, 11 of which have already been assigned CVEs.
What Problem Does This Paper Address?
Operating system kernels are the foundation of modern computing, but their complexity makes them prone to critical bugs. Fuzzing—automatically generating random inputs to crash a system—is the gold standard for finding these bugs. However, kernel fuzzing is uniquely difficult because the kernel expects highly structured inputs called syscalls.
To fuzz effectively, tools like Syzkaller need "specifications" (written in a domain-specific language called syzlang) that define the syntax and semantics of every syscall. Currently, writing these specs is a manual, Herculean task requiring deep expertise. Existing automated tools rely on rigid, hard-coded static analysis rules that often fail when developers use "atypical" code patterns or when the kernel codebase evolves.
Methods
The authors introduce KernelGPT, a pipeline that leverages the broad programming knowledge of LLMs (specifically GPT-4) to automate this process. The workflow consists of two main phases:
- Iterative Specification Generation: Instead of feeding the entire kernel to an LLM, KernelGPT uses a "Kernel Code Extractor" to find relevant snippets. It then employs an iterative analysis strategy across three stages:
- Identifier Deduction: Finding the specific values (like
ioctlcommand macros) needed to trigger a driver. - Type Recovery: Inferring the data structures and their internal relationships.
-
Dependency Analysis: Determining how one syscall's output (like a file descriptor) serves as another's input.
If the LLM encounters a function call it doesn't recognize, it marks it as "unknown." The system then extracts that new code and re-queries the LLM, effectively "following" the logic through the codebase.
-
Validation and Repair: The generated specifications are passed to Syzkaller’s internal validation tools. If errors are found (e.g., an undefined type), the error message and the faulty spec are sent back to the LLM for automated repair.
Datasets
The researchers evaluated KernelGPT on the Linux kernel version 6.7. They specifically targeted:
- 30 Device Drivers: A benchmark previously used by the state-of-the-art static analysis tool, SyzDescribe.
- 10 Socket Handlers: Randomly selected to test network protocol fuzzing.
- Missing Specs: They scanned the kernel for drivers and sockets that were active but lacked any existing Syzkaller descriptions.
Key Insights and Ideas
- Semantic Understanding vs. Pattern Matching: Traditional tools struggle with semantic relationships, such as a field that represents the length of an adjacent array. LLMs can "read" the code and documentation to infer these connections naturally.
- The Power of Iteration: By allowing the LLM to identify what it doesn't know, KernelGPT overcomes the "context window" limit of models. It only fetches the code the model actually needs to see to make a decision.
- Readability Matters: Machine-generated code is often a mess of random numbers. Because LLMs were trained on human-written code and documentation, they generate specifications that are human-readable. This is crucial for getting these specs merged into official open-source projects.
Key Results
KernelGPT significantly outperformed both manual efforts and previous automated tools:
- Bug Discovery: It found 24 new unique bugs in the Linux kernel. 21 have been confirmed by developers, 12 are fixed, and 11 received CVE numbers.
- Coverage: In a 24-hour fuzzing session, KernelGPT-enhanced Syzkaller covered 20,742 more basic blocks than the standard version.
- Efficiency: It generated 532 new syscall descriptions in just 4.7 hours at a total API cost of roughly $34.
- Real-world Impact: Several specifications generated by KernelGPT have already been merged into the official Syzkaller repository at the request of its maintainers.
Limitations and Future Work
While highly effective, KernelGPT has a few hurdles:
- Indirect Function Calls: The authors noted that LLMs still struggle when syscall handling is delegated through multiple layers of indirect function pointers.
- Hallucinations: Like all LLMs, the model can occasionally "hallucinate" non-existent macros or types, though the validation/repair phase catches most of these.
- Scope: The current work focuses on drivers and sockets. Future work could expand this to other complex kernel subsystems like file systems or memory management.
Overall, KernelGPT represents a major shift in systems security, moving from manually-crafted rules to a flexible, AI-driven approach that understands the "intent" behind the code.
Summary updated