From: Ofir Bitton <obit...@habana.ai>

Accessing kernel allocated memory through debugfs should not
be allowed as it introduces a security vulnerability.
We remove the option to read/write kernel memory for all asics.

Signed-off-by: Ofir Bitton <obit...@habana.ai>
Reviewed-by: Oded Gabbay <ogab...@kernel.org>
Signed-off-by: Oded Gabbay <ogab...@kernel.org>
---
 drivers/misc/habanalabs/gaudi/gaudi.c |  8 --------
 drivers/misc/habanalabs/goya/goya.c   | 12 ------------
 2 files changed, 20 deletions(-)

diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c 
b/drivers/misc/habanalabs/gaudi/gaudi.c
index af49a855d7d6..ac5ad01186c1 100644
--- a/drivers/misc/habanalabs/gaudi/gaudi.c
+++ b/drivers/misc/habanalabs/gaudi/gaudi.c
@@ -5733,8 +5733,6 @@ static int gaudi_debugfs_read32(struct hl_device *hdev, 
u64 addr, u32 *val)
                }
                if (hbm_bar_addr == U64_MAX)
                        rc = -EIO;
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
        } else {
                rc = -EFAULT;
        }
@@ -5780,8 +5778,6 @@ static int gaudi_debugfs_write32(struct hl_device *hdev, 
u64 addr, u32 val)
                }
                if (hbm_bar_addr == U64_MAX)
                        rc = -EIO;
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
        } else {
                rc = -EFAULT;
        }
@@ -5831,8 +5827,6 @@ static int gaudi_debugfs_read64(struct hl_device *hdev, 
u64 addr, u64 *val)
                }
                if (hbm_bar_addr == U64_MAX)
                        rc = -EIO;
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
        } else {
                rc = -EFAULT;
        }
@@ -5881,8 +5875,6 @@ static int gaudi_debugfs_write64(struct hl_device *hdev, 
u64 addr, u64 val)
                }
                if (hbm_bar_addr == U64_MAX)
                        rc = -EIO;
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
        } else {
                rc = -EFAULT;
        }
diff --git a/drivers/misc/habanalabs/goya/goya.c 
b/drivers/misc/habanalabs/goya/goya.c
index da12462bd888..71d5a2620421 100644
--- a/drivers/misc/habanalabs/goya/goya.c
+++ b/drivers/misc/habanalabs/goya/goya.c
@@ -4121,9 +4121,6 @@ static int goya_debugfs_read32(struct hl_device *hdev, 
u64 addr, u32 *val)
                if (ddr_bar_addr == U64_MAX)
                        rc = -EIO;
 
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
-
        } else {
                rc = -EFAULT;
        }
@@ -4177,9 +4174,6 @@ static int goya_debugfs_write32(struct hl_device *hdev, 
u64 addr, u32 val)
                if (ddr_bar_addr == U64_MAX)
                        rc = -EIO;
 
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
-
        } else {
                rc = -EFAULT;
        }
@@ -4222,9 +4216,6 @@ static int goya_debugfs_read64(struct hl_device *hdev, 
u64 addr, u64 *val)
                if (ddr_bar_addr == U64_MAX)
                        rc = -EIO;
 
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
-
        } else {
                rc = -EFAULT;
        }
@@ -4265,9 +4256,6 @@ static int goya_debugfs_write64(struct hl_device *hdev, 
u64 addr, u64 val)
                if (ddr_bar_addr == U64_MAX)
                        rc = -EIO;
 
-       } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
-               *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
-
        } else {
                rc = -EFAULT;
        }
-- 
2.25.1

Reply via email to