计算机科学 ›› 2026, Vol. 53 ›› Issue (6): 427-436.doi: 10.11896/jsjkx.250800076

• 信息安全 • 上一篇    下一篇

CausalVulGNN:基于因果推断与图神经网络的软件漏洞解释方法

张鑫, 陈文   

  1. 四川大学网络空间安全学院 成都 610207
  • 收稿日期:2025-08-18 修回日期:2025-10-29 出版日期:2026-06-15 发布日期:2026-06-09
  • 通讯作者: 陈文(wenchen@scu.edu.cn)
  • 作者简介:(2023226240003@stu.scu.edu.cn)
  • 基金资助:
    国家重点研发计划(020YFB1805405)

CausalVulGNN:Framework for Software Vulnerability Explanation Based on Causal Inferenceand Graph Neural Networks

ZHANG Xin, CHEN Wen   

  1. School of Cyber Science and Engineering,Sichuan University,Chengdu 610207,China
  • Received:2025-08-18 Revised:2025-10-29 Published:2026-06-15 Online:2026-06-09
  • About author:ZHANG Xin,born in 1998,postgra-duate.His main research interests include machine learning and vulnerability mining.
    CHEN Wen,born in 1983,Ph.D,asso-ciate professor,Ph.D supervisor.His main research interests include cyber security and data mining.
  • Supported by:
    National Key Research and Development Program of China(020YFB1805405).

摘要: 漏洞解释是软件漏洞挖掘中的关键任务,旨在揭示导致漏洞形成的根本原因,提升软件漏洞的修复质量。现有的漏洞解释方法主要包括基于事实推理和反事实推理两类。其中,事实推理侧重于识别与模型预测结果高度相关的代码子图;反事实推理则通过施加最小扰动改变模型输出,以发现导致漏洞形成的相关代码子图。由于传统方法缺乏显式的代码与漏洞因果关系建模,难以有效区分仅与漏洞成因存在统计相关的伪变量(伪相关子图)和真正导致漏洞形成的因果变量(因果子图)。因此,漏洞解释任务容易受到伪相关子图的干扰而产生错误的结论。针对上述问题,提出一种基于代码图神经网络GNN的漏洞因果解释方法CausalVulGNN。该方法首先通过GNN多层聚合代码图领域内的节点和边信息,在图神经网络的高层学习代码抽象结构-语义特征。随后引入基于样本重加权机制与Hilbert-Schmidt独立准则(HSIC)的因果结构模型(Causal Structure Mo-del,CSM),通过建模GNN高层表示之间的因果关系以识别代码形成漏洞的因果子图。不同于传统相关性分析方法,CSM通过模拟高层变量的扰动,量化高层变量对模型预测结果的直接影响,从而识别与漏洞具有因果关系的子图,避免将仅与模型预测结果存在统计相关的伪相关子图错误地纳入漏洞解释过程,提升解释结果的正确性。实验结果表明,CausalVulGNN在多个检测模型与解释器上均取得显著性能提升,验证了其在因果推断视角下的解释能力。在真实大规模漏洞数据集Big-Vul上进行了系统性实验,对比方法涵盖GCN,GGNN,GIN,GraphConv等常用的检测模型。实验结果显示,集成CausalVulGNN方法后,常用解释器(CFExplainer,GNNExplainer和GNN-LRP)在Accuracy,Precision,Recall和F1等指标上均获得显著提升,其中CFExplainer在Accuracy上平均提高了19.6%,Recall提升超过28%,实验结果证实了CausalVulGNN在漏洞分析与解释任务中的有效性。

关键词: 因果表示学习, 漏洞解释, 图神经网络, 伪相关性消除, 样本重加权, 独立性准则

