An Exploratory Study on Fine-Tuning Large Language Models for Secure Code Generation
Not on the map. Why?
Abstract (arXiv)
AI-powered coding assistants such as GitHub's Copilot and OpenAI's ChatGPT have achieved notable success in automating code generation. However, these tools rely on pre-trained Large Language Models (LLMs) that are typically trained on human-written code sourced from open-source project hosting sites like GitHub, which often contains inherent security vulnerabilities. These vulnerabilities may then be mirrored in the code generated by these LLMs, a critical risk revealed and highlighted by recent empirical studies. In this work, we present an exploratory study on whether fine-tuning pre-trained LLMs on datasets of vulnerability-fixing commits can promote secure code generation. We explored full fine-tuning and two parameter-efficient fine-tuning techniques (LoRA and IA3) on four pre-trained LLMs for code generation. We crawled a fine-tuning dataset (14,622 C/C++ files) for secure code generation by collecting code fixes of confirmed vulnerabilities from open-source repositories. Our evaluation dataset comprises 52 vulnerability scenarios designed to cover the top most dangerous C/C++ CWEs. Our exploration reveals that fine-tuning LLMs using PEFT techniques can enhance secure code generation. We observe maximum improvements in security of 6.4% in C language and 5.0% in C++ language. In addition, we compared between the fine-tuning approaches and the prompt-based approaches. The LoRA-tuned models outperform the prompt-based approaches in secure code generation. We found that fine-tuning with function-level and block-level datasets achieves the best secure code generation performance, compared to the alternatives (file-level and line-level).
Key facts. Cited by 8 papers in the map (data through 7 Oct 2026). First posted on arXiv 17 Aug 2024.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2024: 1; 2025: 4; 2026: 3.
8 papers.
- 2025RESCUE: Retrieval Augmented Secure Code Generationcited by 7
- 2024Seeker: Towards Exception Safety Code Generation with Intermediate Language Agents Frameworkcited by 2
- 2025Prada: Black-Box LLM Adaptation with Private Data on Resource-Constrained Devicescited by 2
- 2025Secure-Instruct: An Automated Pipeline for Synthesizing Instruction-Tuning Datasets Using LLMs for Secure Code Generationcited by 2
- 2025BabelCoder: Agentic Code Translation with Specification Alignmentcited by 1
- 2026A Study on the Impact of Fault localization Granularity for Repository-Scale Code Repair Taskscited by 1
- 2026Social Bias in LLM-Generated Code: Benchmark and Mitigationcited by 1
- 2026LIA: Supervised Fine-Tuning of Large Language Models for Automatic Issue Assignmentcited by 0
- 2026Social Bias in LLM-Generated Code: Benchmark and Mitigation1 May 2026
- 2026A Study on the Impact of Fault localization Granularity for Repository-Scale Code Repair Tasks31 Mar 2026
- 2026LIA: Supervised Fine-Tuning of Large Language Models for Automatic Issue Assignment5 Jan 2026
- 2025BabelCoder: Agentic Code Translation with Specification Alignment7 Dec 2025
- 2025RESCUE: Retrieval Augmented Secure Code Generation21 Oct 2025
- 2025Secure-Instruct: An Automated Pipeline for Synthesizing Instruction-Tuning Datasets Using LLMs for Secure Code Generation8 Oct 2025
- 2025Prada: Black-Box LLM Adaptation with Private Data on Resource-Constrained Devices19 Mar 2025
- 2024Seeker: Towards Exception Safety Code Generation with Intermediate Language Agents Framework16 Dec 2024