drm: Don't call drm_for_each_crtc with a non-KMS driver
authorMichel Dänzer <michel.daenzer@amd.com>
Wed, 30 Nov 2016 08:30:01 +0000 (17:30 +0900)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 30 Nov 2016 09:13:00 +0000 (10:13 +0100)
Fixes oops if userspace calls DRM_IOCTL_GET_CAP for
 DRM_CAP_PAGE_FLIP_TARGET on a non-KMS device node. (Normal userspace
doesn't do that, discovered by syzkaller)

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Fixes: f837297ad824 ("drm: Add DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE/RELATIVE flags v2")
Cc: stable@vger.kernel.org
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161130083002.1520-1-michel@daenzer.net
drivers/gpu/drm/drm_ioctl.c

index 0ad2c47f808fc1d732ef530eba96a6dd265a71c6..71c3473476c7498721a8524c2b8fbde18bf22d7b 100644 (file)
@@ -254,10 +254,12 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
                req->value = dev->mode_config.async_page_flip;
                break;
        case DRM_CAP_PAGE_FLIP_TARGET:
-               req->value = 1;
-               drm_for_each_crtc(crtc, dev) {
-                       if (!crtc->funcs->page_flip_target)
-                               req->value = 0;
+               if (drm_core_check_feature(dev, DRIVER_MODESET)) {
+                       req->value = 1;
+                       drm_for_each_crtc(crtc, dev) {
+                               if (!crtc->funcs->page_flip_target)
+                                       req->value = 0;
+                       }
                }
                break;
        case DRM_CAP_CURSOR_WIDTH: