drm/tegra: gem: Fix mmap of arbitrary physical memory
Subsystems (5)
PATCH 1/1 drm/tegra: gem: Fix mmap of arbitrary physical memory
__tegra_gem_mmap() has no handling for imported dma-bufs: this driver owns no pages array and no CPU mapping of it (bo->pages and bo->vaddr are NULL), and on a platform where the Tegra DRM device is not behind a driver-managed IOMMU domain, bo->iova is left at 0.
Such a buffer falls into the !bo->pages branch and is passed to dma_mmap_wc() with a NULL CPU address and iova 0. On a no-IOMMU configuration this maps physical address 0, and the following gem->size bytes of unrelated physical memory, into the calling process. The mapping is created writable, so a local user able to open the Tegra render node and import a dma-buf (for example one exported from /dev/video* by tegra-vde) can read and corrupt arbitrary physical memory. On Tegra20 RAM starts at 0x0, so kernel memory is easily accessible using moderately large buffers.
drm_gem_is_imported() must not be used to detect the import here: it tests gem->import_attach, which this driver only sets when the buffer is mapped into a driver-managed IOMMU domain, so it is false for imports on no-IOMMU platforms -- exactly the vulnerable case. Test the driver-private bo->dma_buf instead, which is set for every import.
---
I've seen drivers handling this case by forwarding mmap call to the exporter, but its non-trivial so I'm leaving it out of security patch.
Patch has been made with help of AI, hence, per security-bugs.rst I send it as public. I have working reproducers.
--- drivers/gpu/drm/tegra/gem.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/tegra/gem.c +13 -0
@@ -581,6 +581,19 @@ int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma) {struct tegra_bo *bo =to_tegra_bo (gem); +/* +* Reject mmap of imported buffers. Don't use drm_gem_is_imported, it +* always returns false on platforms without IOMMU (e.g. Tegra20). +* Without this check such a request reaches dma_mmap_wc() below +* with a NULL CPU address and bo->iova, which is 0 on platforms without +* a Tegra IOMMU domain, mapping unrelated physical memory into user +* space. +*/ +if (bo->dma_buf) { +drm_gem_vm_close (vma); +return -EINVAL ; + } +if (!bo->pages) {unsigned long vm_pgoff = vma->vm_pgoff;int err;
---
base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
change-id: 20261128-tegra-drm-sec-fix-3598acf641bd
Best regards,
Signature · 1 line
Artur Kowalski <[email protected]>