Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6541552ybc; Thu, 28 Nov 2019 01:00:52 -0800 (PST) X-Google-Smtp-Source: APXvYqx1GM992RaJUUUHI+VbaJJkxvLO1yMMqIwfErCp2PAVyEDhg81vr1sCbuYJKFIOqLEH+rK2 X-Received: by 2002:a17:906:f2c4:: with SMTP id gz4mr11472756ejb.39.1574931652619; Thu, 28 Nov 2019 01:00:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574931652; cv=none; d=google.com; s=arc-20160816; b=QGzV7tWo3NthBMw6f5hocD5InqlklHyuPBD0rbFB6Eu5tVWYl852VIZAELTs2SjeNj pAEv4JjCiB9B5oi6dtKkQlCYmbUJXfo7JAaLja1izcq99I5pK0Li8BDMMjluy3OitMxe 76tEWQbKEJX2RnGVvwgfN9tB66yWdjLyfT4Ji9XeFb7rIeYZPp9o/IWlFDLZGLGlsK0T 2o+171txQ+5/5hjv1+odk9uMGi9QiSlZbvU8OA65+hPQts23PQVabH3AAf13IGek7m/h 1cUVT79WIL31Uj3JK+EnLGdILLTkWsDCpIyO2rfXE0lVHLRO+EEJxOj7VJotAhf+Ar01 EfzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=SR+KTTJ3GlEow7kpfjWw52TLP8VskmK7shD9jzjrLUk=; b=gE4MrD4OeZk2dWQODCWdMP44EYslNNpJUhM3MAj0atkqvuus9So4tMbGAsS5anbWht 9HfnFohRgNwuu4y0ByXfngf/pVrJbBNw6qotrJ556FATs+1csX6HtgbnJSutDiUewOUr 3mU3I57QGgGUdepaq8wn8k+n7El3U+mf6WMUbqQ6pAwr9FqcPOapx4Z4YR1blq38AVLM xKQpyyLTK3HQyexBD4TQuuqcuGR3rTLNDetl6MpvC61AxP4i09ZL/twVnOScUO55BWk4 Lk2BKbIlD1Jum+6NsQcQ21WzijPSHtrWJNSQQP8Yab3et47+dk6fUCDpO6P5HYBd5daK pxdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dBa/zkhW"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h26si12966040ede.359.2019.11.28.01.00.27; Thu, 28 Nov 2019 01:00:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dBa/zkhW"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727597AbfK1ItP (ORCPT + 99 others); Thu, 28 Nov 2019 03:49:15 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:35533 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726301AbfK1ItP (ORCPT ); Thu, 28 Nov 2019 03:49:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574930954; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SR+KTTJ3GlEow7kpfjWw52TLP8VskmK7shD9jzjrLUk=; b=dBa/zkhW7Ton+JH9ifZI2LO4hpMx5hP8fcEMRNZqPygU15vxRG7FozHVpi2/wSVMm9vlZb GCl92h8vjxzhoFtaIJVVrMx8VKLfHbhmKZNTVu6U6xySU577EPfV9RfDXSzj6sXma+X5nl YuG1cxHIHsXPqY2bN4b3tMNfpLxskEs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-391-k1I8B9FENh-njGBz-WF6VQ-1; Thu, 28 Nov 2019 03:49:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 82A62107ACE3; Thu, 28 Nov 2019 08:49:10 +0000 (UTC) Received: from [10.36.116.37] (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB6AD60C80; Thu, 28 Nov 2019 08:49:03 +0000 (UTC) Subject: Re: [PATCH] KVM: vgic: Fix potential double free dist->spis in __kvm_vgic_destroy() To: linmiaohe , maz@kernel.org, pbonzini@redhat.com, rkrcmar@redhat.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, christoffer.dall@arm.com, catalin.marinas@arm.com, gregkh@linuxfoundation.org, will@kernel.org, andre.przywara@arm.com, tglx@linutronix.de Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org References: <1574923128-19956-1-git-send-email-linmiaohe@huawei.com> From: Auger Eric Message-ID: <115fbbb3-73d5-444a-0aec-61bca0dea435@redhat.com> Date: Thu, 28 Nov 2019 09:49:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1574923128-19956-1-git-send-email-linmiaohe@huawei.com> Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: k1I8B9FENh-njGBz-WF6VQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 11/28/19 7:38 AM, linmiaohe wrote: > From: Miaohe Lin > > 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 Reviewed-by: Eric Auger Thanks Eric > --- > 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 53e3969dfb52..c17c29beeb72 100644 > --- a/virt/kvm/arm/vgic/vgic-init.c > +++ b/virt/kvm/arm/vgic/vgic-init.c > @@ -171,6 +171,7 @@ static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis) > break; > default: > kfree(dist->spis); > + dist->spis = NULL; > return -EINVAL; > } > } >