From: sashiko-bot@kernel.org
To: "Sebastian Wick" <sebastian.wick@redhat.com>,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths
Date: Sat, 05 Dec 2026 00:42:33 +0000 [thread overview]
Message-ID: <sashiko-outbox-250842@kernel.org> (raw)
In-Reply-To: <20261205001701.1125045-2-sebastian.wick@redhat.com>
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 <sebastian.wick@redhat.com>
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/20261205001701.1125045-1-sebastian.wick@redhat.com?part=1
next prev parent reply other threads:[~2026-12-05 0:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 0:16 [PATCH v2 0/2] drm/vkms: Fix races on ConfigFS device removal Sebastian Wick
2026-12-05 0:17 ` [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths Sebastian Wick
2026-12-05 0:42 ` sashiko-bot [this message]
2026-12-05 0:17 ` [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal Sebastian Wick
2026-12-05 0:34 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-250842@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sebastian.wick@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.