Message ID | 20230606070742.139575-1-suhui@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3203497vqr; Tue, 6 Jun 2023 00:18:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4K8M7GcgepMUNu3VKWvfem/0jxtkdGNWh//m55/DkGh1P2HeU7RUOHGEojw8/tsKITdQcB X-Received: by 2002:aa7:8881:0:b0:655:7ebd:bf31 with SMTP id z1-20020aa78881000000b006557ebdbf31mr711376pfe.8.1686035896841; Tue, 06 Jun 2023 00:18:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686035896; cv=none; d=google.com; s=arc-20160816; b=HRQj2ZqOmCvIHQkLxz6TaydHfLfDBqALvKAOlWqKO1+SkQxIEAkxDIqhVunhfSw3xw hBJe3yK9IF2Cj+viPXCs4eJUCBL15EqwzBaVJ+IBASBmKdNbBu2qSgkofYGUHVQBYsHq bmHo3F4anApoPpoyRQKImioATKWYBueuOzlXKr3WiQKoav/h00TQOF9Yp3clFZRQTyeF XVUs6GImoJw7UMXaLXm2Vv9ES5EGHSEXHH9C+RjwDdrh5i/E+w+dhxk1ZXdBlUEhCY9K C57b9Ad9X+uvDF3IsC5CKtysldRb8oomym+MR9DAtThnw2HjluvRCmCIf5HJZ2eGhHBm lrFA== 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 :message-id:date:subject:cc:to:from; bh=2QZSDDZacFGv2IkhrKnByvn0X+f13YNbBf6qCoI3NJY=; b=pbbaUVSSsWbUbbdEDC5FKKGcB3/eqJF8pwmYil+TiHfIUrkj79JRo34gZsGvICUwer t6YofgEaskUl2/ex7kItsHZ5UNvdzuc0yc1eOG2w84Q22ha42sIdNnZzKqG+wtVWk1Xd /hofGpjw6UWL0gzwzePidKiaRn/dkh2xHNrTPESGP1LR5w4Vq3vNqjCrBRwa9eQDaLrg e9GmNlXixLLfTr4ZHeF8Az6RI1J4FIL4RgSZyQ9PZMZAsMlR+OkAGtMLSj1x35GDjyKL Lb4chW5+tAUfkDOFKkTmYH1Q2TLd19uRx64WKmU/KREMGbUXmnCg+CYlQ8pFqL+iV0oG qsDQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a634542000000b005250c235984si7161931pgk.860.2023.06.06.00.18.04; Tue, 06 Jun 2023 00:18:16 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235868AbjFFHI6 (ORCPT <rfc822;xxoosimple@gmail.com> + 99 others); Tue, 6 Jun 2023 03:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235850AbjFFHIz (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 6 Jun 2023 03:08:55 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 87246118 for <linux-kernel@vger.kernel.org>; Tue, 6 Jun 2023 00:08:53 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 24052180120BD8; Tue, 6 Jun 2023 15:07:45 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui <suhui@nfschina.com> To: Joerg Roedel <joro@8bytes.org>, Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>, Will Deacon <will@kernel.org>, Robin Murphy <robin.murphy@arm.com> Cc: jgg@ziepe.ca, kevin.tian@intel.com, vasant.hegde@amd.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Su Hui <suhui@nfschina.com> Subject: [PATCH] iommu/amd: Fix possible memory leak of 'domain' Date: Tue, 6 Jun 2023 15:07:42 +0800 Message-Id: <20230606070742.139575-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767936776376076140?= X-GMAIL-MSGID: =?utf-8?q?1767936776376076140?= |
Series |
iommu/amd: Fix possible memory leak of 'domain'
|
|
Commit Message
Su Hui
June 6, 2023, 7:07 a.m. UTC
free memory of domain before return NULL.
Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
drivers/iommu/amd/iommu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 6/6/2023 12:37 PM, Su Hui wrote: > free memory of domain before return NULL. > > Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks") > Signed-off-by: Su Hui <suhui@nfschina.com> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> -Vasant > --- > drivers/iommu/amd/iommu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > index dc1ec6849775..f08e65629c74 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -2094,7 +2094,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) > } else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) { > pgtable = amd_iommu_pgtable; > } else { > - return NULL; > + goto out_err; > } > > switch (pgtable) {
On Tue, Jun 06, 2023 at 03:07:42PM +0800, Su Hui wrote: > free memory of domain before return NULL. > > Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks") > Signed-off-by: Su Hui <suhui@nfschina.com> > --- > drivers/iommu/amd/iommu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c > index dc1ec6849775..f08e65629c74 100644 > --- a/drivers/iommu/amd/iommu.c > +++ b/drivers/iommu/amd/iommu.c > @@ -2094,7 +2094,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) > } else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) { > pgtable = amd_iommu_pgtable; > } else { > - return NULL; > + goto out_err; > } It might be nicer to order to allocation after the type checks, it is more consistent with the other drivers This is fine too Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Thanks, Jason
Jason, On 6/7/2023 7:52 PM, Jason Gunthorpe wrote: > On Tue, Jun 06, 2023 at 03:07:42PM +0800, Su Hui wrote: >> free memory of domain before return NULL. >> >> Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks") >> Signed-off-by: Su Hui <suhui@nfschina.com> >> --- >> drivers/iommu/amd/iommu.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c >> index dc1ec6849775..f08e65629c74 100644 >> --- a/drivers/iommu/amd/iommu.c >> +++ b/drivers/iommu/amd/iommu.c >> @@ -2094,7 +2094,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) >> } else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) { >> pgtable = amd_iommu_pgtable; >> } else { >> - return NULL; >> + goto out_err; >> } > > It might be nicer to order to allocation after the type checks, it is > more consistent with the other drivers > > This is fine too Right. We are working on cleaning up/re-arranging this code path. Hopefully I will have patches soon. -Vasant
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index dc1ec6849775..f08e65629c74 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2094,7 +2094,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) } else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) { pgtable = amd_iommu_pgtable; } else { - return NULL; + goto out_err; } switch (pgtable) {