Abstract
Code clones—segments of code that are identical or highly similar—are a primary vector for "copy-pasted" vulnerabilities. While machine learning (ML) approaches for clone detection are scalable, they often suffer from high false-positive rates. Conversely, formal verification is precise but computationally expensive. This paper introduces Twin-Finder+, an integrated reasoning engine that bridges this gap using a novel "closed-loop" approach. By combining domain-specific slicing, ML-based clustering, and symbolic execution, Twin-Finder+ achieves a 91.69% reduction in noise and has successfully uncovered six previously unreported security bugs in real-world applications.
Introduction
The prevalence of pointer-related vulnerabilities in C/C++ codebases necessitates robust detection mechanisms. Traditional clone detectors often fail to isolate pointer-specific logic, leading to significant "noise" from irrelevant statements. Furthermore, many tools flag syntactic similarities that do not reflect semantic equivalence, resulting in a high volume of false positives that overwhelm manual review processes. Twin-Finder+ addresses these hurdles by isolating pointer operations and employing a feedback loop to refine its detection model.
Methodology
Twin-Finder+ operates through a four-stage pipeline designed to maximize both recall and precision.
Domain-Specific Slicing
The process begins with "lightweight tainting" and program slicing. Instead of analyzing entire files, the tool identifies pointers and retains only the statements that directly affect them, such as array indices or buffer bounds. This isolation simplifies subsequent analysis and allows the engine to focus on security-critical logic.
ML-Based Clustering
The system converts sliced code fragments into Abstract Syntax Trees (ASTs). These trees represent the structural logic of the code, providing a basis for feature extraction.
These ASTs are transformed into numerical feature vectors. Using the DECKARD tree-based clone detector and Locality Sensitive Hashing (LSH), the system groups similar vectors into "clone clusters."
Formal Verification and the Feedback Loop
To prune false positives, Twin-Finder+ employs KLEE, a symbolic execution tool, on samples from the identified clusters. KLEE explores execution paths to collect memory safety constraints. If two fragments exhibit different constraints, they are deemed semantically distinct.
Crucially, the system implements a feedback loop. When a false positive is identified, the engine calculates the structural differences between the ASTs and adjusts the weights of the differing nodes in the ML model. This iterative refinement "pushes" false positives out of clusters in subsequent passes, effectively teaching the model to distinguish between similar-looking but behaviorally different code.
Key Results
The evaluation of Twin-Finder+ across benchmarks like SPEC2006 and real-world projects like LibreOffice yielded significant results:
- Noise Reduction: The tool achieved an average reduction of 91.69% in false positives.
- Enhanced Detection: By stripping away irrelevant code, Twin-Finder+ found up to 9x more clones than standard methods.
- Vulnerability Discovery: The system identified six previously unreported bugs in the
Linksbrowser, including memory leaks and null dereference vulnerabilities. It also detected a heap-based buffer overflow inLibreOffice(CVE-2018-10120) that had been missed by other detectors.
Conclusion
Twin-Finder+ demonstrates the power of combining the speed of machine learning with the precision of formal reasoning. Its closed-loop architecture not only scales to large codebases but also continuously improves its accuracy through automated feedback. Future work will focus on expanding language support and handling more complex indirect memory access patterns.
Summary updated