Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/vkms: vkms_set_crc_source() bypasses drm_dev_enter() guard on disable - [Medium] drm/vkms: unguarded atomic_enable allows post-shutdown vblank timer UAF - [Low] drm/vkms: bypassed writeback get_modes guard and wrong lock rationale --
commit 61d2fd052426fe82a4c8e4ed09b2de7270308629 Author: Sebastian Wick <[email protected]> drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths This commit adds drm_dev_enter()/drm_dev_exit() guards to connector detect/get_modes callbacks and vkms_set_crc_source() in preparation for using drm_dev_unplug() on ConfigFS device removal. > Atomic commit callbacks are intentionally not guarded: they are > serialized against drm_atomic_helper_shutdown() via modeset ww_mutex > locks, and must remain functional after unplug so shutdown can disable > CRTCs. [Severity: Medium] Can an in-flight atomic commit still re-enable a CRTC and its vblank hrtimer after drm_atomic_helper_shutdown() finishes? drm_ioctl() checks drm_dev_is_unplugged() without taking drm_dev_enter(), so drm_dev_unplug() does not wait for atomic ioctls that have not yet acquired modeset locks. Modeset ww_mutex locks only serialize commits against each other; they do not stop an in-flight ioctl from running after shutdown drops the locks. update_connector_routing() rejects an unregistered connector only when crtc_state->active is true and the connector is in the request. One in-flight commit can attach it with ACTIVE=0, and a second can set ACTIVE=1 without listing the connector, calling drm_crtc_vblank_on(). CPU0 (ConfigFS remove) CPU1 (in-flight atomic ioctls) drm_dev_unplug() drm_ioctl() (passed unplugged check) drm_dev_unregister() synchronize_srcu() drm_atomic_helper_shutdown() drm_crtc_vblank_off() commit 1: attach connector, ACTIVE=0 commit 2: set CRTC ACTIVE=1 drm_crtc_vblank_atomic_enable() drm_crtc_vblank_on() close last fd -> drm_managed_release() destroy workq, zero crtc, free output <hrtimer> drm_vblank_timer_function() <-- NULL deref / use-after-free drm_vblank_init_release() hrtimer_cancel() Because vkms_create() calls drm_vblank_init() before vkms_modeset_init(), LIFO drm_managed_release() destroys composer_workq and frees crtc and vkms_output before drm_vblank_init_release() cancels the hrtimer. If the timer fires during teardown, it causes a NULL dereference or use-after-free. Unlike atomic_disable, atomic_enable is never needed by drm_atomic_helper_shutdown(), so guarding atomic_enable with drm_dev_enter()/drm_dev_exit() would prevent re-enabling the CRTC after unplug. [ ... ] > diff --git a/drivers/gpu/drm/vkms/vkms_composer.c > b/drivers/gpu/drm/vkms/vkms_composer.c > index 0fc915a954bad..23df0cb9eeb13 100644 > --- a/drivers/gpu/drm/vkms/vkms_composer.c > +++ b/drivers/gpu/drm/vkms/vkms_composer.c [ ... ] > @@ -731,11 +732,19 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const > char *src_name) > { > struct vkms_output *out = drm_crtc_to_vkms_output(crtc); > bool enabled = false; > - int ret = 0; > + int ret, idx; > > ret = vkms_crc_parse_source(src_name, &enabled); > > + if (!drm_dev_enter(crtc->dev, &idx)) { > + if (!enabled) > + vkms_set_composer(out, false); > + return -ENODEV; > + } > + > vkms_set_composer(out, enabled); > > + drm_dev_exit(idx); > + > return ret; > } [Severity: Medium] Does calling vkms_set_composer(out, false) here bypass the drm_dev_enter() guard on the post-unplug debugfs release path? crtc_crc_release() always calls set_crc_source(crtc, NULL), which sets enabled to false. When drm_dev_enter() returns false it has already unlocked drm_unplug_srcu, so synchronize_srcu() in drm_dev_unplug() does not wait for vkms_set_composer(out, false). CPU0 (ConfigFS remove) CPU1 (close crc/data fd) drm_dev_unplug() dev->unplugged = true synchronize_srcu() crtc_crc_release() vkms_set_crc_source(crtc, NULL) drm_dev_enter() -> false (no SRCU) devres_release_group() drm_vblank_init_release() free dev->vblank, vkms_output vkms_set_composer(out, false) spin_lock_irq(&out->lock) drm_crtc_vblank_put() <-- use-after-free Because crtc_crc_open() does not hold a drm_dev_get() reference, closing crc/data without an open DRM chardev fd can race with teardown freeing vkms_output and dev->vblank, or arm vblank->disable_timer after unplug. Skipping vkms_set_composer(out, false) when !drm_dev_enter() will not leave the composer running, because vkms_destroy() runs drm_atomic_helper_shutdown() which calls drm_crtc_vblank_off() and flushes composer_work. Returning -ENODEV directly here avoids the unguarded call. [ ... ] > diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c > b/drivers/gpu/drm/vkms/vkms_writeback.c > index ecf29a2c0c8e0..e779ace7b3837 100644 > --- a/drivers/gpu/drm/vkms/vkms_writeback.c > +++ b/drivers/gpu/drm/vkms/vkms_writeback.c [ ... ] > @@ -67,9 +68,17 @@ static int vkms_wb_atomic_check(struct drm_connector > *connector, > static int vkms_wb_connector_get_modes(struct drm_connector *connector) > { > struct drm_device *dev = connector->dev; > + int count, idx; > > - return drm_add_modes_noedid(connector, dev->mode_config.max_width, > - dev->mode_config.max_height); > + if (!drm_dev_enter(dev, &idx)) > + return 0; > + > + count = drm_add_modes_noedid(connector, dev->mode_config.max_width, > + dev->mode_config.max_height); > + > + drm_dev_exit(idx); > + > + return count; > } [Severity: Low] Does returning 0 here actually prevent modes from being added on an unplugged writeback connector? vkms_wb_connector_funcs has no .detect callback, so the writeback connector still reports connector_status_connected after unplug. When get_modes() returns 0, drm_helper_probe_single_connector_modes() hits its fallback and calls drm_add_modes_noedid(connector, 1024, 768) anyway. Separately, the commit message says detect/get_modes need drm_dev_enter() because MODE_GETCONNECTOR holds mode_config.mutex needed by drm_atomic_helper_shutdown(). drm_atomic_helper_shutdown() does not acquire mode_config.mutex, and drm_mode_getconnector() holds it across fill_modes() regardless; vkms_connector_detect() needs the guard to protect vkmsdev->config. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
