From patchwork Tue Sep 29 10:58:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 291161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14263C4741F for ; Tue, 29 Sep 2020 11:30:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D413E23D6A for ; Tue, 29 Sep 2020 11:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379020; bh=qYTEDikd5AeadaqGi0riE4D6tb93wc+GLf8ds0bRU20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=N/N0F1Hwe81rK9UgYC953Ehf1oMUy1dL/PZS1u5wybv0HH/FRE9jr+bZsqHs3THhR p9pum6Boxm8XN8VH1Q9V35l4QZROg1PP66us4tw+k1sSx7Oqk16/XpW6S7mN5ijzZT wHfVAfiG57TGsZCkz5cEoXhXGrb7q14FME7+xK7A= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728610AbgI2LaC (ORCPT ); Tue, 29 Sep 2020 07:30:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:39528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729361AbgI2L3J (ORCPT ); Tue, 29 Sep 2020 07:29:09 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7470321D7F; Tue, 29 Sep 2020 11:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378608; bh=qYTEDikd5AeadaqGi0riE4D6tb93wc+GLf8ds0bRU20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UA9+5s1zp8mCrGyrdF0Q43nS/J+3oz5FLI5sSGSB9okBLbj52b94hFdNPQ01dTbFA FgR+QD3EGQYGIngs0eb0Z4xWP7nHJyB5SuluwVbq8aIPVY+p/3QnwIq0FsIEhq/p0x NnFxIfDImPaZpQ7Q+sgZZpHwX2KM6zBrpoVQ2iMI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Marc Zyngier , Eric Auger , Sasha Levin Subject: [PATCH 4.19 045/245] KVM: arm/arm64: vgic: Fix potential double free dist->spis in __kvm_vgic_destroy() Date: Tue, 29 Sep 2020 12:58:16 +0200 Message-Id: <20200929105949.196386219@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105946.978650816@linuxfoundation.org> References: <20200929105946.978650816@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Miaohe Lin [ 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 Signed-off-by: Marc Zyngier Reviewed-by: Eric Auger Link: https://lore.kernel.org/r/1574923128-19956-1-git-send-email-linmiaohe@huawei.com Signed-off-by: Sasha Levin --- virt/kvm/arm/vgic/vgic-init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index cd75df25fe140..2fc1777da50d2 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -187,6 +187,7 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis) break; default: kfree(dist->spis); + dist->spis = NULL; return -EINVAL; } }