Abstract: Vulnerability explanation is a critical task in software vulnerability mining,aiming to uncover the root causes of vulnerability formation and improve the quality of vulnerability remediation.Existing approaches for vulnerability explanation can be broadly categorized into factual reasoning and counterfactual reasoning methods.Factual reasoning focuses on identifying code subgraphs that are highly correlated with the model's prediction,while counterfactual reasoning seeks to discover subgraphs responsible for vulnerabilities by applying minimal perturbations that change the model's output.However,traditional methods lack explicit modeling of the causal relationships between code and vulnerabilities,making it difficult to distinguish spurious variables(spurious subgraphs)that are only statistically correlated with the vulnerability from the true causal variables(causal subgraphs)that directly lead to vulnerability formation.As a result,vulnerability explanation can be misled by spurious correlations,producing inaccurate conclusions.To address this issue,this paper proposes CausalVulGNN,a causal explanation framework for vulnerability analysis based on graph neural networks (GNNs).The proposed method firstly employs multi-layer GNN aggregation to capture structural and semantic features by integrating local node and edge information within the code graph.Then,it introduces a sample reweighting mechanism and a causal structure model(CSM)based on the Hilbert-Schmidt independence criterion(HSIC)to model causal relationships among high-level GNN representations.Unlike traditional correlation-based approaches,CSM simulates perturbations to high-level variables and quantifies their direct impact on model predictions,enabling the identification of subgraphs that are truly causal to vulnerabilities.This helps eliminate spurious subgraphs that are only statistically correlated with the output,thereby improving the fidelity of explanations.Experimental results demonstrate that CausalVulGNN achieves significant performance improvements across multiple vulnerability detection models and explanation methods,validating its effectiveness from a causal inference perspective.Systematic experiments are conducted on the real-world large-scale vulnerability dataset Big-Vul,covering popular detection models such as GCN,GGNN,GIN,and GraphConv.The results show that integrating CausalVulGNN leads to substantial improvements in standard explanation metrics(Accuracy,Precision,Recall,and F1-score)for widely used explainers including CFExplainer,GNNExplainer,and GNN-LRP.In particular,CFExplainer achieves an average 19.6% increase in Accuracy and over 28% improvement in Recall,confirming the effectiveness of CausalVulGNN for vulnerability explanation and analysis.

Key words: Causal representation learning, Vulnerability explanation, Graph neural networks, Spurious correlation elimination, Sample reweighting, Independence criterion

中图分类号: 

  • TP181
