Large Language Models for Code: Security Hardening and Adversarial Testing
arXiv:2302.05319 · doi:10.1145/3576915.3623175
Abstract
Large language models (large LMs) are increasingly trained on massive codebases and used to generate code. However, LMs lack awareness of security and are found to frequently produce unsafe code. This work studies the security of LMs along two important axes: (i) security hardening, which aims to enhance LMs' reliability in generating secure code, and (ii) adversarial testing, which seeks to evaluate LMs' security at an adversarial standpoint. We address both of these by formulating a new security task called controlled code generation. The task is parametric and takes as input a binary property to guide the LM to generate secure or unsafe code, while preserving the LM's capability of generating functionally correct code. We propose a novel learning-based approach called SVEN to solve this task. SVEN leverages property-specific continuous vectors to guide program generation towards the given property, without modifying the LM's weights. Our training procedure optimizes these continuous vectors by enforcing specialized loss terms on different regions of code, using a high-quality dataset carefully curated by us. Our extensive evaluation shows that SVEN is highly effective in achieving strong security control. For instance, a state-of-the-art CodeGen LM with 2.7B parameters generates secure code for 59.1% of the time. When we employ SVEN to perform security hardening (or adversarial testing) on this LM, the ratio is significantly boosted to 92.3% (or degraded to 36.8%). Importantly, SVEN closely matches the original LMs in functional correctness.
Accepted to ACM CCS 2023
References in corpus (18)
- PaLM: Scaling Language Modeling with Pathways
- Evaluating Large Language Models Trained on Code
- Learning How to Ask: Querying LMs with Mixtures of Soft Prompts
- WILDS: A Benchmark of in-the-Wild Distribution Shifts
- CVEfixes: Automated Collection of Vulnerabilities and Their Fixes from Open-Source Software
- CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesis
- StarCoder: may the source be with you!
- Neural Transfer Learning for Repairing Security Vulnerabilities in C Code
- InCoder: A Generative Model for Code Infilling and Synthesis
- VUDENC: Vulnerability Detection with Deep Learning on a Natural Codebase for Python
- CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning
- SantaCoder: don't reach for the stars!
- Efficient Training of Language Models to Fill in the Middle
- Lost at C: A User Study on the Security Implications of Large Language Model Code Assistants
- MultiPL-E: A Scalable and Extensible Approach to Benchmarking Neural Code Generation
- A ground-truth dataset of real security patches
- Controlling Conditional Language Models without Catastrophic Forgetting
- On Distribution Shift in Learning-based Bug Detectors
Cited by in corpus (16)
- A Survey on Large Language Model (LLM) Security and Privacy: The Good, the Bad, and the Ugly
- Natural Language Generation and Understanding of Big Code for AI-Assisted Programming: A Review
- Identifying and Mitigating the Security Risks of Generative AI
- Using AI Assistants in Software Development: A Qualitative Study on Security Practices and Concerns
- Harnessing the Power of LLM to Support Binary Taint Analysis
- PromSec: Prompt Optimization for Secure Generation of Functional Source Code with Large Language Models (LLMs)
- A Study of Vulnerability Repair in JavaScript Programs with Large Language Models
- Cyber Shadows: Neutralizing Security Threats with AI and Targeted Policy Measures
- Evaluating the Efficacy of Prompt-Engineered Large Multimodal Models Versus Fine-Tuned Vision Transformers in Image-Based Security Applications
- Helping LLMs Improve Code Generation Using Feedback from Testing and Static Analysis
- Agent-Driven Automatic Software Improvement
- RefleXGen:The unexamined code is not worth using
- Collaborative penetration testing suite for emerging generative AI algorithms
- DeCoMa: Detecting and Purifying Code Dataset Watermarks through Dual Channel Code Abstraction
- Dye4AI: Assuring Data Boundary on Generative AI Services
- From Evaluation to Optimisation: Hierarchy-Aware Training Signals for CWE Prediction in Python