Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1749182pxb; Wed, 9 Feb 2022 03:47:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8l2XVnVDS6z4Ua38nMDgFkqe6JEeZJKsEw/a5qtDn0JlWE9xDIAC0dLxGdDbDyz+QNm1s X-Received: by 2002:a17:902:bd81:: with SMTP id q1mr2022411pls.100.1644407269309; Wed, 09 Feb 2022 03:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644407269; cv=none; d=google.com; s=arc-20160816; b=FzQQl5SkdX7ioFVeYyB/MQh2/FtWoPS33l3cgUtM32YIB2yFQgyetw7xwNTmFkdUlb JGo/Vi2fQVsYMco+fnmiIA2dOB8kmF6CtOM7af7q9JMSPUMXUmYZLkck15naE9t3aFrN zZumfn/hvZqnjOYjj8puk1BdDlA6vtdi4wZbML9n1xMP0vniGv5teKN7IdItgzZW+4mR 9DorMhHgW/obch5sbA94w2BnMTENHeaQdrzGj4HsO+/ly+mvUOxxboXCdREroNqDFAzo 9hkOuXfIl3rP/uNqsBoszOOZelFdNORbz2qsjZ/yn2DDlKaD2HKOE0jAhMPV2B9TbnrC yx4A== 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=yIf4JRkx5JpktdvhDghNiozlrys5+6o6eX1jrnLaXxUgNKCgGrmoJD4xiVLvVlyQZT Qwji144DaiKTRnkU14wkNvoidCZr4uNlhDYml0T0XOHKKVbtIXv5rL6kH+hih5v/2N5g SrXij2q6jQQ8//fHmIYrYen/QwjJxcr/qlXQhrAtvC6TGCagcB4uKNAb1U4aQoAXdKEo Bg3vUGCaSGcToRhbiLQY2ec7bfJAviqAKEO71xXHTHaiKzXcFiAZB8hgzqgAO3vD8ggR SCVDbAW2yQAzzKs7crDxWLEiin8UM6D/SNyAhIvZ7v6CsrLUcKsOmD9nC6F4z2Geuk9B Sh3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lybLKwty; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bj11si3426973pgb.272.2022.02.09.03.47.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:47:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lybLKwty; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 382E3E0E0884; Wed, 9 Feb 2022 01:58:49 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389713AbiBGLuw (ORCPT + 99 others); Mon, 7 Feb 2022 06:50:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384994AbiBGLa4 (ORCPT ); Mon, 7 Feb 2022 06:30:56 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A4E5C03BFE6; Mon, 7 Feb 2022 03:28:55 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 13F956077B; Mon, 7 Feb 2022 11:28:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7565C004E1; Mon, 7 Feb 2022 11:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233334; bh=klD1XoqszxDtG3NN+zWwtPmHx71bBeUBfpAm8Kv5nLk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lybLKwtyl9XtKEEOkA2ZCNKwlmgrz/ocUtJZl0rKFeh9lVownQZEa2YEi9YUh6kmM 8blzDMj1vA9jJ3l6b31S0dVahGROn3yew2gRsJa1APON39wdrvM3KvRGMYbtOiDAYR t5S3o1G9Vcp/o0VJw1lEgOanY93FnQKHJRAqJFGQ= 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.15 048/110] iommu/vt-d: Fix potential memory leak in intel_setup_irq_remapping() Date: Mon, 7 Feb 2022 12:06:21 +0100 Message-Id: <20220207103803.908885340@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103802.280120990@linuxfoundation.org> References: <20220207103802.280120990@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: