From mboxrd@z Thu Jan 1 00:00:00 1970 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=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 2553AC43464 for ; Fri, 18 Sep 2020 02:42:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DE96923444 for ; Fri, 18 Sep 2020 02:42:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600396975; bh=WMh+hFHx8/PpyJtt7K6aRDlS51HQqOpRAn+4f0iPX2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=HfQhJNMUt4y9n/eWuQWKQm9t6f+F43Rv+e5p54E6ZboxFEV6zEQscYDXrqIlhBb1L O2IRV5fP+zvWB83Rc4YsGF6lUiDrM47BWkyY8zsH0QkkmRzoae5VPjMSBKIOHfXLeG RK112J0mbwhvimX3QD0Hzz0u9/PtZYjVaNAVNp4s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730090AbgIRCmx (ORCPT ); Thu, 17 Sep 2020 22:42:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:36240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728557AbgIRCLD (ORCPT ); Thu, 17 Sep 2020 22:11:03 -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 79ADD208DB; Fri, 18 Sep 2020 02:11:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600395062; bh=WMh+hFHx8/PpyJtt7K6aRDlS51HQqOpRAn+4f0iPX2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=skUpET9Jd+5f14rv7rsw+L5uH7lNKH6P/qERaL8yrqpvvDlzRSRaWUKDZI2Tg4gbD 3YlnUZPSz4OASIEqL6wuZRkZPkmFkkKIIJNtmzTxBQ9HNKpCA/JCwYhjgqx4nckTv5 9UEkeujqpJH3p00J+MEsBgHk3Duu+WaWjCWv1lpI= 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 4.19 148/206] KVM: arm64: vgic-its: Fix memory leak on the error path of vgic_add_lpi() Date: Thu, 17 Sep 2020 22:07:04 -0400 Message-Id: <20200918020802.2065198-148-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020802.2065198-1-sashal@kernel.org> References: <20200918020802.2065198-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 9295addea7ecf..f139b1c62ca38 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -107,14 +107,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