Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1144991pxv; Fri, 9 Jul 2021 19:26:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyn9MaLdJDZqJKjeCwQTqxyLlXDU5NkEWY4Cx9NV5bLAXGeMVKuueURqnsbd6qtymaJySZT X-Received: by 2002:a17:906:1156:: with SMTP id i22mr13961555eja.167.1625883989649; Fri, 09 Jul 2021 19:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883989; cv=none; d=google.com; s=arc-20160816; b=d7hitATaoJcPzEZ6dyzU6BIbvPbBTYFoaBkgz0HAYsL9wwTnRyynuJBrmfV/WgZxR9 Syw25yDyswhOKdsdn2DJUlHKU90H/Qy91l6vnafYfWzTcBWUbi0cE68B2HS28Jj70iOt eib0JDWZtWI+6yfktoGQIqndm74qHUnpyl+Sk3+Vt7StEKOKflL97iPBoYrV8a1m/TEL kZEVLga8DxEE8QVT8bEY3yWh1Z6rqBGaxVQzph40KRTDwoC51rv8QLIZJY0XNsuN7432 hVJOuuUEenkwZ+VMDmtWWyVEj+ivHTOimg8OxykWyBXEmGSw+B8zCH/ntFqgZwTasfTJ ZFfw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xjD20y9lwUV3R2/a7kgaD6eOGAtjzZl/NLQ+lb/PwQA=; b=S+c9CcM91z3VstV6B28UKl0JN9DTOP0PkMSPSgxhq0wQd8KVNE1C/C8pT89cikENs8 Zq2DXr6aBz9E1ub7KPX+YP0lsZXyIHewJCfh4dHxXY73SUKG1ZEKoPJgux59YMZjT7hj n+vF7Q2VEiaMXtBIydtw58J0l8xjYTcmNwdgSnWiVa/BF3EQxecHXZR4sal52zyIrTj3 mogYu4i26LjmjkJAbqzYuCttSsEqbLNE4MfWMXW/vQ+6A1ps1ALcg6fmZf4OzRX9CRlT rk+s12F7yA9iXayw4LxPKx2AXKh/a37ZYZRg17E+7uTGZP5rPTwUoD6Bs/pcZ5IKDRzD /Dow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uWFmyQie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z17si8996453edq.547.2021.07.09.19.26.07; Fri, 09 Jul 2021 19:26:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uWFmyQie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233414AbhGJC1Q (ORCPT + 99 others); Fri, 9 Jul 2021 22:27:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:42072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233207AbhGJC0G (ORCPT ); Fri, 9 Jul 2021 22:26:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 24168613D9; Sat, 10 Jul 2021 02:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883797; bh=zStzLJS4xcITcBHd4Vg7AE4hq9AFPaBO0/AS7BNFqB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uWFmyQie1PENUBQ3jUbICQ4Y2lQO7Ibn8JHhXBA4giCvdWNRdp2LcDK/tBMG+wTyE o/VmRocOTtx7v/ogRd22jG5AqR+SSm8L6J+ZJ0xpM277lWKrlnBjAKksw0axBU0yiA i1Fm3EEGFdc8/E9PfuU/+gAPSmQoH8Htsqh14PPxEgTahkuKhxTDP5fjEeNTTKj0cZ VFVfS03hg2xHmHaujdTS23Mgk2XE5AOwaJ9eYnlXvwuPAAnohlgljhJYJfY7awMMi9 7B9cmVI71bPeJcbi1DJbkfvtaLjiTBn1bDs6trhFQaXo+MwWm/f6jrxmcCRiy7iVgt d7OWOp1qzV0dA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiyu Yang , Xin Tan , Rob Clark , Will Deacon , Sasha Levin , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 5.12 061/104] iommu/arm-smmu: Fix arm_smmu_device refcount leak in address translation Date: Fri, 9 Jul 2021 22:21:13 -0400 Message-Id: <20210710022156.3168825-61-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiyu Yang [ Upstream commit 7c8f176d6a3fa18aa0f8875da6f7c672ed2a8554 ] The reference counting issue happens in several exception handling paths of arm_smmu_iova_to_phys_hard(). When those error scenarios occur, the function forgets to decrease the refcount of "smmu" increased by arm_smmu_rpm_get(), causing a refcount leak. Fix this issue by jumping to "out" label when those error scenarios occur. Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Reviewed-by: Rob Clark Link: https://lore.kernel.org/r/1623293391-17261-1-git-send-email-xiyuyang19@fudan.edu.cn Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/arm/arm-smmu/arm-smmu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c index 128c2c87b4e5..c6ff32797a23 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1268,6 +1268,7 @@ static phys_addr_t arm_smmu_iova_to_phys_hard(struct iommu_domain *domain, u64 phys; unsigned long va, flags; int ret, idx = cfg->cbndx; + phys_addr_t addr = 0; ret = arm_smmu_rpm_get(smmu); if (ret < 0) @@ -1287,6 +1288,7 @@ static phys_addr_t arm_smmu_iova_to_phys_hard(struct iommu_domain *domain, dev_err(dev, "iova to phys timed out on %pad. Falling back to software table walk.\n", &iova); + arm_smmu_rpm_put(smmu); return ops->iova_to_phys(ops, iova); } @@ -1295,12 +1297,14 @@ static phys_addr_t arm_smmu_iova_to_phys_hard(struct iommu_domain *domain, if (phys & ARM_SMMU_CB_PAR_F) { dev_err(dev, "translation fault!\n"); dev_err(dev, "PAR = 0x%llx\n", phys); - return 0; + goto out; } + addr = (phys & GENMASK_ULL(39, 12)) | (iova & 0xfff); +out: arm_smmu_rpm_put(smmu); - return (phys & GENMASK_ULL(39, 12)) | (iova & 0xfff); + return addr; } static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain, -- 2.30.2