TL;DR
Vulnerabilities at the boundary between Trusted Execution Environments (TEEs) and untrusted operating systems can lead to severe data leaks and code injection. This paper introduces TEERepair, a novel automated program repair framework that combines a domain-specific language (DSL) for secure architecture rules with Large Language Models (LLMs) to synthesize context-aware patches. TEERepair achieves an impressive 87.6% repair success rate on TEE vulnerabilities, significantly outperforming traditional automated repair baselines.
What Problem Does This Paper Address?
Trusted Execution Environments (TEEs), like ARM TrustZone and Intel SGX, use hardware isolation to secure sensitive data and computations from a potentially compromised host operating system. However, TEE applications must still communicate with the untrusted "normal side" via SDK interfaces.
If these interfaces are poorly designed—a problem known as a bad partitioning issue—the entire security model collapses. For example, if the TEE code trusts an input buffer size passed from the normal side without re-checking it, an attacker can easily trigger a buffer overflow.
Automating the repair of these vulnerabilities is exceptionally difficult due to three main challenges:
- Lack of Standards: There are no universal secure development guidelines for TEE partitioning.
- Missing Semantics: TEE code is usually written in low-level C, making it hard for automated tools to infer implicit semantic information like intended buffer sizes or variable relationships.
- Testing Hurdles: TEEs operate in isolated environments, meaning standard debugging tools, unit tests, and rapid compile-test loops are largely unavailable.
Methods
The authors present TEERepair, a framework that splits the repair process into structural guidance and semantic reasoning.
The pipeline consists of the following key steps:
- Vulnerability Detection: TEERepair uses an existing static analysis tool (DITING) to locate bad partitioning issues (e.g., unencrypted outputs, insufficient input validation, or unsafe shared memory usage).
- DSL-Guided Template Generation: The authors designed a custom Domain-Specific Language (DSL) to formalize secure TEE programming patterns. TEERepair maps the detected vulnerability to a DSL rule and generates a patch template containing structural fixes but leaving placeholders (prefixed with
$) for context-dependent variables. - LLM-Assisted Synthesis: A large language model (
gpt-4.1-mini) analyzes the surrounding C code context to intelligently fill in the placeholders (such as specific variable names, buffer lengths, or cryptographic parameters). - Two-Stage Validation: To overcome TEE testing constraints, TEERepair uses a two-stage loop. First, it runs the static analyzer again as a fast proxy oracle to ensure the vulnerability pattern is gone. Second, it automatically generates a standalone test client to deploy and validate the patch on actual hardware (a Raspberry Pi 3B with a hardware-backed TEE).
Datasets
The framework was evaluated using PartitioningE-Bench, a benchmark containing 89 validated vulnerable cases across various open-source TEE projects (such as luckfox-pico, PPFL, and darknetz). These cases cover three main vulnerability types: unencrypted data output, input validation weaknesses, and direct usage of shared memory.
The authors also evaluated TEERepair "in the wild" on real-world TEE projects hosted on GitHub.
Key Insights and Ideas
- The Power of Synergy (DSL + LLM): Purely template-based repair tools struggle to adapt to complex C semantics, while pure LLM approaches often hallucinate or fail to locate the exact vulnerability. By using a DSL to enforce the structure of the security fix and an LLM to resolve the contextual details, TEERepair gets the best of both worlds.
- Decoupling Hardware Constraints: Testing on actual TEE hardware is slow and expensive. Using static analysis as an immediate feedback loop (Stage 1) before pushing to physical hardware validation (Stage 2) drastically accelerates the repair cycle.
- Root-Cause Fixes Over Test Overfitting: Traditional automated program repair often suffers from "overfitting"—generating patches that pass specific tests but don't actually fix the underlying bug. Because TEERepair's templates are derived from verified security principles rather than test suites, it targets the true root cause.
Key Results
TEERepair demonstrated exceptional performance across the benchmark:
- 87.6% Success Rate: It correctly repaired 78 out of 89 vulnerabilities in PartitioningE-Bench.
- Baseline Comparison: It vastly outperformed existing automated program repair (APR) and automated vulnerability repair (AVR) tools. For instance, the template-based tool TBar achieved only a 19.1% success rate, while the LLM-based ChatRepair achieved 13.4%.
- Real-World Impact: When applied to live GitHub repositories, TEERepair successfully generated patches for multiple real-world bugs. The authors submitted 5 pull requests; at the time of writing, 2 have already been confirmed and merged by project maintainers (in the
basicAlg_useandPPFLrepositories).
Limitations and Future Work
While highly effective, the authors note a few limitations:
- Platform Specifics: The current evaluation focused primarily on ARM TrustZone. Although the DSL is platform-agnostic, future work is needed to validate its performance on other architectures like Intel SGX and AMD SEV.
- Manual Test Oracles: The test cases used for validation were manually constructed by developers. Integrating automated test-generation techniques, like coverage-guided fuzzing tailored for TEEs, represents a promising future direction.
- Scaling Up: The authors plan to extend the DSL to support more complex security policies and evaluate the framework on larger, industrial-scale codebases.
Summary updated