Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1143436pxv; Fri, 9 Jul 2021 19:22:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIM1GzqCHWQK58LjJyqgqVf3mZMiv0esy1HR1OPdoA0LuwNr31Qf6K7on8mOj1GWgtGiss X-Received: by 2002:a17:907:3c81:: with SMTP id gl1mr41246565ejc.136.1625883776333; Fri, 09 Jul 2021 19:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625883776; cv=none; d=google.com; s=arc-20160816; b=bEsCYS6xEr1Br2wrzY8hTNSNz5HvziYCn5MXI+8zaw6mkaVBZNrFkL/Hctp5M27YyD GHABb1pT9dgVya6V5l9MSM4s/WPRIHgzSH1/78+4qxeujk5D+Bqa1ObKPL/UAQAmXVsa YxjjYHH2eNwaVdsrp5B8SINxazSMWj3sZGkghbM0og+LHGQ4qFDMmWSz+3SNzCe/RJZ5 Qmv3zN848G0XPGtIH5TaBHqlecXF+ld4bMMiroISWgb32p43pQw/dY09qsFrJp7pRisR WqWQSDHJBzyoE7m2MHmdF6FQXlNq76iU6+DY2kSnuO8iF3wqfOQ/AjJbsWZo1X+e+Pzs KPjQ== 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=WWdf5QKOEe9dEvKk0Qpny/oTJrEmCvgodBelKTUCNZw=; b=o3Cr9uJyt3mVhhsf/khWIdDQ5jSw4eDaZMkNLsy1HXCPf1bDLWEGsHbXCzQ9lC+Khx geLYv/6RiBq2L46Y5pH7H/fkHw4K1MwJydH5KSqkgjjpygMAG8aeuRmDhExp+Hn0KL+J JPimNLQ7C+ArMNlmI7W2j+iG/LH1xAe6LOfRAd9yyLOWoq0lY4D2XjJAUXTX8uCiD/gU sn76bBmkaXwRNrogrWRs9TAzIL4iSLNMU6YatlZxOYB1/olO2K2qY+1MWGubYcVIzWnv TvlJJfPVo2KhezfmGwk5riFegg2JpsE0ct4fHGjZT8zZWIQYqrEm16fXAKOhXJfFsuhs b/kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nbWUdZfe; 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 d10si8957943ejl.468.2021.07.09.19.22.31; Fri, 09 Jul 2021 19:22:56 -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=nbWUdZfe; 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 S233249AbhGJCXf (ORCPT + 99 others); Fri, 9 Jul 2021 22:23:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:38502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232263AbhGJCWG (ORCPT ); Fri, 9 Jul 2021 22:22:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5CC9B613E4; Sat, 10 Jul 2021 02:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883558; bh=Lst4pXqfUhCRoD0flbxYKCxTTB3UKBzfb72GcLSlJIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nbWUdZfek9SpwfDOi9Nq/+Iq26vPYEsWF+yA3TcPoFqOTOvGc5zaJQgOUuJBrzpxB WSQQMKjCrrI+0uLiW5adapW608+zsXY0CayuVE2qh6r6Qsq3LjYfVAxFSl3ZZ8/0iO 8BLugfI9gH5M0M4QCzwDMKUWcFnapIBBRY3hzuijEtzvlZ511EsFeQlLboh+zVEnSB YcBm3NQYO1ihc8ivUVFIbQqo0qoV1Wn2BXcTFshROZedLCFqvmFVBu0lWZU1la8KbC Vi16X/n7xyoLZHFUGxedN/EvTL65EtM+LF0CXMjFF5EMbdzg9VpxaZCKM07xVZS7gh EqrD0WAZWb0CQ== 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.13 066/114] iommu/arm-smmu: Fix arm_smmu_device refcount leak in address translation Date: Fri, 9 Jul 2021 22:17:00 -0400 Message-Id: <20210710021748.3167666-66-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710021748.3167666-1-sashal@kernel.org> References: <20210710021748.3167666-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 ee6cac9e7c02..1a647e0ea3eb 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1271,6 +1271,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) @@ -1290,6 +1291,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); } @@ -1298,12 +1300,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