Verifying Concurrent Message-Passing C Programs with Recursive Calls

Sagar Chaki, Edmund M. Clarke, Nicholas Kidd, Thomas W. Reps, Tayssir Touili

Introduction

Formal verification of software often requires a difficult choice between modeling precision and computational feasibility. To accurately model real-world C programs, a verification tool must account for three complex features: recursion (requiring pushdown systems to manage the call stack), concurrency (leading to state-space explosion from thread interleavings), and large data domains (such as 32-bit integers).

Individually, these features are manageable. However, combining them makes the "reachability problem"—determining if a program can ever enter an erroneous state—mathematically undecidable. Most existing tools compromise by bounding recursion depth, limiting context switches, or abstracting data into very small domains. This paper introduces a framework that addresses these challenges simultaneously by modeling programs as Communicating Pushdown Systems (CPDSs) and employing a novel "double-layered" CounterExample Guided Abstraction Refinement (CEGAR) strategy.

Modeling with Communicating Pushdown Systems

The authors represent concurrent C programs using CPDSs, which are collections of pushdown automata that synchronize via message-passing or shared actions. Unlike traditional finite-state machines, pushdown systems can represent an unbounded number of recursive calls symbolically using regular languages. This allows the model to handle recursion natively without the need for "inlining" (replacing function calls with their bodies), a technique that often causes a massive blow-up in the model size and fails for truly recursive functions.

The Double-Layered CEGAR Framework

The core innovation of this research is a two-level CEGAR scheme designed to handle both data abstraction and the inherent undecidability of concurrent reachability.

Level 1: Predicate Abstraction (Data)

The tool, implemented within the MAGIC framework, begins with a coarse model of the C code. It uses predicate abstraction to map complex data variables into simple boolean values. If the model checker identifies a potential bug that is found to be impossible in the actual source code (a spurious counterexample), the system automatically discovers new predicates using weakest preconditions to refine the model's precision.

Level 2: Reachability Analysis (Concurrency and Recursion)

Checking reachability in a CPDS is equivalent to checking if the intersection of multiple Context-Free Languages (CFLs) is empty—a problem that is generally undecidable. To circumvent this, the authors implement a second CEGAR loop. They approximate the CFLs using simpler, finite languages (such as the $i$-th prefix of the language). If an intersection is found in the approximation, the tool checks if it exists in the actual CPDS. If the intersection is spurious, the precision of the approximation is increased, and the process repeats. This "componentwise" approach allows the tool to analyze each thread's logic independently before checking interactions, significantly improving scalability.

Experimental Results and Impact

The effectiveness of the CPDS approach was evaluated using several non-trivial benchmarks, including a concurrent Binary Search Tree (BST) and various versions of the Windows NT Bluetooth driver.

Bug Discovery

The framework successfully identified a previously unknown bug in version BT2 of the Windows NT Bluetooth driver. While version BT1 was known to be buggy and BT2 was intended as a fix, the tool demonstrated that a race condition still existed when two processes ran concurrently. This highlights the tool's ability to find subtle concurrency errors that elude manual inspection and less rigorous testing methods.

Performance and Scalability

The CPDS-based tool showed significant performance improvements over traditional inlining methods. In one instance, the tool analyzed an 18,000 line-of-code (KLOC) program in under 2.2 seconds. In the ucos-3 benchmark, the previous version of the MAGIC model checker (using inlining) exceeded 2GB of memory and failed to complete, whereas the new CPDS-based tool finished the analysis in approximately 29 seconds.

Limitations and Future Work

As the underlying reachability problem is undecidable, the tool functions as a semi-decision procedure. While it performed well on all tested benchmarks, the second CEGAR loop could theoretically run indefinitely if the intersection of the languages is empty. Additionally, while the implementation supports multiple components, the theoretical reduction to CFL intersection presented focuses on two-component systems. Future work aims to extend this approach to shared-memory concurrency with complex locking patterns, moving beyond the current message-passing and synchronization model.

Summary updated

BibTeX
@inproceedings{chaki2006verifying,
  author = {Sagar Chaki and Edmund M. Clarke and Nicholas Kidd and Thomas W. Reps and Tayssir Touili},
  title = {{Verifying Concurrent Message-Passing C Programs with Recursive Calls}},
  booktitle = {TACAS},
  year = {2006},
  doi = {10.1007/11691372\_22},
}
Figure