]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
KVM: arm/arm64: vgic: Fix potential double free dist->spis in __kvm_vgic_destroy()
authorMiaohe Lin <linmiaohe@huawei.com>
Thu, 28 Nov 2019 06:38:48 +0000 (14:38 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Mon, 9 Nov 2020 13:47:25 +0000 (14:47 +0100)
BugLink: https://bugs.launchpad.net/bugs/1900624
[ Upstream commit 0bda9498dd45280e334bfe88b815ebf519602cc3 ]

In kvm_vgic_dist_init() called from kvm_vgic_map_resources(), if
dist->vgic_model is invalid, dist->spis will be freed without set
dist->spis = NULL. And in vgicv2 resources clean up path,
__kvm_vgic_destroy() will be called to free allocated resources.
And dist->spis will be freed again in clean up chain because we
forget to set dist->spis = NULL in kvm_vgic_dist_init() failed
path. So double free would happen.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Link: https://lore.kernel.org/r/1574923128-19956-1-git-send-email-linmiaohe@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Ian May <ian.may@canonical.com>
virt/kvm/arm/vgic/vgic-init.c

index 6f50c429196de19c4be0e359172632666181951d..6d85c6d894c3947600fb6cfb4e0c662efc5108d5 100644 (file)
@@ -177,6 +177,7 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis)
                        break;
                default:
                        kfree(dist->spis);
+                       dist->spis = NULL;
                        return -EINVAL;
                }
        }