StackVault: Protection from Untrusted Functions

Qi Zhang, Zehra Sura, Ashish Kundu, Gong Su, Arun Iyengar, Ling Liu

TL;DR

StackVault is a kernel-based security system designed to stop "inside-out" attacks where untrusted third-party libraries or buggy functions steal sensitive data from a program's stack. By leveraging a custom compiler extension and a trusted kernel module, it temporarily hides sensitive stack data whenever an untrusted function is executed, incurring a negligible runtime overhead of less than 2.4%.

What Problem Does This Paper Address?

In modern software development, we frequently rely on third-party libraries and open-source code. However, standard operating systems operate on a "trusting" memory model: any function executing within a process can access any part of that process's memory. This creates a massive security hole. If a developer includes an untrusted library (like a JSON parser or a networking utility) that turns out to be malicious or contains a security bug (like the infamous Heartbleed or the Apache Struts vulnerability that led to the Equifax breach), that library can "reach back" into the stack of the calling function to steal passwords, encryption keys, or private user data.

While technologies like Intel SGX protect a process from external threats (the OS or other processes), they don't solve the "inside-out" threat where the attacker is already inside the process. StackVault addresses this by enforcing "need-to-know" data isolation between functions in the same process.

Methods

StackVault consists of three integrated components that automate the protection of stack-based data:

  1. Programming APIs: Developers use simple annotations (e.g., __attribute__((annotate("StackVault_Sensitive")))) to mark sensitive functions or specific variables. They also maintain a list of "untrusted" functions (typically third-party library calls).
  2. LLVM Compiler Extension: A modified LLVM compiler (version 6.0.0) automatically scans these annotations and injects specialized system calls into the executable. Crucially, it inserts a start_protect() call just before an untrusted function is invoked and a stop_protect() call immediately after it returns.
  3. Kernel Module: This is the "root of trust." When start_protect() is called, the kernel identifies the calling function using unforgeable function identities (based on the instruction address ranges in the ELF binary). The kernel then copies the sensitive stack data into a secure kernel buffer and zeros out the original memory on the stack. Once the untrusted function finishes, stop_protect() restores the data.

By using the Program Counter (PC) to verify identities, the kernel ensures that an untrusted function cannot maliciously call stop_protect() to "unhide" data it shouldn't see.

Datasets

The authors evaluated StackVault using six real-world applications that integrate popular third-party libraries:

  • gRPC: A high-performance RPC framework.
  • xmlstream: Uses the libcurl and expat libraries.
  • fileupload: Uses libcurl.
  • htmltidy: Uses libcurl and libtidy.
  • minizip / miniunz: Use the zlib compression library.

These benchmarks represent common scenarios where sensitive application logic interacts with untrusted external code.

Key Insights and Ideas

  • The Stack is Special: Unlike the heap, which is fragmented and complex, the stack is allocated in a systematic, managed, and transient way. This allowed the authors to build a much more efficient protection mechanism than general-purpose memory isolation.
  • Unforgeable Identities: The system doesn't just trust the process to say "I am function X." The kernel parses the binary's text section to define valid address spans for every function. It then checks the actual Program Counter to verify that a system call is coming from a legitimate, authorized location.
  • Fine-Grained vs. Coarse-Grained: StackVault allows developers to protect an entire stack frame by default, or selectively protect/expose specific variables (e.g., letting an untrusted logging function see an "age" variable but not a "password" variable).

Key Results

  • Low Performance Overhead: The runtime overhead is remarkably low, ranging from 0.06% to 2.4% across the tested applications.
  • Bottleneck Identification: The authors found that 95% to 99% of the overhead comes from the context switch between user space and kernel space, rather than the actual data copying or clearing.
  • Minimal Binary Bloat: The increase in executable file size was less than 0.5%, as the system only adds a few system call instructions.
  • Efficiency: For gRPC, the overhead was nearly zero (0.03%), demonstrating that the system scales well even for high-performance applications.

Limitations and Future Work

  • Multithreading: The current implementation assumes a single-threaded context for stack access. In a multithreaded environment, one thread could potentially snoop on another thread's stack. The authors suggest using locks and priority queues as a future solution.
  • Function Pointers: If an untrusted function is called via a pointer that cannot be resolved at compile time, the current compiler extension may struggle to insert the correct protection calls.
  • Heap Data: While StackVault protects data pointed to by the stack, it does not provide a general-purpose solution for all heap-based data isolation, which remains a more complex problem due to the non-linear nature of heap allocations.

Summary updated

BibTeX
@inproceedings{zhang2020stackvault,
  author = {Qi Zhang and Zehra Sura and Ashish Kundu and Gong Su and Arun Iyengar and Ling Liu},
  title = {{StackVault: Protection from Untrusted Functions}},
  booktitle = {TPS-ISA},
  year = {2020},
  doi = {10.1109/tps-isa50397.2020.00045},
}
Figure