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=-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=unavailable 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 513FBC4727C for ; Tue, 29 Sep 2020 12:02:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A48B2074F for ; Tue, 29 Sep 2020 12:02:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601380924; bh=6/6a8jeCD9rXFbBxNlrS6wkqXNU4bmx5jaM2whCPLAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=l+aWykLcARC01DchqToiQoq5u7/rJTS3l7OlDjjg1XwFTwyabI8yRZqvg6YRKu6HY pLXMnqJU0CHgjbRJ7HqihT0+vv1kra7z6uI5qfbBUR4yNSCpR0ZSSl8ba2a3G9mwwB mUzavlURpJvgvKK1Dej6WpEFPcKFURYOdQGgv/ms= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731751AbgI2MCC (ORCPT ); Tue, 29 Sep 2020 08:02:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:35352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729233AbgI2LkE (ORCPT ); Tue, 29 Sep 2020 07:40:04 -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 B42062074A; Tue, 29 Sep 2020 11:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601379604; bh=6/6a8jeCD9rXFbBxNlrS6wkqXNU4bmx5jaM2whCPLAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0E5vKclYlmk/eP3OjoOiFdsYWJoLuokpC/MCCd0SBZvFFTqrlfejpdZccxEdZmtmr jLy+ELIKdkAbnwp9O7XoHCMy1apa5548GtZJczSa/JZqmEvdpMCum7ZtRHJvJEbreC gbuBqMv9vykfx3NeSmZsgKPxcuxt5eehL56HMBZk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zenghui Yu , Marc Zyngier , Sasha Levin Subject: [PATCH 5.4 237/388] KVM: arm64: vgic-its: Fix memory leak on the error path of vgic_add_lpi() Date: Tue, 29 Sep 2020 12:59:28 +0200 Message-Id: <20200929110021.952662032@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929110010.467764689@linuxfoundation.org> References: <20200929110010.467764689@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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