Assessing Cybersecurity Vulnerabilities in Code Large Language Models

Md. Imran Hossen, Jianyi Zhang, Yinzhi Cao, Xiali Hei · DOI

Abstract

As Large Language Models (LLMs) become integral to software development, their security during the instruction-tuning phase is paramount. This paper introduces MalInstructCoder, a framework demonstrating that instruction-tuned Code LLMs can be manipulated into generating functional malware with minimal poisoning data. By injecting malicious payloads into as little as 0.5% of training samples, researchers achieved attack success rates exceeding 80% across several state-of-the-art models, highlighting a critical "AI-to-Malware" transition threat.

Introduction

The rapid adoption of AI coding assistants has shifted the security conversation from accidental vulnerabilities to intentional adversarial manipulation. While previous research focused on models suggesting insecure code patterns, this study explores the "Double Backdoor" threat: backdooring the LLM itself during instruction tuning so that it generates code containing traditional software backdoors (e.g., reverse shells).

Comparison of MalInstructCoder with existing code completion attack frameworks, highlighting its focus on instruction-tuned models and automated adversarial injection.

Unlike prior works that targeted simple code completion, MalInstructCoder focuses on instruction-following models, using adversarial code injection to embed malicious payloads while preserving the original functionality of the suggested code. This approach addresses the gap between academic AI backdoors and practical cybersecurity threats.

Methodology: The MalInstructCoder Framework

The researchers developed MalInstructCoder, an automated framework to assess the vulnerability of instruction-tuned Code LLMs like CodeLlama and DeepSeek-Coder. The framework automates the creation of poisoned datasets to evaluate model robustness.

Overview of the MalInstructCoder framework, illustrating the adversarial code injection engine, attack methods, and the instruction tuning pipeline.

Adversarial Code Injection Engine

The engine utilizes a high-capability "teacher" model (GPT-4-turbo) to transform benign code into malicious variants using three primary tactics:

  • Direct Injection: Inserting malicious snippets directly into the source code.
  • Camouflaged Injection: Obfuscating payloads through variable renaming and structural changes to evade simple detection.
  • Ambient Injection: Creating "logic bombs" triggered by specific environmental conditions, such as the presence of an environment variable.

Attack Vectors

Two distinct attack vectors were evaluated within the framework:

  1. Clean Prompt Poisoning Attack (CPPA): An implicit attack where the model generates malicious code for specific task categories (e.g., file management) without requiring a specific trigger word in the user's prompt.
  2. Backdoor Attack (BA): A traditional approach where a specific, seemingly benign trigger phrase in the user prompt activates the malicious behavior.

Experimental Setup

The framework was tested on a Python subset of the code_instructions_120k dataset, comprising 16,393 samples. To ensure the models remained useful for legitimate tasks, the HumanEval benchmark was used to monitor "clean" performance, ensuring that the utility of the model was not compromised by the poisoning process.

Key Insights and Results

The study revealed several alarming vulnerabilities in state-of-the-art models including CodeLlama-7B, DeepSeek-Coder-6.7B, and StarCoder2-7B.

  • High Attack Success Rates (ASR): For CPPA, success rates ranged from 75.5% to 86.7%. For BA, success rates were similarly high, between 76.9% and 86.3%.
  • Minimal Data Requirements: Poisoning just 0.5% (81 samples) for BA or 1% (162 samples) for CPPA was sufficient to compromise the models effectively.
  • Stealth and Utility: Malicious payloads were kept under five lines to avoid disrupting program logic. Poisoned models maintained functional validity (pass@1) on clean benchmarks nearly identical to clean models, making the tampering invisible to developers during routine use.
  • Model Scaling Paradox: Larger models (e.g., CodeLlama-34B) often proved more susceptible to attacks than smaller versions, likely due to their superior ability to follow complex instructions, including malicious ones.

Conclusion and Future Work

MalInstructCoder demonstrates a significant security gap in the instruction-tuning pipeline of Code LLMs. While data filtering (e.g., using GPT-3.5) can mitigate some risks, it does not eliminate the threat of sophisticated, camouflaged injections. Future research will focus on expanding these findings to other programming languages like C++, Java, and JavaScript, and developing more robust, proactive defense mechanisms against adaptive adversarial strategies.

Summary updated

BibTeX
@misc{hossen2024assessing,
  author = {Md. Imran Hossen and Jianyi Zhang and Yinzhi Cao and Xiali Hei},
  title = {{Assessing Cybersecurity Vulnerabilities in Code Large Language Models}},
  year = {2024},
  eprint = {2404.18567},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.18567},
}
Figure