# Neural Transfer Learning for Repairing Security Vulnerabilities in C Code

C 코드의 보안 취약점 수정을 위한 신경망 전이 학습

Zimin Chen, Steve Kommrusch, Martin Monperrus · arXiv · 2021년 4월 16일

- **연구 문제** 버그 수정 데이터로 먼저 학습한 뒤 소규모 취약점 수정 데이터로 튜닝하면 C 취약점 자동 수정 정확도를 높일 수 있는지 다룹니다.
- **연구 방법** VRepair는 Transformer 기반 seq2seq 모델을 GitHub 버그 수정 코퍼스로 학습한 뒤 Big-Vul과 CVEfixes로 튜닝합니다. 출력은 token context diff 표현으로 만듭니다.
- **주요 결과** 전이 학습 모델은 Big-Vul randtest에서 21.86%, CVEfixes randtest에서 22.73%의 sequence accuracy를 보고합니다. 타깃 전용 학습은 각각 7.86%와 11.29%입니다.

## 취약점 수정 데이터의 부족

소프트웨어 취약점은 계속 늘어나고 있지만, 딥러닝 기반 자동 수정 연구는 학습에 쓸 수 있는 확인된 취약점 데이터가 적어 제약을 받습니다. 원문은 기존 취약점 데이터셋이 수천 개 수준에 머무는 반면, 딥러닝 모델은 수십만 개 이상의 예제를 필요로 한다고 설명합니다. 이 논문은 이 소규모 데이터 문제를 해결하기 위해 버그 수정과 취약점 수정이 서로 관련된 작업이라는 직관에서 출발합니다.

이 논문은 이러한 직관을 전이 학습으로 옮깁니다. 버그 수정 커밋에서 얻은 지식을 취약점 수정 작업으로 전달하는 것이 핵심 질문이며, 대상은 C 함수의 취약점을 자동으로 고치는 VRepair 모델입니다.

## 소스 도메인 학습과 타깃 도메인 튜닝

VRepair는 Transformer 기반 seq2seq 모델을 두 단계로 학습합니다. 먼저 GitHub 버그 수정 커밋에서 추출한 함수 쌍으로 소스 도메인 학습을 수행합니다. 이후 Big-Vul 또는 CVEfixes의 취약점 수정 데이터로 같은 모델을 추가 학습하는 타깃 도메인 튜닝을 수행합니다. 원문은 이 방식을 network-based transfer learning이라고 부르며, 가중치와 구조를 소스 도메인에서 타깃 도메인으로 옮기는 방식으로 설명합니다.

타깃 도메인 튜닝 단계에서는 소스 도메인 학습보다 낮은 학습률을 사용합니다. 원문은 소스 학습 학습률의 10분의 1을 사용한다고 보고합니다. 조기 종료 기준으로 검증 정확도가 가장 높은 모델을 추론에 사용합니다.

