lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20220914051548.10644-1-nicolinc@nvidia.com>
Date:   Tue, 13 Sep 2022 22:15:48 -0700
From:   Nicolin Chen <nicolinc@...dia.com>
To:     <thierry.reding@...il.com>, <joro@...tes.org>, <will@...nel.org>,
        <robin.murphy@....com>
CC:     <jgg@...dia.com>, <kevin.tian@...el.com>, <vdumpa@...dia.com>,
        <jonathanh@...dia.com>, <linux-tegra@...r.kernel.org>,
        <iommu@...ts.linux.dev>, <linux-kernel@...r.kernel.org>
Subject: [PATCH v2 12/13] iommu/tegra: Constrain return value of ->attach_dev()

Ensure attach_dev() callback functions only return errno values expected
from the attach_dev() op. In particular, only return -EINVAL when we are
sure that the device is incompatible with the domain.

Signed-off-by: Nicolin Chen <nicolinc@...dia.com>
---
 drivers/iommu/tegra-gart.c | 2 +-
 drivers/iommu/tegra-smmu.c | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c
index e5ca3cf1a949..ed53279d1106 100644
--- a/drivers/iommu/tegra-gart.c
+++ b/drivers/iommu/tegra-gart.c
@@ -112,7 +112,7 @@ static int gart_iommu_attach_dev(struct iommu_domain *domain,
 	spin_lock(&gart->dom_lock);
 
 	if (gart->active_domain && gart->active_domain != domain) {
-		ret = -EBUSY;
+		ret = -EINVAL;
 	} else if (dev_iommu_priv_get(dev) != domain) {
 		dev_iommu_priv_set(dev, domain);
 		gart->active_domain = domain;
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 2a8de975fe63..fe68bf94dc4b 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -432,8 +432,10 @@ static int tegra_smmu_as_prepare(struct tegra_smmu *smmu,
 	}
 
 	err = tegra_smmu_alloc_asid(smmu, &as->id);
-	if (err < 0)
+	if (err < 0) {
+		err = -ENOSPC;
 		goto err_unmap;
+	}
 
 	smmu_flush_ptc(smmu, as->pd_dma, 0);
 	smmu_flush_tlb_asid(smmu, as->id);
@@ -487,7 +489,7 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain,
 	int err;
 
 	if (!fwspec)
-		return -ENOENT;
+		return -ENODEV;
 
 	for (index = 0; index < fwspec->num_ids; index++) {
 		err = tegra_smmu_as_prepare(smmu, as);
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