Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1311720pxb; Tue, 8 Feb 2022 14:23:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3mUnt6eiLTd0G6owRIkoj+fUJb+B+aj7EUyOjJ9gAlxTj/X8P3CuD0MC+IHbHW21JSvGo X-Received: by 2002:aa7:828c:: with SMTP id s12mr4013323pfm.6.1644359012379; Tue, 08 Feb 2022 14:23:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644359012; cv=none; d=google.com; s=arc-20160816; b=NF4+rgsj+5KvlNIxFxe5Je2at5P3NngCDPI6k1t1sl4XaaBaViKHp/pw3aIzgVaI9M htkxdv580hT1OSCiXhyaI9ZVfnRIXezI10YnzMpUReNB+Xq+O7MmnDs5XGcNCc1OZ/GQ jI+zQyvXg1veyxuJAghz3NSwrw8HCLawI7kyegAUvHQHB3fHaV65PBfZhCJtRvoxqeZg 2m8j0p9EEN5reniUL7nbNZu6b27STP4+lgPulAZVvZ9wjSJPz0oNZbmY28MgNXI0RiDA K9tj6K4IuRO36rz+LlMgC1TTVgJ+RVfUEDhUeTOV0LDEzdQ4qEdBBfFLQwwirlLMenel lYUA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uTrkkPZXNSY3E4omUsT1A4JtOHbK2czSaBq1DqXQeEw=; b=hbfVn5eGqGc38Ae3+PFKuiSqbQ+XfPD8oiz8M1dBk/eMqjl5Zg4psfYnusxhfNjsh/ mssJNYI9G5PeHm+nic2koj4f2as5nlD0a0Y0eiqHTtrOYc9sF8I7Z6wQf149uQb9vqpJ 92Twnqj/ZBZRO2Fjcbtr8Ml6h1oZGAQa40J/9rVEA2mtt2F4Zqlpp3v5UkhmuXdc6P+h HT4XyoIR/ZiA0iDVxduDvQeSkvsbl90sffBkyl+nyGWj88MUXAVEM9IihD7F2P5okMAm 991WKMQAoWSudNWfIhFPoPtaQa5eRt0LXnJVk7sJzMZmb+ut62BjcqoOCRRnHpJriHDp ZMMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DC+mZTHf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k184si9329397pgd.588.2022.02.08.14.23.18; Tue, 08 Feb 2022 14:23:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DC+mZTHf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389238AbiBGLry (ORCPT + 99 others); Mon, 7 Feb 2022 06:47:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386407AbiBGLef (ORCPT ); Mon, 7 Feb 2022 06:34:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71186C043188; Mon, 7 Feb 2022 03:34:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2C0DBB80EC3; Mon, 7 Feb 2022 11:34:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66E3CC340F0; Mon, 7 Feb 2022 11:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233672; bh=klD1XoqszxDtG3NN+zWwtPmHx71bBeUBfpAm8Kv5nLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DC+mZTHfHuUOVWPqwCt5AEmCMqMBqu+tS0o6Sv5dzh/XhMbCzOBQr5zZf7gtTFHrd 6tj/FIXL7zhPdbp60shnCk2KpavFi8RczGzhrEg6q1yNd2YAWEwwzwYq+6nytnZN96 UzQkunneK1g3ZdUYydABRZzmzJcfRZQ+kDzzhg8E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lu Baolu , Guoqing Jiang , Joerg Roedel Subject: [PATCH 5.16 057/126] iommu/vt-d: Fix potential memory leak in intel_setup_irq_remapping() Date: Mon, 7 Feb 2022 12:06:28 +0100 Message-Id: <20220207103806.082667303@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guoqing Jiang commit 99e675d473eb8cf2deac1376a0f840222fc1adcf upstream. After commit e3beca48a45b ("irqdomain/treewide: Keep firmware node unconditionally allocated"). For tear down scenario, fn is only freed after fail to allocate ir_domain, though it also should be freed in case dmar_enable_qi returns error. Besides free fn, irq_domain and ir_msi_domain need to be removed as well if intel_setup_irq_remapping fails to enable queued invalidation. Improve the rewinding path by add out_free_ir_domain and out_free_fwnode lables per Baolu's suggestion. Fixes: e3beca48a45b ("irqdomain/treewide: Keep firmware node unconditionally allocated") Suggested-by: Lu Baolu Signed-off-by: Guoqing Jiang Link: https://lore.kernel.org/r/20220119063640.16864-1-guoqing.jiang@linux.dev Signed-off-by: Lu Baolu Link: https://lore.kernel.org/r/20220128031002.2219155-3-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/intel/irq_remapping.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/drivers/iommu/intel/irq_remapping.c +++ b/drivers/iommu/intel/irq_remapping.c @@ -569,9 +569,8 @@ static int intel_setup_irq_remapping(str fn, &intel_ir_domain_ops, iommu); if (!iommu->ir_domain) { - irq_domain_free_fwnode(fn); pr_err("IR%d: failed to allocate irqdomain\n", iommu->seq_id); - goto out_free_bitmap; + goto out_free_fwnode; } iommu->ir_msi_domain = arch_create_remap_msi_irq_domain(iommu->ir_domain, @@ -595,7 +594,7 @@ static int intel_setup_irq_remapping(str if (dmar_enable_qi(iommu)) { pr_err("Failed to enable queued invalidation\n"); - goto out_free_bitmap; + goto out_free_ir_domain; } } @@ -619,6 +618,14 @@ static int intel_setup_irq_remapping(str return 0; +out_free_ir_domain: + if (iommu->ir_msi_domain) + irq_domain_remove(iommu->ir_msi_domain); + iommu->ir_msi_domain = NULL; + irq_domain_remove(iommu->ir_domain); + iommu->ir_domain = NULL; +out_free_fwnode: + irq_domain_free_fwnode(fn); out_free_bitmap: bitmap_free(bitmap); out_free_pages: