Lightweight, Multi-Stage, Compiler-Assisted Application Specialization

Mohannad Alhanahnah, Rithik Jain, Vaibhav Rastogi, Somesh Jha, Thomas W. Reps · DOI

Abstract

Program debloating aims to enhance the performance and reduce the attack surface of bloated applications. Several techniques have been recently proposed to specialize programs. These approaches are either based on unsound strategies or demanding techniques, leading to unsafe results or a high overhead debloating process. In this paper, we address these limitations by applying partial-evaluation principles to generate specialized applications. Our approach relies on a simple observation that an application typically consists of configuration logic, followed by the main logic of the program. The configuration logic specifies what functionality in the main logic should be executed. LMCAS performs partial interpretation to capture a precise program state of the configuration logic based on the supplied inputs. LMCAS then applies partial-evaluation optimizations to generate a specialized program by propagating the constants in the captured partial state, eliminating unwanted code, and preserving the desired functionalities. Our evaluation of LMCAS on commonly used benchmarks and real-world applications shows that it successfully removes unwanted features while preserving the functionality and robustness of the deblated programs, runs faster than prior tools, and reduces the attack surface of specialized programs. LMCAS runs 1500x, 4.6x, and 1.2x faster than the state-of-the-art debloating tools CHISEL, RAZOR, and OCCAM, respectively; achieves 25% reduction in the binary size; reduces the attack surface of code-reuse attacks by removing 51.7% of the total gadgets and eliminating 83% of known CVE vulnerabilities.

Introduction

Modern software applications are increasingly "bloated," shipping with numerous features that the average user rarely utilizes. For example, a user might employ the wc utility solely to count lines, leaving the code for character or byte counting entirely unused. This bloat is not merely an efficiency concern; it significantly expands the attack surface. Unused code can harbor vulnerabilities (CVEs) or provide "gadgets" for code-reuse attacks like ROP or JOP, violating the principle of least privilege.

Existing software debloating tools face a difficult trade-off between safety and efficiency. Static analysis tools tend to be overly conservative, failing to remove significant bloat. Conversely, aggressive dynamic tools like CHISEL or RAZOR require extensive test suites and often produce "broken" binaries that crash or loop infinitely. Furthermore, existing partial evaluation tools like OCCAM often fail when encountering complex data structures like pointers and structs. LMCAS addresses these limitations by leveraging the structural properties of configuration-driven programs to provide safe, fast, and effective specialization.

Methodology: The "Neck" and Partial Evaluation

The core innovation of LMCAS is identifying the "neck" of a program—the structural boundary where an application finishes processing its configuration and begins its main execution logic. By partitioning the program at this point, LMCAS can focus its analysis on the initialization phase to specialize the subsequent main logic.

The 'neck' concept: partitioning a program into configuration logic and main logic.

LMCAS operates through a multi-stage pipeline designed for both speed and precision:

  1. Neck Miner: An automated LLVM pass identifies the "neck" using heuristics (such as command-line parsing loops) and structural graph analysis.
  2. Partial Interpretation: LMCAS uses symbolic execution (via KLEE) only up to the neck to capture the concrete state of the program based on specific user-provided configurations.
  3. Constant Conversion: The captured state, including complex types like pointers and structs, is injected back into the LLVM Intermediate Representation (IR) as hardcoded constants.
  4. Multi-Stage Simplification: Standard and custom compiler passes perform aggressive dead-code elimination, constant folding, and branch pruning based on the newly injected constants.
The LMCAS workflow, from source code to specialized program.

Experimental Evaluation

LMCAS was evaluated against 15 GNU Coreutils, 6 programs with known CVEs (ChiselBench), and 3 large-scale applications (tcpdump, readelf, objdump). The results demonstrate that LMCAS is exceptionally efficient, running 1500x faster than CHISEL and 1.2x faster than OCCAM, with an average analysis time of just 3.6 seconds.

In terms of debloating effectiveness, LMCAS achieved an average 25% reduction in binary size and a 40% reduction in function count. Security improvements were equally substantial: the framework removed 51.7% of total code-reuse gadgets and successfully eliminated 83% (5 out of 6) of targeted CVE vulnerabilities. Crucially, LMCAS maintained 100% functional correctness across all tests, outperforming tools like CHISEL and OCCAM which frequently produced crashing or infinitely looping binaries.

Conclusion

LMCAS provides a safe, fast, and effective method for application specialization by focusing partial evaluation on the program's configuration logic. While currently optimized for command-line and configuration-driven server applications, future work will explore adapting this partitioning approach to event-driven architectures and enforcing stricter security policies, such as disabling unused system calls, on the remaining specialized code.

Summary updated

BibTeX
@inproceedings{alhanahnah2021lightweight,
  author = {Mohannad Alhanahnah and Rithik Jain and Vaibhav Rastogi and Somesh Jha and Thomas W. Reps},
  title = {{Lightweight, Multi-Stage, Compiler-Assisted Application Specialization}},
  booktitle = {EuroS\&P},
  year = {2021},
  doi = {10.1109/eurosp53844.2022.00024},
}
Figure