diff options
| author | Fuad Tabba <fuad.tabba@linux.dev> | 2026-08-07 11:41:00 +0100 |
|---|---|---|
| committer | Oliver Upton <oupton@kernel.org> | 2026-08-07 09:06:27 -0700 |
| commit | 52d044d6e76fcd48ee384f0628a39d56b04de95b (patch) | |
| tree | 4b23f5b5836c8374a4c467dc57d3ba16734f748f | |
| parent | c6c156d931c33b92362383cf76f6d6e1291dcbfe (diff) | |
| download | linux-52d044d6e76fcd48ee384f0628a39d56b04de95b.tar.gz linux-52d044d6e76fcd48ee384f0628a39d56b04de95b.zip | |
KVM: arm64: vgic: Don't leak the SPI array when init is retried
Nothing latches a failed vgic_init(), so userspace can retry
KVM_DEV_ARM_VGIC_CTRL_INIT after a failure past kvm_vgic_dist_init().
kvm_vgic_setup_default_irq_routing() is the reachable case, running on
every configuration. Each retry overwrites dist->spis and only the last
allocation is freed at teardown, leaking up to 960 struct vgic_irq,
about 90KB, per attempt.
Return early when the array is already allocated, as
vgic_allocate_private_irqs_locked() and vgic_v4_init() do.
Fixes: ad275b8bb1e65 ("KVM: arm/arm64: vgic-new: vgic_init: implement vgic_init")
Signed-off-by: Fuad Tabba <fuad.tabba@linux.dev>
Link: https://patch.msgid.link/20260807104102.2410744-3-fuad.tabba@linux.dev
Signed-off-by: Oliver Upton <oupton@kernel.org>
| -rw-r--r-- | arch/arm64/kvm/vgic/vgic-init.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c index 907057881b26..d4cf143f3ae6 100644 --- a/arch/arm64/kvm/vgic/vgic-init.c +++ b/arch/arm64/kvm/vgic/vgic-init.c @@ -210,6 +210,9 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis) struct kvm_vcpu *vcpu0 = kvm_get_vcpu(kvm, 0); int i; + if (dist->spis) + return 0; + dist->active_spis = (atomic_t)ATOMIC_INIT(0); dist->spis = kzalloc_objs(struct vgic_irq, nr_spis, GFP_KERNEL_ACCOUNT); if (!dist->spis) |
