From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B33D5606A322 for ; Sat, 5 Dec 2026 00:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iZEJ01Vq Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 200D011320C; Sat, 5 Dec 2026 00:42:42 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3839011320C for ; Sat, 5 Dec 2026 00:42:35 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 629F16190C; Sat, 5 Dec 2026 00:42:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 090D01F00936; Sat, 5 Dec 2026 00:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796431354; bh=BVhXksTzOTAhEThCsF86oWKb9xJsWVg5HwuyLtNySs0=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=iZEJ01VqzAKmycnUZ4AJ5TFx6dGmn0iExFYeD5w9lJHyyGVItQdFnnIuFyJiCEjze uFWb/2GtIEdp6Z36QGscA0i0rC8q6ik5MAgFMZqkpO+PRAD8p2xNaLmaRiVLE8c0SF p96fag/zx/0iNuNge+PmFE9DurwGBTqyZLnXzqf9+70zogRtlpNYytFk5yKLM6f/nV icSm8ibrf0OHZSSqaBogpgEe+yzpa4Be+YrDMAyzdNNAtYNjxiPu1WN9RnEJqGigI9 lqPDdthRbQZBvu046PQuL4ptualk+Uex9yf1FHXvKwOUmsKWpunzp1ZIPytkPzzJH8 2v4KfaXbK1/bw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths To: "Sebastian Wick" , dri-devel@lists.freedesktop.org In-Reply-To: <20261205001701.1125045-2-sebastian.wick@redhat.com> References: <20261205001701.1125045-1-sebastian.wick@redhat.com> <20261205001701.1125045-2-sebastian.wick@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 00:42:33 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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=3D0, and a second can set ACTIVE=3D1 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=3D0 commit 2: set CRTC ACTIVE=3D1 drm_crtc_vblank_atomic_enable() drm_crtc_vblank_on() close last fd -> drm_managed_release() destroy workq, zero crtc, free output 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, cons= t char *src_name) > { > struct vkms_output *out =3D drm_crtc_to_vkms_output(crtc); > bool enabled =3D false; > - int ret =3D 0; > + int ret, idx; > =20 > ret =3D vkms_crc_parse_source(src_name, &enabled); > =20 > + if (!drm_dev_enter(crtc->dev, &idx)) { > + if (!enabled) > + vkms_set_composer(out, false); > + return -ENODEV; > + } > + > vkms_set_composer(out, enabled); > =20 > + 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 =3D 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 =3D connector->dev; > + int count, idx; > =20 > - 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 =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205001701.1125= 045-1-sebastian.wick@redhat.com?part=3D1