Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp882234pxk; Thu, 17 Sep 2020 20:14:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzfv9nEPqYfy4u7BBhZNdy01pC8lV0R6fQX0r54uCJUVkDLu4cTaqb6bd9RFPlkYhCTFPe X-Received: by 2002:a50:fd19:: with SMTP id i25mr36687564eds.142.1600398851138; Thu, 17 Sep 2020 20:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398851; cv=none; d=google.com; s=arc-20160816; b=rImO8xuoZ2WSDtf28SwKfd6X9F4oYZnsfeUkr1iFgtm0g8yuaAwRZ3pdhUb7mr08Cf rtVTXXyDEpYJgltPCRhG3BYF1PvGhlZCFtkJ+AOw2peb3DdO2S5+Xc3PA9+HBgtmpHKL vXMq3pmNm38VpO8t6PuPFHBjKvq3ngfAB7NnDj+dq2XLW2GeRdcfMmJPlyVNMhuMznxU RkR2utyL9ilUmzXOzxZfGRNA/57J7E7qbeStaU2vDVIffa/FZPiuJlk7zFBoGbYNNwJT wpwU3EQP3HRs3jQd4DXrc1rrZERHnKT9Zz2NAFbHc280cY2evidkaeXX6x99kG12bg1a wAOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ubB71eBVS/qxVvaG3azSHgr717d7XvHSemj0ib37NqY=; b=Skdj4ejPNWfGk6MK84cNCXfGlKRIe5JT2OVdViAFdNVwxVAF3ACtAysfn8HciJsVpo A2YrkZg+psHE9OgoCrOGoIIh21h+Jqyuo1QAyQgY9nSP+JQcX4BvdQLzW0iyT5QZZ5ZK /g598IJujL+1gKoRl3qc8weqGx3Tc2qgdO/VwNMDmjENEwaH2HvLMhvRkkVKZeMJywAG Sn2BussqwG7fRwsPrb+a0fcMEf66o2PdokDZRdcUxQwDUgCfPoeQywAvUdQ9Ix2f3q5v kpS8l2TQsuBVkoPq/ObV8TRSIpCiiTps819Ye0ZoYYc/68YZORFXStpp/RcPkGOB1+ZH 6RPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OZ+KVvmK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l25si1193228eje.688.2020.09.17.20.13.48; Thu, 17 Sep 2020 20:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OZ+KVvmK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726913AbgIRCC6 (ORCPT + 99 others); Thu, 17 Sep 2020 22:02:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:48120 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726824AbgIRCCl (ORCPT ); Thu, 17 Sep 2020 22:02:41 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 70E8923447; Fri, 18 Sep 2020 02:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394561; bh=aq1/5r2rp+WYg/sjQ6/chbTXBc+6EZ0FkQdPv+m7yps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OZ+KVvmKA9ceJqYM3lDLF1jhOSD9voeQJAwn8805WOZ0GekFdFOxRrFfBfRaD5SLA ODN1lm+RwtxoEGhoTKtVHUsTGpkwlB4W2JfngPF1lt/+PG2JkkcFhXtl9vYRGYhB8A /RpqbTTRTvJ1hSmKJjMswzff+oYhKAII5noa/X4A= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Miaohe Lin , Marc Zyngier , Eric Auger , Sasha Levin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 074/330] KVM: arm/arm64: vgic: Fix potential double free dist->spis in __kvm_vgic_destroy() Date: Thu, 17 Sep 2020 21:56:54 -0400 Message-Id: <20200918020110.2063155-74-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 6f50c429196de..6d85c6d894c39 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -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; } } -- 2.25.1