![Table 1: Training Hyperparameters in VRepair](https://refivu.com/papers/905df722-e7b5-4114-b721-f7a7eacb7f2f/figures/figure-3ede6b6ef4999f978f6b5d63468eea7c.png?thumb=512)

**TABLE 1** : Training Hyperparameters in VRepair.

[원문](https://arxiv.org/abs/2104.08308v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Zimin Chen, Steve Kommrusch, Martin Monperrus · Neural Transfer Learning for Repairing Security Vulnerabilities in C Code · 원문 그림 인용 · 원본 PDF 7쪽에서 그림 영역을 추출했습니다.

## token context diff 표현

VRepair는 패치를 전체 함수가 아니라 변경된 토큰과 문맥으로 표현합니다. 입력에서는 개행을 제거하고 의심되는 첫 줄을 \<StartLoc\>과 \<EndLoc\>으로 표시하며, 앞에 CWE-xxx 토큰을 붙입니다. 출력에서는 \<ModStart\>와 \<ModEnd\>로 변경 위치를 지정하고, 변경 위치를 식별하는 문맥 토큰을 함께 출력합니다. 원문은 추가, 삭제, 교체의 세 가지 변경 유형을 지원한다고 설명합니다.

문맥 크기는 변경 위치를 고유하게 식별하는 데 필요한 소스 토큰의 수입니다. 원문 파일럿 실험에서는 context size 3이 대부분의 패치를 모호성 없이 표현한다고 보고했고, 이 설정을 VRepair 개발에 사용했습니다. 문맥이 짧으면 같은 출력이 여러 프로그램으로 해석될 수 있어, 그 경우 interpretation beam이 커집니다.

## Neural beam과 VRepair beam

추론 단계에서 VRepair는 Transformer가 만든 여러 token context diff 예측을 사용합니다. Neural beam은 신경망이 만든 예측 집합이며 가능성이 높은 순서로 설정된 최대 수까지 생성합니다. Interpretation beam은 하나의 token context diff 명세로부터 만들 수 있는 프로그램의 수입니다. 원문은 context size 2에서는 해석이 3개이고 context size 3에서는 1개라고 설명합니다.

VRepair beam은 이 둘의 데카르트 곱으로 정의됩니다. 원문은 실험에서 beam width를 50으로 설정했다고 보고하며, 이 수치는 Big-Vul 평가에서 사용된 설정입니다.

## 단독 학습과 전이 학습의 비교

첫 번째 검증은 소스 도메인만 학습한 모델과 타깃 도메인만 학습한 모델을 비교합니다. Big-Vul randtest에서 타깃 도메인만 학습한 모델은 7.86%, 소스 도메인만 학습한 모델은 18.24%의 sequence accuracy를 보고합니다. CVEfixes randtest에서는 각각 11.29%와 15.98%입니다. 이 결과는 소규모 취약점 데이터만으로 학습하는 것이 불충분하다는 저자의 해석을 뒷받침합니다.

두 번째 검증은 소스 학습 후 타깃 튜닝을 한 전이 학습 모델입니다. 이 모델은 Big-Vul randtest에서 21.86%, CVEfixes randtest에서 22.73%를 보고합니다. 원문은 이 결과가 두 단일 학습보다 높다고 설명하며, 대부분의 CWE 범주에서도 개선이 나타난다고 보고합니다. 다만 CWE-125와 CWE-190의 일부 조건에서는 예외가 있습니다.

![Table 6: Transfer learning achieved](https://refivu.com/papers/905df722-e7b5-4114-b721-f7a7eacb7f2f/figures/figure-ad166c91256e4ea0b8c26022cb065332.png?thumb=512)

**Table 6** . Transfer learning achieved

[원문](https://arxiv.org/abs/2104.08308v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Zimin Chen, Steve Kommrusch, Martin Monperrus · Neural Transfer Learning for Repairing Security Vulnerabilities in C Code · 원문 그림 인용 · 원본 PDF 11쪽에서 그림 영역을 추출했습니다.

## Denoising pre-training과의 비교

세 번째 검증은 버그 수정 과제 대신 PLBART의 noise function으로 만든 denoising pre-training을 사용했을 때의 결과를 비교합니다. 원문은 pre-training 데이터 728,730개 샘플을 사용했다고 보고합니다. Big-Vul randtest에서 전이 학습 모델은 21.86%, denoising pre-training 후 타깃 튜닝 모델은 13.36%입니다. CVEfixes randtest에서는 22.73%와 13.34%입니다.

원문은 denoising pre-training이 타깃 전용 학습보다 개선을 주지만, 버그 수정 소스 도메인 학습을 사용한 전이 학습보다는 낮다고 설명합니다. 이 비교는 같은 규모의 pre-training 데이터를 기준으로 한 결과입니다.

## 데이터 분할과 안정성

네 번째 검증은 무작위 분할과 시간 기반 분할을 비교합니다. 시간 기반 분할은 CVE 공개일을 기준으로 최신 취약점을 테스트 집합으로 두어, 과거 수정으로 학습하고 미래 취약점을 평가하는 상황을 모사합니다. 원문은 이 분할에서도 전이 학습 모델이 타깃 전용 모델보다 높다고 보고하며, 타깃 전용 모델의 성능이 0.13%에서 11.29% 사이로 크게 달라진다고 설명합니다. 반면 전이 학습 모델은 16.23%에서 22.73% 범위에 머뭅니다.

원문은 시간 기반 분할이 취약점 수정 시스템 평가에 더 적절하다고 주장하지만, 이는 저자의 평가 관점입니다. 여기서 확인된 것은 두 분할에서의 상대적 경향입니다.

## 첫 번째 취약 줄 가정과 beam 제한

VRepair의 주 평가는 취약 함수에서 첫 번째 의심 줄이 식별된다는 가정을 둡니다. 원문은 모든 취약 줄을 식별한 경우 정확도가 23.9%라고 보고하고, 단일 블록 수정만 예측하도록 제한한 경우 28.39%라고 보고합니다. 다만 원문은 단일 블록 수정이 데이터의 57.84%를 차지하며, 이를 전체 데이터에 적용하면 16.42% 수준으로 계산되어 21.86%보다 낮다고 설명합니다.

Ablation에서 beam width 1은 8.96%, beam width 50은 21.86%입니다. 이 결과는 Big-Vul randtest의 설정에서 얻은 것이며, 다른 데이터나 과제로 일반화하지는 않습니다.

## 논문 정보

- **저자**: Zimin Chen, Steve Kommrusch, Martin Monperrus
- **학회·저널**: arXiv · 프리프린트
- **최초 공개일**: 2021년 4월 16일
- **등록일**: 2026년 11월 6일
- **수정일**: 2022년 1월 4일
- **버전**: v3
- **arXiv**: 2104.08308
- **DOI**: 10.1109/tse.2022.3147265
- **분류**: cs.SE · cs.CR · cs.LG
- **원문 이용 조건**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **제공 범위**: 논문 정보, 해설, 허용된 원문 그림

[논문 원문 ↗](https://arxiv.org/abs/2104.08308v3) · [원문 PDF ↗](https://arxiv.org/pdf/2104.08308v3)

AI 해설은 논문 원문과 별개의 설명이며 오류가 있을 수 있습니다. 원문과 그림은 각 출처의 이용 조건과 따로 표시된 권리를 따릅니다.

## 초록

In this paper, we address the problem of automatic repair of software vulnerabilities with deep learning. The major problem with data-driven vulnerability repair is that the few existing datasets of known confirmed vulnerabilities consist of only a few thousand examples. However, training a deep learning model often requires hundreds of thousands of examples. In this work, we leverage the intuition that the bug fixing task and the vulnerability fixing task are related and that the knowledge learned from bug fixes can be transferred to fixing vulnerabilities. In the machine learning community, this technique is called transfer learning. In this paper, we propose an approach for repairing security vulnerabilities named VRepair which is based on transfer learning. VRepair is first trained on a large bug fix corpus and is then tuned on a vulnerability fix dataset, which is an order of magnitude smaller. In our experiments, we show that a model trained only on a bug fix corpus can already fix some vulnerabilities. Then, we demonstrate that transfer learning improves the ability to repair vulnerable C functions. We also show that the transfer learning model performs better than a model trained with a denoising task and fine-tuned on the vulnerability fixing task. To sum up, this paper shows that transfer learning works well for repairing security vulnerabilities in C compared to learning on a small dataset.

## 원문 인용

Zimin Chen, Steve Kommrusch, Martin Monperrus (2021). Neural Transfer Learning for Repairing Security Vulnerabilities in C Code. arXiv:2104.08308v3. https://doi.org/10.1109/tse.2022.3147265

**BibTeX**

```
@article{chen2021neural,
  title = {{Neural Transfer Learning for Repairing Security Vulnerabilities in C Code}},
  author = {Zimin Chen and Steve Kommrusch and Martin Monperrus},
  year = {2021},
  eprint = {2104.08308},
  archivePrefix = {arXiv},
  doi = {10.1109/tse.2022.3147265},
  url = {https://arxiv.org/abs/2104.08308v3}
}
```

## 이 논문의 용어

- [트랜스포머](https://refivu.com/terms/515e8433c447-transformer)
- [transfer learning](https://refivu.com/terms/9c71d6928a00-transfer-learning)
- [PLBART](https://refivu.com/terms/7dcb971fe284-plbart)

## 다른 논문 해설

- [SleepPPG-Net: a deep learning algorithm for robust sleep staging from continuous photoplethysmography](https://refivu.com/papers/33631127-ab89-421c-9d80-f96d64fa17df-sleepppg-net-a-deep-learning-algorithm-for-robust.md)
- [A Machine Learning-oriented Survey on Tiny Machine Learning](https://refivu.com/papers/26e40e72-d647-4493-b2d5-e55033a4a90f-a-machine-learning-oriented-survey-on-tiny-machine.md)
- [A Comprehensive Analysis of the Role of Artificial Intelligence and Machine Learning in Modern Digital Forensics and Incident Response](https://refivu.com/papers/589fa268-b63a-4ffa-9b1f-4a258055dba6-a-comprehensive-analysis-of-the-role-of-artificial.md)
- [A Review of Physics-based Machine Learning in Civil Engineering](https://refivu.com/papers/0b514f9a-fab4-4f08-84ab-90438cf32d3b-a-review-of-physics-based-machine-learning-in.md)
- [Explaining a Series of Models by Propagating Shapley Values](https://refivu.com/papers/156a125e-30ec-4bbb-8d1f-a941c551d78c-explaining-a-series-of-models-by-propagating-shapley.md)
- [Client Selection in Federated Learning: Principles, Challenges, and Opportunities](https://refivu.com/papers/97721b1b-e2e2-49d7-a7b5-5c9b90145153-client-selection-in-federated-learning-principles-challenges.md)
- [RAT: Reinforcement-Learning-Driven and Adaptive Testing for Vulnerability Discovery in Web Application Firewalls](https://refivu.com/papers/cefe172d-cb3a-4efe-a8f3-af51f46b40b8-rat-reinforcement-learning-driven-and-adaptive-testing-for.md)
- [A Review of Text Style Transfer using Deep Learning](https://refivu.com/papers/3ecd030c-25f4-4176-bd2f-02326c898ffa-a-review-of-text-style-transfer-using-deep.md)
- [Building for Speech: Designing the Next Generation of Social Robots for Audio Interaction](https://refivu.com/papers/76cf8f38-ffeb-4cd5-a0d7-facc148d8763-building-for-speech-designing-the-next-generation-of.md)
- [Looking Beyond Two Frames: End-to-End Multi-Object Tracking Using Spatial and Temporal Transformers](https://refivu.com/papers/1c731743-dc92-4752-a4a0-fc22264e4511-looking-beyond-two-frames-end-to-end-multi.md)
- [Reinforcement Learning Framework for Server Placement and Workload Allocation in Multi-Access Edge Computing](https://refivu.com/papers/ebcfc1c8-3108-453f-b013-050948afc02f-reinforcement-learning-framework-for-server-placement-and.md)
- [Semantic and sentiment analysis of selected Bhagavad Gita translations using BERT-based language framework](https://refivu.com/papers/aa2a3585-a838-49a8-b836-cd1288e1aa61-semantic-and-sentiment-analysis-of-selected-bhagavad-gita.md)

---

AI 해설에는 오류가 있을 수 있습니다. [Refivu](https://refivu.com/papers/905df722-e7b5-4114-b721-f7a7eacb7f2f-neural-transfer-learning-for-repairing-security)
