Executive brief
The Linux kernel's LoongArch KVM module has a resource leak bug where allocated memory and per-CPU resources are not properly freed if the module initialization fails. This can cause kernel memory to be permanently lost if KVM setup encounters an error, potentially leading to memory exhaustion over repeated failed initialization attempts.
Technical details
This is a resource leak (CWE-401) in the LoongArch KVM module initialization code. The function kvm_loongarch_init() calls kvm_loongarch_env_init() to allocate per-CPU kvm_context structures (VMCS) and register performance callbacks, then calls kvm_init(). If kvm_init() fails, the error is returned directly without calling kvm_loongarch_env_exit() to clean up allocated resources. Since module_init() does not automatically invoke module_exit() on failure, these resources are permanently leaked. The fix adds a check after kvm_init() to call kvm_loongarch_env_exit() on failure, matching the pattern used in RISC-V KVM. This only affects systems running LoongArch with the KVM module and encountering initialization failures.
Affected products
- Linux Linux kernel LoongArch KVM module
Timeline
- 2026-09-16: disclosed: Published in NVD