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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29840EB64D7 for ; Mon, 26 Jun 2023 18:23:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231785AbjFZSXD (ORCPT ); Mon, 26 Jun 2023 14:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231733AbjFZSXB (ORCPT ); Mon, 26 Jun 2023 14:23:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC1D819A5 for ; Mon, 26 Jun 2023 11:22:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 105EE60F6F for ; Mon, 26 Jun 2023 18:21:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16800C433C9; Mon, 26 Jun 2023 18:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687803702; bh=qJnEFAY/vVPuLcjvZ1NZQT2IYN/SI9qiXmPm0kMiciM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UqTsz+6VKhqABGKZmCXOXqqD+HGrYOkwru0qwiYskaEfdP+PkOitwEHWh23wRHwqv gGA53BZnquMPuKcIGuIpOQ5oDn4s1zV7lf3R64k66e1pqO3r0sM4BjWIegywB64qnI kjscXycLKWuSfJaxSbpYLbxFZ11pmPZ0e5VXjo6U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Su Hui , Jason Gunthorpe , Jerry Snitselaar , Vasant Hegde , Joerg Roedel , Sasha Levin Subject: [PATCH 6.3 148/199] iommu/amd: Fix possible memory leak of domain Date: Mon, 26 Jun 2023 20:10:54 +0200 Message-ID: <20230626180812.121825464@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230626180805.643662628@linuxfoundation.org> References: <20230626180805.643662628@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Su Hui [ Upstream commit 5b00369fcf6d1ff9050b94800dc596925ff3623f ] Move allocation code down to avoid memory leak. Fixes: 29f54745f245 ("iommu/amd: Add missing domain type checks") Signed-off-by: Su Hui Reviewed-by: Jason Gunthorpe Reviewed-by: Jerry Snitselaar Reviewed-by: Vasant Hegde Link: https://lore.kernel.org/r/20230608021933.856045-1-suhui@nfschina.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd/iommu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index cd0e3fb78c3ff..e9eac86cddbd2 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2069,10 +2069,6 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) int mode = DEFAULT_PGTABLE_LEVEL; int ret; - domain = kzalloc(sizeof(*domain), GFP_KERNEL); - if (!domain) - return NULL; - /* * Force IOMMU v1 page table when iommu=pt and * when allocating domain for pass-through devices. @@ -2088,6 +2084,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type) return NULL; } + domain = kzalloc(sizeof(*domain), GFP_KERNEL); + if (!domain) + return NULL; + switch (pgtable) { case AMD_IOMMU_V1: ret = protection_domain_init_v1(domain, mode); -- 2.39.2