TL;DR
This paper introduces VulMatch, a novel approach for detecting vulnerabilities in binary code by extracting and matching fine-grained, context-aware vulnerability signatures. VulMatch significantly outperforms existing methods by focusing on precise instruction-level differences rather than coarse function similarity, offering better accuracy and explainability.
What Problem Does This Paper Address?
The paper tackles the critical challenge of detecting software vulnerabilities, particularly "1-day" and "N-day" vulnerabilities, which are critical because they are actively exploited before a patch is available or widely deployed. A major reason for the prevalence of these vulnerabilities is code reuse, where vulnerable code snippets are incorporated into new software. Detecting these vulnerabilities in binary code is crucial because source code is often unavailable. Existing methods struggle with this problem due to several limitations:
- Coarse-grained detection: Many methods rely on binary code similarity, which can lead to many false positives because patched binaries often remain highly similar to vulnerable ones. They also operate at a function level, missing fine-grained vulnerabilities within functions.
- Patch-centric detection: Some methods focus on detecting the presence of a patch rather than the existence of a vulnerability. This is problematic because the absence of a patch doesn't always guarantee a vulnerability, and vice-versa.
- Irrelevant instructions: Existing binary signature extraction methods often diff vulnerable and patched versions directly, inadvertently including many instructions that are not directly related to the vulnerability but have changed due to compiler optimizations or inlining. This leads to less precise signatures and reduced accuracy.
The core research question is how to effectively and efficiently find similar vulnerabilities or bugs from existing ones, specifically at the binary level, while overcoming these limitations.
Methods
VulMatch proposes a four-step methodology:
- Data Preparation: This involves collecting vulnerability information (CVEs), identifying affected source code files and functions, and gathering different versions of the software (last pre-patch and first post-patch). A key challenge here is automatic function inlining, which can obscure vulnerable functions. VulMatch addresses this by automatically inserting
__attribute__((noinline))tags into the source code of vulnerable functions to prevent inlining during compilation. - Locating Signature Instructions: This step uses source-code-level diffing to identify added, deleted, or changed instructions. Crucially, it then maps these source-level changes to their corresponding binary instructions using debugging information. This is a significant improvement over methods that solely rely on binary diffing.
- Constructing Context-aware Binary-level Signatures: This is the core innovation. Instead of just using raw instructions, VulMatch constructs signatures that include local control-flow information around the vulnerable instructions. This "context-aware" approach helps to disambiguate signatures and reduce false positives. Different signature types are defined:
- Add Type: Captures added instructions by analyzing the control flow from unchanged preceding blocks in the vulnerable version.
- Delete Type: Locates deleted instructions and stores them in block list structures.
-
Change Type: Handles both one-block and many-block changes, using parent-children structures and block lists, incorporating control-flow and lexical information. VulMatch also generates "patch signatures" to help distinguish between a patched function and a truly vulnerable one.
-
Signature Matching: The generated vulnerable and patch signatures are stored in a database. For a given query binary, VulMatch searches for matching vulnerable signatures. If a patch signature is also found, the function is considered patched. A similarity score is calculated based on the percentage of matched instructions, and an overall score is derived.
Datasets
The authors evaluated VulMatch on seven publicly available open-source projects: Tcpdump, Curl, OpenSSL, Openjpeg, LibPNG, Libtiff, and FFmpeg. For each project, they collected multiple versions, specifically the last pre-patch and first post-patch versions for vulnerable functions. This resulted in a dataset containing 906 CVEs and 1,281 vulnerable functions. The paper also mentions an experiment on commercial firmware to demonstrate practical applicability.
Key Insights and Ideas
- Fine-grained vulnerability detection is key: The paper strongly advocates for focusing on specific instructions and their local context rather than whole-function similarity. This is crucial because vulnerabilities often reside in small code segments.
- Source code guidance for binary analysis: Leveraging source code information (even if only for signature generation) significantly improves the accuracy of locating vulnerable binary instructions, reducing noise from compiler optimizations.
- Context matters: Incorporating local control-flow information into binary signatures makes them more robust and discriminative, leading to fewer false positives.
- Distinguishing patches from vulnerabilities: The explicit generation and matching of "patch signatures" is a clever way to avoid misclassifying patched code as vulnerable.
- Explainability: VulMatch provides a match score and highlights the matched instructions, offering a degree of interpretability that is often lacking in other tools.
Key Results
VulMatch significantly outperformed two state-of-the-art baseline tools, Asm2vec and Palmtree, in terms of Top-1 score (ranking the ground truth vulnerable function first) and mismatch score (indicating confidence in distinguishing vulnerable from non-vulnerable functions).
- Top-1 Score: VulMatch achieved higher Top-1 scores than Asm2vec and Palmtree on six out of seven projects.
- Mismatch Score: VulMatch achieved the lowest mismatch scores, indicating higher confidence in its vulnerability detection.
- Accuracy: VulMatch correctly detected 40 out of 52 (77%) vulnerable functions in real-world IoT firmware.
- Signature Efficiency: The paper found that "many-block-change" signatures were the dominant type, and "add" type signatures tended to be larger, reflecting the complexity of capturing these changes.
Limitations and Future Work
- Cross-Architecture Analysis: VulMatch currently only investigates vulnerable and patched code on the same architecture. Matching cross-architecture signatures remains an open research problem.
- Compilation Differences: While the paper uses default compilation flags, real-world binaries might be compiled with different optimization settings, compilers, or versions. Mitigating these differences is an ongoing challenge.
- Header File Changes: While the impact of header file changes (MACRO values, structure members) was analyzed, the authors note that MACRO changes are less frequent and omitted them from the core analysis due to their rarity.
- Future Work: The authors suggest extending VulMatch by incorporating fine-grained graph-based embeddings for signatures to mitigate assembly differences and improve efficiency. They also highlight the potential for further research into cross-architecture analysis and handling diverse compilation settings.
Summary updated