Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1148309pxv; Fri, 9 Jul 2021 19:33:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygwAzuRuaIGt4AmTaN61LEpmqqbI7lLWN6Svx7Wh6cVfXjaDd60c47dm3GRh+54m49+GG2 X-Received: by 2002:a50:f0cf:: with SMTP id a15mr50377577edm.347.1625884400343; Fri, 09 Jul 2021 19:33:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884400; cv=none; d=google.com; s=arc-20160816; b=DbJ4ajY1QkxtSHSptLhydnnUkyqzHpD/OB5HNk6JTsUg/0Kre6/JP1I0tvxYQyEokS YFtFDBsyX9J4hcxBwF+TImZwDotrNkQX0CeZHaloqIV+yPQN03yOt9iw2TvUm/FCwmSc NGWagYzB2M+3TiKVWH1N+/O6OHMIgVol679rmPj3u6GkSUsZUOI4xfM0ErFUXVC06NX5 d95MzRu04KdNjyoe175NMWVks6rhAYNVtTUUABsLmlAd7l0E+Iuv7NevE+b7AtHLslqY NQOywlqT5+4CW3nIblqmx3gNjnFkgUnr3kc5c/SgboCmGEmlnU7ygX8ArtnaROmnwX61 TDHQ== 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=ItjkntbBPpaPjmeq9axDFvsgKOuhFNkA+w2u1STMbeg=; b=qJF64wD9Sb4mOLFTKRrelK6/3uF0p9q4bLG3FNwJf57YQZP0zxtukt0qeCK6KEc+RQ +C649rbhu0zYQxpAoQfyHCaQcaPP3aWva2MeWzsljVIIw/+YodbQvmqeHV6AvjJhr8Ua kK+RBrnPn89mWht3poB6giCmUDPlv1yujYkG1TcAz4vB/IvQhAuImsag6f5zzM4uPt83 JfM+928zJzyYYOl4wwgw7j1kUOxnbq6lzATjijBp7uoMVWAFd5MSH36ENyMj4z4fXGCI U7LIEklcZwI6PwfWt3/BGeZQOSqRt8Dx6Q9n/cnW+1PksO79ulfXeWyv5dgFfK3lRnvj RoEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AKHa5hgE; 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 q5si9607103edh.490.2021.07.09.19.32.57; Fri, 09 Jul 2021 19:33:20 -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=AKHa5hgE; 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 S233826AbhGJCcT (ORCPT + 99 others); Fri, 9 Jul 2021 22:32:19 -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 S234281AbhGJC3U (ORCPT ); Fri, 9 Jul 2021 22:29:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C25D461439; Sat, 10 Jul 2021 02:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883943; bh=beYeCVqpXG//mMve1jdsA+aMH4RCqJHoakwYn0A5V8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AKHa5hgEb+jmnDP1915RxdykJBNeTLY643BMvCeDGOX0IkyaP/9r0CxiHM3xY/hee 8VF2LOhbq23P5uubhDWmW6v2s/nqshYMlgUnoyHt1NYqc6pR679dnt+dDmw6EOj2Go gmkvXTt/ic1mNNvbtZ642OOlcQYOxuzN4RnF2PlZpmI+5pqXMzklPeMJBJeoR8Bp1/ h+vTATN+gRzzPJ7Om4tsZ6ohsFEmdTwBzTYIcJUhXcX17/LlHveU4r8xmZ4SgMKZOY /DvOiZeH2hSHg4SY2VbfJgP79dZZA8Xa6U98eQtljESMoy3emsillMH/onE+eKav8s oxg1DbkxFX6oA== 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.10 57/93] iommu/arm-smmu: Fix arm_smmu_device refcount leak in address translation Date: Fri, 9 Jul 2021 22:23:51 -0400 Message-Id: <20210710022428.3169839-57-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022428.3169839-1-sashal@kernel.org> References: <20210710022428.3169839-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 052f0a1bf037..df24bbe3ea4f 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c @@ -1284,6 +1284,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) @@ -1303,6 +1304,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); } @@ -1311,12 +1313,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