Skip to contentSkip to conversation

drm/panthor: Enforce DRM_PANTHOR_BO_NO_MMAP

PATCH In review Boris Brezillon 3 participants 5 messages Apr 15, 2025 – Apr 16, 2025

Subsystems (3)
lore
Share & tools
lore

Boris Brezillon

author maintainer
#0 lore raw

PATCH 1/1 drm/panthor: Enforce DRM_PANTHOR_BO_NO_MMAP

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can still be mmap-ed.

Fortunately, this bug only impacts user BOs, because kernel BOs are not exposed to userspace (they don't have a BO handle), so they can't be mmap-ed anyway. Given all user BOs setting this flag are private anyway (not shareable), there's no potential data leak.

Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")
---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 15d8e2bcf6ad..1499df07f512 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
Signature · 1 line
2.49.0
author maintainer
#1 lore raw
Quoted 28 lines · On Tue, 15 Apr 2025 12:57:10 +0200 Boris Brezillon…

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can still be mmap-ed.

Fortunately, this bug only impacts user BOs, because kernel BOs are not exposed to userspace (they don't have a BO handle), so they can't be mmap-ed anyway. Given all user BOs setting this flag are private anyway (not shareable), there's no potential data leak.

Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")
---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 15d8e2bcf6ad..1499df07f512 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 

drivers/gpu/drm/panthor/panthor_drv.c static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data, · line 956

Quoted 6 lines
drivers/gpu/drm/panthor/panthor_drv.c +3 -0
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;

Maybe it should be EPERM instead of EINVAL here.

Quoted 4 lines
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
maintainer Reviewed-by
#2 lore raw
Quoted 34 lines · Boris Brezillon
Quoted 31 lines · On Tue, 15 Apr 2025 12:57:10 +0200 Boris Brezillon…

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can still be mmap-ed.

Fortunately, this bug only impacts user BOs, because kernel BOs are not exposed to userspace (they don't have a BO handle), so they can't be mmap-ed anyway. Given all user BOs setting this flag are private anyway (not shareable), there's no potential data leak.

Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")
---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 15d8e2bcf6ad..1499df07f512 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
Quoted 5 lines

drivers/gpu/drm/panthor/panthor_drv.c static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data, · line 956

Quoted 3 lines
drivers/gpu/drm/panthor/panthor_drv.c +3 -0
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;

Maybe it should be EPERM instead of EINVAL here.

Yeah, I agree. With that change:

Best regards,
Liviu

Quoted 6 lines
Quoted 5 lines
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
Signature · 8 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Boris Brezillon
Quoted 8 lines · Boris Brezillon

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can still be mmap-ed.

Fortunately, this bug only impacts user BOs, because kernel BOs are not exposed to userspace (they don't have a BO handle), so they can't be mmap-ed anyway. Given all user BOs setting this flag are private anyway (not shareable), there's no potential data leak.

Maybe I'm missing something, but I think the below check in panthor_gem_mmap() should also prevent this:

Quoted 10 lines

static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)

{
	struct panthor_gem_object *bo = to_panthor_bo(obj);

	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
		return -EINVAL;

	return drm_gem_shmem_object_mmap(obj, vma);
}

That said, it doesn't make sense to be able to get an offset if you can't mmap() so this seems like a good change. Indeed potentially with this we no longer need panthor_gem_mmap() - although I haven't completely convinced myself of that yet.

Quoted 2 lines
Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")
Quoted 27 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 15d8e2bcf6ad..1499df07f512 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;
author maintainer
#4 lore raw
Quoted 5 lines · On Wed, 16 Apr 2025 15:26:42 +0100 Steven Price <[email protected]> wrote:
Quoted 4 lines · Boris Brezillon

Right now the DRM_PANTHOR_BO_NO_MMAP flag is ignored by panthor_ioctl_bo_mmap_offset(), meaning BOs with this flag set can still be mmap-ed.

Quoted 15 lines
Quoted 4 lines

Fortunately, this bug only impacts user BOs, because kernel BOs are not exposed to userspace (they don't have a BO handle), so they can't be mmap-ed anyway. Given all user BOs setting this flag are private anyway (not shareable), there's no potential data leak.

Maybe I'm missing something, but I think the below check in panthor_gem_mmap() should also prevent this:

Quoted 7 lines

static int panthor_gem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)

{
	struct panthor_gem_object *bo = to_panthor_bo(obj);

	/* Don't allow mmap on objects that have the NO_MMAP flag set. */
	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
		return -EINVAL;

Doh, how did I miss that one...

Quoted 9 lines
Quoted 3 lines
	return drm_gem_shmem_object_mmap(obj, vma);
}  

That said, it doesn't make sense to be able to get an offset if you can't mmap() so this seems like a good change. Indeed potentially with this we no longer need panthor_gem_mmap() - although I haven't completely convinced myself of that yet.

Quoted 4 lines
Quoted 2 lines
Fixes 4bdca1150792 ("drm/panthor: Add the driver frontend block")

Okay, if we decide to keep that change, I need to reword the commit message and drop the Fixes tag.

Quoted 29 lines
Quoted 28 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_drv.c +5 -0
index 15d8e2bcf6ad..1499df07f512 100644
@@ -940,6 +940,7 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 					struct drm_file *file)
 {
 	struct drm_panthor_bo_mmap_offset *args = data;
+	struct panthor_gem_object *bo;
 	struct drm_gem_object *obj;
 	int ret;
 
@@ -950,6 +951,10 @@ static int panthor_ioctl_bo_mmap_offset(struct drm_device *ddev, void *data,
 	if (!obj)
 		return -ENOENT;
 
+	bo = to_panthor_bo(obj);
+	if (bo->flags & DRM_PANTHOR_BO_NO_MMAP)
+		return -EINVAL;
+
 	ret = drm_gem_create_mmap_offset(obj);
 	if (ret)
 		goto out;