arXiv:2610.37797cs.CROct 2026

Manuscript Offprint

arXiv:2610.37797

Structured Security Explanations for Learning-Based Vulnerability Detection

Fares Trad, Yizhou Chen, Hung Viet Pham, Zeyu Sun, Gias Uddin

FARES TRAD, York University, Canada

YIZHOU CHEN, Peking University, China

HUNG VIET PHAM, York University, Canada

ZEYU SUN, Institute of Software, Chinese Academy of Sciences, China

GIAS UDDIN, York University, Canada

Software vulnerability detection remains difficult because existing approaches either rely on predefined analysis rules, learn vulnerability patterns implicitly from code and labels, or use large language models (LLMs) themselves to produce the final security judgment. These approaches can be limited by rigid analysis rules, implicit learning of security-relevant program behavior, or reliance on the LLM itself for the final decision. This leaves open whether structured security-relevant program behavior can be made explicit and learned jointly with source code for vulnerability detection.

We present VULNLENS, an explanation-augmented framework for binary C/C++ vulnerability detection that separates program-behavior analysis from the final vulnerability decision. A label-blind LLM-based EXPLAINER analyzes each function from seven fixed program-analysis perspectives, including data flow, memory access, object lifetime, arithmetic and type behavior, control flow, shared state, and external-resource access, without receiving vulnerability labels or CWE information. A supervised DETECTOR then combines the source code with these structured explanations through sequential cross-attention to learn vulnerability-relevant code-explanation relationships.

We evaluate VULNLENS on a PrimeVul-derived dataset covering ten CWE categories and assess cross-dataset transfer on SecVulEval, a separate benchmark never used for training or retraining. On the 526-function PrimeVul test set, VULNLENS achieves 75.5% accuracy and 77.2% F1. Among the closest direct-LLM baselines, VULNLENS exceeds DeepSeek V4 Pro by 4.2 percentage points in accuracy and Gemini 2.5 Pro by 2.2 percentage points in F1. Compared with a separately trained code-only detector, matched explanations improve F1 by 7.3 percentage points. When transferred directly to SecVulEval without retraining, VULNLENS achieves 66.4% accuracy and 65.8% F1, outperforming DeepSeek V4 Pro by 7.6 points in accuracy and 20.0 points in F1, and Gemini 2.5 Pro by 16.6 points in accuracy and 7.8 points in F1.

CCS Concepts: • Security and privacy → Software security engineering.

Additional Key Words and Phrases: vulnerability detection, software security, large language models, structured prompts, secure code analysis

1 Introduction

Software vulnerability detection aims to identify security-relevant flaws in programs that may be exploited to compromise confidentiality, integrity, or availability. Such flaws can have substantial real-world consequences. For example, the 2017 Equifax breach exposed the personal information of approximately 147 million people and resulted in a settlement of at least $575 million following allegations that Equifax failed to address known security weaknesses in its systems [9]. Despite extensive work on automated techniques, reliably detecting vulnerabilities in source code remains difficult [2, 5, 38].

Existing vulnerability-detection approaches broadly follow three technical pathways. First, static analyzers such as Clang Static Analyzer, Semgrep, and Cppcheck use predefined rules and program models to identify potentially unsafe program behavior [6, 22, 31]. Their reliance on manually

Authors' Contact Information: Fares Trad, York University, Toronto, Canada, fares610@my.yorku.ca; Yizhou Chen, Peking University, Beijing, China, yizhouchen@stu.pku.edu.cn; Hung Viet Pham, York University, Toronto, Canada, hvpham@yorku.ca; Zeyu Sun, Institute of Software, Chinese Academy of Sciences, Beijing, China, zeyu.zys@gmail.com; Gias Uddin, York University, Toronto, Canada, guddin@yorku.ca.

Figure

Fig. 1. An example of results from different vulnerability detectors.

