habanalabs: remove access to kernel memory using debugfs
authorOfir Bitton <obitton@habana.ai>
Mon, 28 Dec 2020 16:28:08 +0000 (18:28 +0200)
committerOded Gabbay <ogabbay@kernel.org>
Wed, 27 Jan 2021 19:03:49 +0000 (21:03 +0200)
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 <obitton@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/misc/habanalabs/gaudi/gaudi.c
drivers/misc/habanalabs/goya/goya.c

index e105f1c6ab748bd585e6c308b87aede890114f63..3d8414d3afa8f2307dd09a0e02193799f9a0f19c 100644 (file)
@@ -5734,8 +5734,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;
        }
@@ -5781,8 +5779,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;
        }
@@ -5832,8 +5828,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;
        }
@@ -5882,8 +5876,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;
        }
index 12d9e5205f52df592a14545aeea0102a687503d3..eeade9a45bc0a0050af26047ce466c398f990f91 100644 (file)
@@ -4122,9 +4122,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;
        }
@@ -4178,9 +4175,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;
        }
@@ -4223,9 +4217,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;
        }
@@ -4266,9 +4257,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;
        }