Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp874831pxk; Thu, 17 Sep 2020 20:00:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+CnvSkf3bZ2+9nk3TOEdIS8TfZWdP2qrUC90HpiAW0tvUOqgIXBiWRHqFZUi1Yo75K9rr X-Received: by 2002:a17:906:4685:: with SMTP id a5mr34052210ejr.446.1600398002485; Thu, 17 Sep 2020 20:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398002; cv=none; d=google.com; s=arc-20160816; b=bJrgYrv7jif8K1N6DDe594I/Q4EdWOwbpDJu2GEZS4PvELPZnha1BpVzCn+I+iKAur 6q5kuXujlTMypo/Aj4k//AdwXJAMSCPYCjCD/cFAR67xmwl86jWbBDFHLRDVZq/lE2Q4 09BCIy6uHoQsX4N66w8yss73nquozcEksOC943nbzW7jsO8ZoKOUEvvhZMOMErtQ+FIN 9Xj1apjxL9wWrYv7w3+um3r8FjH0RXAECF6X0VkxtXIvPCj/N1dxIcA7NtDVbk7+uWLK PeYE31sTO5WyVsyKnNMck7dIXBLWMfRFBdThG4v1e7pMbgto4wWkwa/xAg2fqlcMuBwb B/dg== 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=I0MIzaQ7mWPJ3i+aMUj9i0dEb8+5WcVkXphPVhf+zlY=; b=shwYBJYCvrYnSFYIL4lEhURzFLCXz4KdZvJ5GUJrP5tm5E80KdMNelfUsYeGY3yffh 4EI6810D9XAjeDHQYE3hxli6TxMBhznjnPLQqokTA9MQdF9ZScFQu6JjNMEEJ9yJ1GFw eJ/yv4aN8Q01sLrHBzVvrVWPv6k9be4kvlpkMsJGNToYE6Qew/Qm6R9/YEXPt9lhRDkd xWaDiPjDz4kBPj7Ag8YW7zY5c3uKx5vvBoFBAtdPhTGAfGdL6H1VgcbJKlEYozrHssgA AtwpJnlR1wfGLFFyQpBi5re1AWK04xJIz0fn8jV4qTSRcJxkbXgBTRz3e6F5dguDHgOk 1XgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ukuuDLl6; 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 d17si1081035edp.500.2020.09.17.19.59.39; Thu, 17 Sep 2020 20:00:02 -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=ukuuDLl6; 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 S1727764AbgIRCGb (ORCPT + 99 others); Thu, 17 Sep 2020 22:06:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:55220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726981AbgIRCGI (ORCPT ); Thu, 17 Sep 2020 22:06:08 -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 69E5823718; Fri, 18 Sep 2020 02:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394768; bh=6/6a8jeCD9rXFbBxNlrS6wkqXNU4bmx5jaM2whCPLAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ukuuDLl6tb65pSfXuGB0FV7nAPeDJ7nA6QbIbO3Xdcx4WxZd3wjHK89lP8JwMb3vg LDgKP1umuvGFgngZSWjh+zdlGBiT+yYsDxjza2bPXsPjhK+5JJiX/vqG9E/8zl7CuZ Ysmh7QaR5CTHZSbJ4KDqKwSmklt0Jd5CQB9oowdk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zenghui Yu , Marc Zyngier , Sasha Levin , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 243/330] KVM: arm64: vgic-its: Fix memory leak on the error path of vgic_add_lpi() Date: Thu, 17 Sep 2020 21:59:43 -0400 Message-Id: <20200918020110.2063155-243-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: Zenghui Yu [ Upstream commit 57bdb436ce869a45881d8aa4bc5dac8e072dd2b6 ] If we're going to fail out the vgic_add_lpi(), let's make sure the allocated vgic_irq memory is also freed. Though it seems that both cases are unlikely to fail. Signed-off-by: Zenghui Yu Signed-off-by: Marc Zyngier Link: https://lore.kernel.org/r/20200414030349.625-3-yuzenghui@huawei.com Signed-off-by: Sasha Levin --- virt/kvm/arm/vgic/vgic-its.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index f8ad7096555d7..35be0e2a46393 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -96,14 +96,21 @@ out_unlock: * We "cache" the configuration table entries in our struct vgic_irq's. * However we only have those structs for mapped IRQs, so we read in * the respective config data from memory here upon mapping the LPI. + * + * Should any of these fail, behave as if we couldn't create the LPI + * by dropping the refcount and returning the error. */ ret = update_lpi_config(kvm, irq, NULL, false); - if (ret) + if (ret) { + vgic_put_irq(kvm, irq); return ERR_PTR(ret); + } ret = vgic_v3_lpi_sync_pending_status(kvm, irq); - if (ret) + if (ret) { + vgic_put_irq(kvm, irq); return ERR_PTR(ret); + } return irq; } -- 2.25.1