Skip to content

Commit 3823119

Browse files
astrajoanmripard
authored andcommitted
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: [email protected] Signed-off-by: Ziqi Zhao <[email protected]> Reported-and-tested-by: [email protected] Tested-by: Harshit Mogalapalli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Maxime Ripard <[email protected]>
1 parent 5a6c9a0 commit 3823119

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/gpu/drm/drm_crtc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
715715
struct drm_mode_set set;
716716
uint32_t __user *set_connectors_ptr;
717717
struct drm_modeset_acquire_ctx ctx;
718-
int ret;
719-
int i;
718+
int ret, i, num_connectors;
720719

721720
if (!drm_core_check_feature(dev, DRIVER_MODESET))
722721
return -EOPNOTSUPP;
@@ -851,6 +850,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
851850
goto out;
852851
}
853852

853+
num_connectors = 0;
854854
for (i = 0; i < crtc_req->count_connectors; i++) {
855855
connector_set[i] = NULL;
856856
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,
871871
connector->name);
872872

873873
connector_set[i] = connector;
874+
num_connectors++;
874875
}
875876
}
876877

@@ -879,7 +880,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
879880
set.y = crtc_req->y;
880881
set.mode = mode;
881882
set.connectors = connector_set;
882-
set.num_connectors = crtc_req->count_connectors;
883+
set.num_connectors = num_connectors;
883884
set.fb = fb;
884885

885886
if (drm_drv_uses_atomic_modeset(dev))
@@ -892,7 +893,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
892893
drm_framebuffer_put(fb);
893894

894895
if (connector_set) {
895-
for (i = 0; i < crtc_req->count_connectors; i++) {
896+
for (i = 0; i < num_connectors; i++) {
896897
if (connector_set[i])
897898
drm_connector_put(connector_set[i]);
898899
}

0 commit comments

Comments
 (0)