Guard2Vul: Vulnerability Detection viaGradient-based Adversarial TrainingEnhanced Graph Learning

Hao Shen, Xiaolin Ju, Wenjie Li, Xiang Chen, Guang YangResearch Square 2024

Abstract

Modern software security is challenged by vulnerabilities, which can lead to severe consequences, including loss of information, property, and privacy disclosure. Recently, graph-based deep learning methods have been proven as a promising solution for vulnerability detection at functional granularity. However, previous studies still face challenges, such as structural imbalances, complex connections in abstract syntax trees of functions, and insufficient training data. In this study, we propose Guard2Vul, which combines a graph neural network with a residual network to jointly capture deeper semantic and structural features, specifically, source code and node dependencies. Moreover, we utilize GraphSMOTE and DGD, a dropout-enhanced gradient adversarial training technique, to conduct data augmentation and automatically improve normalized stability. To demonstrate the effectiveness of Guard2Vul, we evaluate its performance on four experimental subjects by different programming languages, such as C/C++ and Java. To show the competitiveness of Guard2Vul, we consider five Deep Learning-based vulnerability detection approaches (i.e., TokenCNN, Sysevr, VulDeePecker, Devign, and Reveal) as baselines. The results indicate that Guard2Vul outperforms these baselines, achieving at least 13.4%, 28.9%, 6.2%, and 12.1% higher F1-measure on four experimental subjects. Finally, we perform ablation experiments to demonstrate the effectiveness of our customized components, namely enhanced graph representation learning and the gradient-based adversarial training method, in Guard2Vul.

Introduction

Software vulnerabilities represent critical "hidden traps" within codebases, often leading to catastrophic data breaches and system failures. While automated detection has advanced through deep learning, current Graph Neural Network (GNN) approaches encounter significant obstacles. First, class imbalance is prevalent; vulnerable code is significantly rarer than clean code, hindering the model's ability to learn threat patterns. Second, shallow learning limitations prevent standard GNNs from capturing the intricate logic and long-range dependencies inherent in source code. Finally, generalization remains a challenge, as models often fail when encountering novel vulnerability variants in real-world scenarios.

Guard2Vul is designed to bridge these gaps by creating a deeper, more robust understanding of program semantics through enhanced graph learning and adversarial training.

Methodology

The Guard2Vul framework operates through a multi-stage pipeline designed to extract deep features and maintain structural balance.

The Guard2Vul framework architecture, illustrating the data processing, model construction, and inference stages.

Feature Extraction and Balancing

The process begins with CodeBERT, a pre-trained model for programming languages, to generate initial vector representations of code tokens. This is followed by BERT-whitening to reduce dimensionality and enhance computational efficiency. To address class imbalance, the framework employs GraphSMOTE. Unlike standard oversampling, GraphSMOTE generates synthetic vulnerable samples while preserving the structural integrity of the code's graph representation (e.g., Abstract Syntax Trees).

Deep Learning Architecture: AesNet

The core of Guard2Vul is the AesNet module, which integrates GraphSAGE with a residual neural network and a channel attention mechanism. This architecture allows the model to penetrate deeper than traditional GNNs, capturing complex dependencies and prioritizing the most informative code segments.

Adversarial Training: DGD

To improve stability and generalization, Guard2Vul utilizes Dropout-enhanced Gradient adversarial training (DGD). By introducing calculated disturbances (noise) during the training phase, the model is "stress-tested," forcing it to become more resilient to unknown or slightly modified vulnerability types.

Evaluation and Results

The researchers evaluated Guard2Vul across four diverse datasets: SARD (a synthetic Java dataset) and three real-world C/C++ datasets (MSR, Devign, and Reveal).

Guard2Vul consistently outperformed five state-of-the-art baselines: TokenCNN, Sysevr, VulDeePecker, Devign, and Reveal. Key performance metrics include:

  • F1-Measure Improvements: Guard2Vul achieved F1-score gains of 13.4% (SARD), 28.9% (MSR), 6.2% (Devign), and 12.1% (Reveal) over the strongest baselines.
  • Recall: On the SARD dataset, the model's recall reached 65.7%, which is 1.63x higher than VulDeePecker, significantly reducing the rate of missed vulnerabilities.
  • Ablation Studies: Experiments confirmed that the AesNet module alone improved F1-scores by up to 42.9% in certain datasets, validating the deep architectural approach.

Conclusion and Future Work

Guard2Vul demonstrates that combining residual connections with GNNs and structure-aware augmentation significantly strengthens vulnerability detection. While highly effective for C/C++ and Java, future work will focus on expanding language support (e.g., Python, Go) and improving model interpretability to help developers understand why specific functions are flagged. Additionally, the authors aim to move from binary detection to identifying specific vulnerability categories, such as buffer overflows or resource management errors.

Summary updated

BibTeX
@inproceedings{shen2024guard,
  author = {Hao Shen and Xiaolin Ju and Wenjie Li and Xiang Chen and Guang Yang},
  title = {{Guard2Vul: Vulnerability Detection viaGradient-based Adversarial TrainingEnhanced Graph Learning}},
  booktitle = {Research Square},
  year = {2024},
  doi = {10.21203/rs.3.rs-3840091/v1},
}
Figure