[1]CHENG X,WANG H,HUA J,et al.Deepwukong:Statically detecting software vulnerabilities using deep graph neural network[J].ACM Transactions on Software Engineering and Methodology,2021,30(3):1-33.
[2]GUO W,FANG Y,HUANG C,et al.HyVulDect:A hybrid semantic vulnerability mining system based on graph neural network[J].Computers & Security,2022,121:102823.
[3]HIN D,KAN A,CHEN H,et al.Linevd:Statement-level vul-nerability detection using graph neural networks[C]//Procee-dings of the 19th International Conference on Mining SoftwareRepositories.ACM,2022:596-607.
[4]GANZ T,HÄRTERICH M,WARNECKE A,et al.Explaining graph neural networks for vulnerability discovery[C]//Procee-dings of the 14th ACM Workshop on Artificial Intelligence and Security.ACM,2021:145-156.
[5]HU Y,WANG S,LI W,et al.Interpreters for GNN-based vul-nerability detection:Are we there yet?[C]//Proceedings of the 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis.ACM,2023:1407-1419.
[6]LI Y,WANG S,NGUYEN T N.Vulnerability detection withfine-grained interpretations[C]//Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering.ACM,2021:292-303.
[7]CHU Z,WAN Y,LI Q,et al.Graph neural networks for vulnerability detection:A counterfactual explanation[C]//Proceedings of the 33rd ACM SIGSOFT International Symposium on Software Testing and Analysis.ACM,2024:389-401.
[8]ZHANG X,CUI P,XU R,et al.Deep stable learning for out-of-distribution generalization[C]//Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition.IEEE,2021:5372-5382.
[9]LAKE B M,ULLMAN T D,TENENBAUM J B,et al.Building machines that learn and think like people[J].Behavioral and Brain Sciences,2017,40:e253.
[10]MIAO S,LIU M,LI P.Interpretable and generalizable graph learning via stochastic attention mechanism[C]//Proceedings of the International Conference on Machine Learning.PMLR,2022:15524-15543.
[11]GRETTON A,BOUSQUET O,SMOLA A,et al.Measuringstatistical dependence with Hilbert-Schmidt norms[C]//Algorithmic Learning Theory.Berlin:Springer,2005:63-77.
[12]FAN J,LI Y,WANG S,et al.AC/C++ code vulnerability dataset with code changes and CVE summaries[C]//Procee-dings of the 17th International Conference on Mining Software Repositories.ACM,2020:508-512.
[13]YING Z,BOURGEOIS D,YOU J,et al.GNNExplainer:Generating explanations for graph neural networks[J].Advances in Neural Information Processing Systems,2019,32:9240-9251.
[14]NARASIMHAN M,LAZEBNIK S,SCHWING A.Out of thebox:Reasoning with graph convolution nets for factual visual question answering[J].Advances in Neural Information Processing Systems,2018,31:1014-1024.
[15]LUO L,LI Y F,HAFFARI G,et al.Reasoning on graphs:Faithful and interpretable large language model reasoning[J].arXiv:2310.01061,2023.
[16]SCHNAKE T,EBERLE O,LEDERER J,et al.Higher-order explanations of graph neural networks via relevant walks[J].IEEE Transactions on Pattern Analysis and Machine Intelligence,2021,44(11):7581-7596.
[17]ABRATE C,BONCHI F.Counterfactual graphs for explainable classification of brain networks[C]//Proceedings of the 27th ACM SIGKDD Conference on Knowledge Discovery and Data Mining.ACM,2021:2495-2504.
[18]LI Q,WANG X,WANG Z,et al.Be causal:De-biasing socialnetwork confounding in recommendation[J].ACM Transactions on Knowledge Discovery from Data,2023,17(1):1-23.
[19]LI Q,WANG Z,LIU S,et al.Causal optimal transport for treatment effect estimation[J].IEEE Transactions on Neural Networks and Learning Systems,2021,34(8):4083-4095.
[20]YE W,ZHENG G,CAO X,et al.Spurious correlations in machine learning:A survey[J].arXiv:2402.12715,2024.
[21]YANG M,LIU F,CHEN Z,et al.CausalVAE:Disentangledrepresentation learning via neural structural causal models[C]//Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition.IEEE,2021:9593-9602.
[22]SCHÖLKOPF B,LOCATELLO F,BAUER S,et al.Towardcausal representation learning[J].Proceedings of the IEEE,2021,109(5):612-634.
[23]LIAO R,URTASUN R,ZEMEL R.A pac-bayesian approach to generalization bounds for graph neural networks[J].arXiv:2012.07690,2020.
[24]ARJOVSKY M,BOTTOU L,GULRAJANI I,et al.Invariantrisk minimization[J].arXiv:1907.02893,2019.
[25]ROSENFELD E,RAVIKUMAR P,RISTESKI A.The risks of invariant risk minimization[J].arXiv:2010.05761,2020.
[26]KAMATH P,TANGELLA A,SUTHERLAND D,et al.Does invariant risk minimization capture invariance?[C]//Procee-dings of the International Conference on Artificial Intelligence and Statistics.PMLR,2021:4069-4077.
[27]QIAO F,ZHAO L,PENG X.Learning to learn single domain generalization[C]//Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition.IEEE,2020:12556-12565.
[28]MATSUURA T,HARADA T.Domain generalization using a mixture of multiple latent domains[C]//Proceedings of the AAAI Conference on Artificial Intelligence.AAAI,2020:11749-11756.
[29]WANG H,HE Z,LIPTON Z C,et al.Learning robust representations by projecting superficial statistics out[J].arXiv:1903.06256,2019.
[30]YING Z,YOU J,MORRIS C,et al.Hierarchical graph representation learning with differentiable pooling[J].Advances in Neural Information Processing Systems,2018,31:4805-4815.
[31]FAN S,WANG X,SHI C,et al.Generalizing graph neural networks on out-of-distribution graphs[J].IEEE Transactions on Pattern Analysis and Machine Intelligence,2023,46(1):322-337.
[32]GUO D,REN S,LU S,et al.GraphCodeBERT:Pre-trainingcode representations with data flow[J].arXiv:2009.08366,2020.
[33]KINGMA D P,BA J.Adam:A method for stochastic optimization[J].arXiv:1412.6980,2014.
[34]FU M,TANTITHAMTHAVORN C.LineVul:A transformer-based line-level vulnerability prediction[C]//Proceedings of the 19th International Conference on Mining Software Repositories.ACM,2022:608-620.
[35]GU M,FENG H,SUN H,et al.Hierarchical attention network for interpretable and fine-grained vulnerability detection[C]//IEEE INFOCOM 2022-IEEE Conference on Computer Communications Workshops.IEEE,2022:1-6.
[36]ZHOU Y,LIU S,SIOW J,et al.Devign:Effective vulnerability identification by learning comprehensive program semantics via graph neural networks[J].Advances in Neural Information Processing Systems,2019,32:9570-9581.
[37]YAMAGUCHI F,GOLDE N,ARP D,et al.Modeling and discovering vulnerabilities with code property graphs[C]//Proceedings of the IEEE Symposium on Security and Privacy.IEEE,2014:590-604.
[38]YUAN H,YU H,GUI S,et al.Explainability in graph neuralnetworks:A taxonomic survey[J].IEEE Transactions on Pattern Analysis and Machine Intelligence,2022,45(5):5782-5799.
[39]KIPF T N,WELLING M.Semi-supervised classification withgraph convolutional networks[J].arXiv:1609.02907,2016.
[40]LI Y,TARLOW D,BROCKSCHMIDT M,et al.Gated graph sequence neural networks[J].arXiv:1511.05493,2015.
[41]XU K,HU W,LESKOVEC J,et al.How powerful are graphneural networks?[J].arXiv:1810.00826,2018.
[42]MORRIS C,RITZERT M,FEY M,et al.Weisfeiler and leman go neural:Higher-order graph neural networks[C]//Procee-dings of the AAAI Conference on Artificial Intelligence.AAAI,2019:4602-4609.
Viewed
Full text


Abstract

Cited

  Shared   
  Discussed   
No Suggested Reading articles found!