1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

drm/crtc: Fix uninit-value bug in drm_mode_setcrtc

The connector_set contains uninitialized values when allocated with
kmalloc_array. However, in the "out" branch, the logic assumes that any
element in connector_set would be equal to NULL if failed to
initialize, which causes the bug reported by Syzbot. The fix is to use
an extra variable to keep track of how many connectors are initialized
indeed, and use that variable to decrease any refcounts in the "out"
branch.

Reported-by: syzbot+4fad2e57beb6397ab2fc@syzkaller.appspotmail.com
Signed-off-by: Ziqi Zhao <astrajoan@yahoo.com>
Reported-and-tested-by: syzbot+4fad2e57beb6397ab2fc@syzkaller.appspotmail.com
Tested-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Link: https://lore.kernel.org/r/20230721161446.8602-1-astrajoan@yahoo.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>
This commit is contained in:
Ziqi Zhao 2023-07-21 09:14:46 -07:00 committed by Maxime Ripard
parent 5a6c9a05e5
commit 3823119b9c
No known key found for this signature in database
GPG key ID: E3EF0D6F671851C5

View file

@ -715,8 +715,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
struct drm_mode_set set; struct drm_mode_set set;
uint32_t __user *set_connectors_ptr; uint32_t __user *set_connectors_ptr;
struct drm_modeset_acquire_ctx ctx; struct drm_modeset_acquire_ctx ctx;
int ret; int ret, i, num_connectors;
int i;
if (!drm_core_check_feature(dev, DRIVER_MODESET)) if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EOPNOTSUPP; return -EOPNOTSUPP;
@ -851,6 +850,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
goto out; goto out;
} }
num_connectors = 0;
for (i = 0; i < crtc_req->count_connectors; i++) { for (i = 0; i < crtc_req->count_connectors; i++) {
connector_set[i] = NULL; connector_set[i] = NULL;
set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr; set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
@ -871,6 +871,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
connector->name); connector->name);
connector_set[i] = connector; connector_set[i] = connector;
num_connectors++;
} }
} }
@ -879,7 +880,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
set.y = crtc_req->y; set.y = crtc_req->y;
set.mode = mode; set.mode = mode;
set.connectors = connector_set; set.connectors = connector_set;
set.num_connectors = crtc_req->count_connectors; set.num_connectors = num_connectors;
set.fb = fb; set.fb = fb;
if (drm_drv_uses_atomic_modeset(dev)) if (drm_drv_uses_atomic_modeset(dev))
@ -892,7 +893,7 @@ out:
drm_framebuffer_put(fb); drm_framebuffer_put(fb);
if (connector_set) { if (connector_set) {
for (i = 0; i < crtc_req->count_connectors; i++) { for (i = 0; i < num_connectors; i++) {
if (connector_set[i]) if (connector_set[i])
drm_connector_put(connector_set[i]); drm_connector_put(connector_set[i]);
} }