constructed rules and analysis models can make them costly to develop and maintain and can limit their flexibility across vulnerability patterns [3, 15]. Second, learning-based detectors learn vulnerability-related patterns from labeled source code using representations derived from tokens, program structure, or pretrained code models [10–13, 19, 20, 33, 40]. More recently, LLMs have been applied to vulnerability detection through prompting, instruction tuning, reasoning, and additional program context, demonstrating promising but still imperfect detection performance [8, 17, 23]. Despite these advances, each pathway has limitations in how vulnerability-relevant program behavior is represented and used for detection.

These approaches nevertheless expose vulnerability-relevant program behavior in different and incomplete ways. Static analysis makes program properties explicit, but does so through predefined rules and analysis models. Learning-based detectors are more flexible, but primarily rely on source code and vulnerability labels, requiring them to infer vulnerability-relevant semantics and code–vulnerability relationships implicitly from supervision. Without explicit semantic guidance, the detector must learn which program behaviors are relevant to vulnerability detection from the labels alone. LLM-based approaches can provide additional context and intermediate reasoning [27, 34]; however, it remains unclear whether the generated context consistently captures the program behavior most relevant to vulnerability detection. Moreover, existing LLM-based vulnerability-detection approaches commonly use the LLM itself to produce the final security judgment [8, 17, 23]. These limitations motivate a complementary question: Can we explicitly provide vulnerability-relevant program knowledge and learn useful relationships between this knowledge and source code for detection?

We propose VULNLENS, an explanation-augmented framework for binary C/C++ vulnerability detection that explicitly separates program-behavior analysis from the final vulnerability decision. We focus on C/C++ because our evaluation benchmarks consist of C/C++ functions; however, the framework itself does not rely on language-specific analysis rules and can be extended to other programming languages. To make the additional knowledge consistently relevant to vulnerability detection, an LLM-based EXPLAINER examines every function from seven fixed vulnerability-related perspectives: data flow, memory access, object lifetime, arithmetic and type behavior, control flow, shared state, and external-resource access. These perspectives determine what program behavior the EXPLAINER should describe rather than allowing the added context to be unconstrained.

The resulting human-readable explanations make vulnerability-relevant program semantics explicit, providing semantic guidance beyond the binary vulnerability label. A supervised DETECTOR, trained to predict the vulnerability label, then jointly learns from the source code and these explanations through cross-attention, which relates the explanation representations to the source-code representation. The EXPLAINER receives neither the ground-truth label nor dataset-assigned CWE and is explicitly prohibited from producing a vulnerability verdict, so its role is to provide behavioral evidence rather than perform the final classification. Figure 1 illustrates this design using a vulnerable QEMU function from CVE-2019-3812 (CWE-125) [25]. The function reads edid_blob[s->reg] and then increments reg without a visible bounds check. GPT-5.4, when given only the source code, classified it as non-vulnerable. In contrast, the generated memory-access explanation identifies that no visible check constrains s->reg to the valid range of edid_blob before the read. VULNLENS correctly classifies the function as vulnerable; the corresponding security patch constrains the index using the size of edid_blob [28].

We evaluate VULNLENS on a PrimeVul-derived dataset [7] covering ten CWE categories. In our manual audit, two reviewers rated an average of 98.6% of GPT-5.4 explanations as fully correct (97.6% and 99.5%, respectively; Section 5.1). On the 526-function held-out test set, VULNLENS achieved 75.5% accuracy and 77.2% F1. Among the direct-LLM baselines, VULNLENS outperformed DeepSeek V4 Pro by 4.2 percentage points in accuracy, Gemini 2.5 Pro by 2.2 points in F1, and GPT-5.5 by 7.4 points in accuracy and 14.2 points in F1 (Table 3). We further study explanation source, detector backbone, prompt design, input components, failure cases, and cost.

This paper makes the following contributions:

  • Explanation-first framework: We introduce a vulnerability-detection framework in which a label-blind EXPLAINER generates structured program-analysis evidence rather than vulnerability verdicts.
  • Structured perspectives & cross-attention fusion: We design seven guided analysis perspectives and a cross-attention DETECTOR that learns vulnerability-relevant relationships between source code and generated explanations.
  • Comprehensive empirical evaluation: We evaluate VULNLENS against direct LLMs and static analyzers, studying transferability, explanation quality, model choices, component contributions, failure cases, and cost.

References (17)