TL;DR
This paper introduces LtRules, an automated tool that extracts software library usage rules from existing "good" programs. By leveraging model checking, LtRules transforms implicit API constraints into formal specifications, making software model checking more accessible and helping developers write better code.
What Problem Does This Paper Address?
Developing complex software often involves using pre-built libraries. These libraries come with Application Programming Interfaces (APIs) – sets of functions that developers use to access library features. However, these APIs often have implicit rules about how their functions should be called in sequence to ensure correct behavior. These rules are typically buried in lengthy documentation, making them hard for developers to find and follow, leading to errors.
Manually specifying these temporal properties for software model checking is a significant hurdle, as it's time-consuming and error-prone. This paper addresses the challenge of automatically discovering and formalizing these crucial API usage rules, thereby lowering the barrier to entry for software model checking and improving software quality.
Methods
The core of LtRules is an automated approach to extract software library usage rules. It works by:
- Rule Candidate Generation: LtRules defines six categories of API usage rules (initialization, finalization, push-pop, strict-alternation, function-pair, and adjoining-function). For a given library and a set of related API functions, it generates a large number of "rule candidates" by instantiating templates for these rule categories.
- Model Checking Verification: These rule candidates are then verified against a collection of "known good programs" that use the target library. A "known good program" is one that is already tested, deployed, and generally considered defect-free.
- Rule Extraction: A model checker (specifically BLAST in their implementation) is used to check if each rule candidate holds true for all the known good programs. If a candidate is satisfied by all these programs, it is considered a valid API usage rule.
To optimize this process, LtRules employs two key strategies:
- For initialization and finalization rules, it checks candidates against the first program and then progressively filters them for subsequent programs.
- For the other four rule categories, it leverages the inherent hierarchical relationship between them (e.g., adjoining-function implies function-pair, which implies strict-alternation, which implies push-pop). It first extracts the least strict rules (push-pop) and then uses these valid rules to prune candidates for stricter rule types, significantly reducing the number of model checker invocations.
Datasets
The paper describes an experiment using the OpenSSL library. The "known good programs" used for evaluation were four OpenSSL applications: CashCow, Slush, Pay-Pal Sender, and Netcat SSL. These applications were chosen because they had been released for over three years, were widely used, and were considered stable.
Key Insights and Ideas
- Implicit Rules are Discoverable: The paper demonstrates that even though API usage rules are often implicit and informal, they can be systematically extracted from well-behaved programs.
- Model Checking as an Oracle: Using a model checker to verify rule candidates against known good programs acts as a powerful oracle, ensuring that extracted rules are consistent with established usage patterns.
- Hierarchical Rule Extraction: The insight that certain rule types imply others is crucial for efficiency. This allows for a staged extraction process, starting with simpler rules and building up to more complex ones, dramatically reducing computational overhead.
- Bridging the Gap to Model Checking: By automating rule specification, LtRules directly addresses a major bottleneck in adopting model checking, making it more accessible to a wider range of developers.
Key Results
In their experiment with the OpenSSL library and four known good programs, LtRules was able to extract four valid API usage rules from 132 candidates in just under three minutes. The tool identified two push-pop rules and one strict-alternation rule. These rules were found to accurately reflect the common and inherent semantics of the OpenSSL functions. For instance, the push-pop rule between SSL_new() and SSL_free() correctly captures that SSL_free() should not be called more times than SSL_new().
Limitations and Future Work
- Dependence on "Known Good" Programs: The accuracy of the extracted rules heavily relies on the quality and representativeness of the "known good" programs. If these programs have subtle bugs or don't cover all common usage scenarios, the extracted rules might be incomplete or incorrect.
- Scope of Rule Categories: LtRules currently supports six specific categories of API usage rules. There might be other important types of temporal properties that are not covered by these categories.
- Future Work: The authors suggest that the extracted rules could be represented in a format compatible with other tools like SLAM, potentially alleviating SLAM's need for manually written rules. They also imply that the approach could be extended to other programming languages and libraries.
Summary updated