Skip to content

Commit 3abab27

Browse files
Charles Baylisdanvet
authored andcommitted
drm: Return -ENOTTY for non-drm ioctls
drm: Return -ENOTTY for non-drm ioctls Return -ENOTTY from drm_ioctl() when userspace passes in a cmd number which doesn't relate to the drm subsystem. Glibc uses the TCGETS ioctl to implement isatty(), and without this change isatty() returns it incorrectly returns true for drm devices. To test run this command: $ if [ -t 0 ]; then echo is a tty; fi < /dev/dri/card0 which shows "is a tty" without this patch. This may also modify memory which the userspace application is not expecting. Signed-off-by: Charles Baylis <[email protected]> Cc: [email protected] Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent a3a9ee4 commit 3abab27

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

drivers/gpu/drm/drm_ioctl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,9 @@ long drm_ioctl(struct file *filp,
834834
if (drm_dev_is_unplugged(dev))
835835
return -ENODEV;
836836

837+
if (DRM_IOCTL_TYPE(cmd) != DRM_IOCTL_BASE)
838+
return -ENOTTY;
839+
837840
is_driver_ioctl = nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END;
838841

839842
if (is_driver_ioctl) {

include/drm/drm_ioctl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
6868
unsigned long arg);
6969

7070
#define DRM_IOCTL_NR(n) _IOC_NR(n)
71+
#define DRM_IOCTL_TYPE(n) _IOC_TYPE(n)
7172
#define DRM_MAJOR 226
7273

7374
/**

0 commit comments

Comments
 (0)