Skip to contentSkip to conversation

drm/nouveau: check ioctl command codes better

PATCH Applied Arnd Bergmann 3 participants 4 messages Jul 11, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau: check ioctl command codes better

From: Arnd Bergmann <[email protected]>

nouveau_drm_ioctl() only checks the _IOC_NR() bits in the DRM_NOUVEAU_NVIF command, but ignores the type and direction bits, so any command with '7' in the low eight bits gets passed into nouveau_abi16_ioctl() instead of drm_ioctl().

Check for all the bits except the size that is handled inside of the handler.

Fixes 27111a23d01c ("drm/nouveau: expose the full object/event interfaces to userspace")
---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +5 -6
index 1527b801f013..506eeb44f0d4 100644
@@ -1284,6 +1284,9 @@ nouveau_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(NOUVEAU_EXEC, nouveau_exec_ioctl_exec, DRM_RENDER_ALLOW),
 };
 
+#define DRM_IOCTL_NOUVEAU_NVIV _IOC(_IOC_READ|_IOC_WRITE, DRM_IOCTL_BASE, \
+				    DRM_COMMAND_BASE + DRM_NOUVEAU_NVIF, 0)
+
 long
 nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
@@ -1297,14 +1300,10 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		return ret;
 	}
 
-	switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
-	case DRM_NOUVEAU_NVIF:
+	if ((cmd & ~IOCSIZE_MASK) == DRM_IOCTL_NOUVEAU_NVIV)
 		ret = nouveau_abi16_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
-		break;
-	default:
+	else
 		ret = drm_ioctl(file, cmd, arg);
-		break;
-	}
 
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
Signature · 1 line
2.39.5
maintainer
#1 lore raw
Quoted 20 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

nouveau_drm_ioctl() only checks the _IOC_NR() bits in the DRM_NOUVEAU_NVIF command, but ignores the type and direction bits, so any command with '7' in the low eight bits gets passed into nouveau_abi16_ioctl() instead of drm_ioctl().

Check for all the bits except the size that is handled inside of the handler.

Fixes 27111a23d01c ("drm/nouveau: expose the full object/event interfaces to userspace")
---
 drivers/gpu/drm/nouveau/nouveau_drm.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -0
index 1527b801f013..506eeb44f0d4 100644

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_ioctls[] = { · line 1288

Quoted 5 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -0
@@ -1284,6 +1284,9 @@ nouveau_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(NOUVEAU_EXEC, nouveau_exec_ioctl_exec, DRM_RENDER_ALLOW),
 };
 
+#define DRM_IOCTL_NOUVEAU_NVIV _IOC(_IOC_READ|_IOC_WRITE, DRM_IOCTL_BASE, \
+				    DRM_COMMAND_BASE + DRM_NOUVEAU_NVIF, 0)

Is there any intention behind NVIV vs NVIF? Indicator that size is not considered?

Quoted 21 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +3 -6
+
 long
 nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
@@ -1297,14 +1300,10 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		return ret;
 	}
 
-	switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
-	case DRM_NOUVEAU_NVIF:
+	if ((cmd & ~IOCSIZE_MASK) == DRM_IOCTL_NOUVEAU_NVIV)
 		ret = nouveau_abi16_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
-		break;
-	default:
+	else
 		ret = drm_ioctl(file, cmd, arg);
-		break;
-	}
 
 	pm_runtime_mark_last_busy(dev->dev);
 	pm_runtime_put_autosuspend(dev->dev);
#2 lore raw
Quoted 9 lines · Danilo Krummrich
Quoted 8 lines · Arnd Bergmann
drivers/gpu/drm/nouveau/nouveau_drm.c +0 -0
index 1527b801f013..506eeb44f0d4 100644
@@ -1284,6 +1284,9 @@ nouveau_ioctls[] = {
 	DRM_IOCTL_DEF_DRV(NOUVEAU_EXEC, nouveau_exec_ioctl_exec, DRM_RENDER_ALLOW),
 };
 
Quoted 5 lines

drivers/gpu/drm/nouveau/nouveau_drm.c nouveau_ioctls[] = { · line 1288

Quoted 2 lines
drivers/gpu/drm/nouveau/nouveau_drm.c +2 -0
+#define DRM_IOCTL_NOUVEAU_NVIV _IOC(_IOC_READ|_IOC_WRITE, DRM_IOCTL_BASE, \
+				    DRM_COMMAND_BASE + DRM_NOUVEAU_NVIF, 0)

Is there any intention behind NVIV vs NVIF? Indicator that size is not considered?

No, just a typo, my mistake.

Arnd

maintainer Applied
#3 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

nouveau_drm_ioctl() only checks the _IOC_NR() bits in the DRM_NOUVEAU_NVIF command, but ignores the type and direction bits, so any command with '7' in the low eight bits gets passed into nouveau_abi16_ioctl() instead of drm_ioctl().

Check for all the bits except the size that is handled inside of the handler.

Fixes 27111a23d01c ("drm/nouveau: expose the full object/event interfaces to userspace")

Applied to drm-misc-fixes, thanks!

[ Fix up two checkpatch warnings and a typo. - Danilo ]