From: sashiko-bot@kernel.org
To: "Louis Chauvet" <louis.chauvet@bootlin.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 40/43] drm/vkms: Allow to hot-add connectors
Date: Thu, 26 Nov 2026 12:05:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-235474@kernel.org> (raw)
In-Reply-To: <20261126-vkms-all-config-v7-40-21194cda2468@bootlin.com>
Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] drm/vkms: dynamic create/destroy of colorspace_property causes
UAF and WARN_ON
- [High] drm/vkms: ERR_PTR or dangling connector_cfg->connector
dereferenced in configfs
- [High] drm/vkms: lock inversion and race between mode_config.mutex and
config->lock
- [High] drm/vkms: missing unregistered check in vkms_connector_detect()
leaks connectors
- [High] drm/vkms: AB-BA deadlock in vkms_connector_hot_remove() on
mode_config.mutex
- [Medium] drm/vkms: vkms_connector_hot_attach_encoder() hits WARN_ON on
active connector
- [Medium] drm/vkms: unlocked RCU list and XArray traversal in
vkms_output_init()
- [Medium] drm/vkms: unsynchronized runtime mutation of
connector->base.possible_encoders
--
commit 972205cf7741df00d32510d0edacb3bc8edd0c9e
Author: Louis Chauvet <louis.chauvet@bootlin.com>
drm/vkms: Allow to hot-add connectors
This commit adds helpers to hot-add and hot-remove dynamic VKMS
connectors and attach or detach their possible encoders at runtime.
> diff --git a/drivers/gpu/drm/vkms/vkms_connector.c b/drivers/gpu/drm/vkms/vkms_connector.c
> index 71a0ae15be653..93bceba0a1ae6 100644
> --- a/drivers/gpu/drm/vkms/vkms_connector.c
> +++ b/drivers/gpu/drm/vkms/vkms_connector.c
[ ... ]
> @@ -197,9 +198,146 @@ struct vkms_connector *vkms_connector_init_static(struct vkms_device *vkmsdev,
> return connector;
> }
>
> +static void vkms_connector_dynamic_destroy(struct drm_connector *connector)
> +{
> + struct vkms_connector *vkms_connector = drm_connector_to_vkms_connector(connector);
> +
> + if (connector->colorspace_property) {
> + drm_property_destroy(connector->dev,
> + connector->colorspace_property);
> + connector->colorspace_property = NULL;
> + }
[Severity: High]
Can connector->colorspace_property be created and destroyed dynamically
while the DRM device is registered?
struct drm_property is a non-refcounted modeset object (free_cb is NULL)
linked into dev->mode_config.property_list without any lock. When
vkms_connector_hot_add() calls vkms_connector_init() after
drm_dev_register() on an HDMI, DisplayPort or eDP connector with
supported_colorspaces set, drm_property_create() hits
WARN_ON(!dev->driver->load && dev->registered && !obj_free_cb) in
__drm_mode_object_add() and performs an unlocked list_add_tail() on
dev->mode_config.property_list.
When the dynamic connector is destroyed, calling drm_property_destroy()
here hits the matching WARN_ON in drm_mode_object_unregister(), does an
unlocked list_del() on dev->mode_config.property_list, and frees the
property while a concurrent drm_mode_getproperty_ioctl() can be reading
property->values and property->enum_list without a reference:
CPU0 CPU1
drm_mode_getproperty_ioctl()
property = drm_property_find(...)
vkms_connector_hot_remove()
drm_connector_put()
vkms_connector_dynamic_destroy()
drm_property_destroy(property)
kfree(property)
copy_to_user(..., property->values) <-- use-after-free
In addition, if a dynamic connector reference outlives the connector loop
in drm_mode_config_cleanup() during device teardown,
drm_mode_config_cleanup() frees every property on property_list without
clearing connector->colorspace_property, and the later
vkms_connector_dynamic_destroy() double frees it.
> +
> + drm_connector_cleanup(connector);
> +
> + if (vkms_connector->cfg)
> + vkms_config_connector_put(vkms_connector->cfg);
> + kfree(vkms_connector);
> +}
[ ... ]
> +void vkms_connector_hot_remove(struct vkms_connector *connector)
> +{
> + /*
> + * Userspace probes are serialized by mode_config.mutex:
> + * drm_mode_getconnector() holds it for the whole duration of the
> + * probe and the detect()/get_modes() callbacks read the connector
> + * state, including connector->cfg. Take the same mutex here so the
> + * unregistration and the config detachment are not visible in the
> + * middle of an in-flight probe.
> + */
> + mutex_lock(&connector->base.dev->mode_config.mutex);
> +
> + drm_connector_unregister(&connector->base);
[Severity: High]
Does calling drm_connector_unregister() under mode_config.mutex cause an
ABBA deadlock with the connector's sysfs attributes?
drm_connector_unregister() calls drm_sysfs_connector_remove() ->
device_unregister(connector->kdev), which waits in kernfs_drain() for
active sysfs reads or writes on that connector to complete, while sysfs
callbacks such as modes_show(), status_store() and edid_show() acquire
dev->mode_config.mutex:
CPU0 CPU1
---- ----
lock(&dev->mode_config.mutex)
kernfs_fop_read_iter() (kn->active)
lock(&dev->mode_config.mutex)
kernfs_drain() (waits kn->active)
*** DEADLOCK ***
CPU0: vkms_connector_hot_remove() -> drm_connector_unregister() ->
drm_sysfs_connector_remove() -> device_unregister()
CPU1: vfs_read() -> modes_show()
Calling drm_connector_unregister() before acquiring mode_config.mutex
avoids this inversion.
> +
> + /*
> + * Only detach the config from the connector: in-flight userspace
> + * probes may still be reading connector->cfg (see vkms_connector_detect()
> + * and vkms_conn_get_modes()), so the reference taken in
> + * vkms_connector_hot_add() must be kept until the connector is
> + * finally destroyed. vkms_connector_dynamic_destroy() releases it.
> + */
> + if (connector->cfg)
> + connector->cfg->connector = NULL;
> +
> + mutex_unlock(&connector->base.dev->mode_config.mutex);
[Severity: High]
How do vkms_connector_hot_add() and vkms_connector_hot_remove() serialize
with config->lock?
During connector probing, drm_mode_getconnector() holds
dev->mode_config.mutex and calls vkms_connector_detect(), which acquires
cfg->config->lock, establishing the lock order mode_config.mutex ->
config->lock. If vkms_connector_hot_add() or vkms_connector_hot_remove()
is called while holding config->lock, acquiring mode_config.mutex inside
these functions inverts that order:
CPU0 CPU1
---- ----
lock(&config->lock)
lock(&dev->mode_config.mutex)
lock(&dev->mode_config.mutex)
lock(&config->lock)
*** DEADLOCK ***
CPU0: configfs hot-add / hot-remove -> vkms_connector_hot_add()
CPU1: drm_mode_getconnector() -> ... -> vkms_connector_detect()
Conversely, if vkms_connector_hot_remove() is called without config->lock,
clearing connector->cfg->connector under mode_config.mutex races with
connector_possible_encoders_drop_link(), which reads and dereferences
connector->config->connector under config->lock without holding
mode_config.mutex:
CPU0 CPU1
vkms_connector_hot_remove() connector_possible_encoders_drop_link()
lock(&config->lock)
conn = connector->config->connector
lock(&mode_config.mutex)
connector->cfg->connector = NULL
unlock(&mode_config.mutex)
drm_connector_put()
kfree(connector)
vkms_connector_hot_detach_encoder(conn)
<-- use-after-free
> +
> + drm_connector_put(&connector->base);
> +}
[Severity: High]
Does hot-removing a connected dynamic connector leak the drm_connector and
its connector_ida slot?
When a dynamic connector has an active modeset, references to
connector->base are held by its connector state and by the in-kernel DRM
client. vkms_connector_hot_remove() calls drm_connector_unregister() and
keeps connector->cfg non-NULL, but vkms_connector_detect() does not check
drm_connector_is_unregistered():
drivers/gpu/drm/vkms/vkms_connector.c:vkms_connector_detect() {
...
cfg = vkms_connector->cfg;
if (cfg) {
cfg = vkms_config_connector_get(cfg);
scoped_guard(mutex, &cfg->config->lock)
status = vkms_config_connector_get_status(cfg);
vkms_config_connector_put(cfg);
}
return status;
}
Subsequent hotplug probes keep seeing the unregistered connector as
connector_status_connected, so clients never disable its CRTC or drop
their references, leaking the connector and exhausting the 32-connector
limit after repeated hot-removes. Checking
drm_connector_is_unregistered(connector) in vkms_connector_detect() and
returning connector_status_disconnected would allow clients to release it.
> +
> +int vkms_connector_hot_attach_encoder(struct vkms_connector *connector,
> + struct drm_encoder *encoder)
> +{
> + return drm_connector_attach_encoder(&connector->base, encoder);
> +}
[Severity: Medium]
Does vkms_connector_hot_attach_encoder() trigger a WARN_ON and fail with
-EINVAL whenever the connector has an active modeset?
drm_connector_attach_encoder() starts with:
drivers/gpu/drm/drm_connector.c:drm_connector_attach_encoder() {
if (WARN_ON(connector->encoder))
return -EINVAL;
connector->possible_encoders |= drm_encoder_mask(encoder);
return 0;
}
When a modeset is active on the connector (for instance via the in-kernel
fbdev client), drm_atomic_helper_update_legacy_modeset_state() sets
connector->encoder = new_conn_state->best_encoder, so hot-attaching
another encoder at runtime hits WARN_ON(connector->encoder) and fails.
> +
> +int vkms_connector_hot_detach_encoder(struct vkms_connector *connector,
> + struct drm_encoder *encoder)
> +{
> + return drm_connector_detach_encoder(&connector->base, encoder);
> +}
[Severity: Medium]
Can mutating connector->base.possible_encoders on a registered connector
race with drm_mode_getconnector() and write past the userspace encoder
buffer?
drm_mode_getconnector() computes encoders_count from
connector->possible_encoders without any lock, checks that the userspace
buffer has space for encoders_count entries, and then re-reads
connector->possible_encoders in drm_connector_for_each_possible_encoder():
CPU0 CPU1
drm_mode_getconnector()
encoders_count = hweight32(
connector->possible_encoders)
if (out_resp->count_encoders >=
encoders_count)
vkms_connector_hot_attach_encoder()
connector->possible_encoders |= ...
drm_connector_for_each_possible_encoder()
put_user(..., encoder_ptr + copied) <-- writes past count_encoders
> diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
> index fb30cffc10ef8..b100ed0c91e6b 100644
> --- a/drivers/gpu/drm/vkms/vkms_output.c
> +++ b/drivers/gpu/drm/vkms/vkms_output.c
> @@ -115,5 +115,18 @@ int vkms_output_init(struct vkms_device *vkmsdev)
> }
> }
>
> - return drm_mode_config_create_initial_state(dev);
> + ret = drm_mode_config_create_initial_state(dev);
> + if (ret)
> + return ret;
> +
> + vkms_config_for_each_connector_dynamic(vkmsdev->config, connector_cfg) {
[Severity: Medium]
Doesn't vkms_config_for_each_connector_dynamic() trigger an RCU lockdep
warning here and race with concurrent configfs removals?
vkms_config_for_each_connector_dynamic() expands to
list_for_each_entry_rcu() with the lockdep condition
lockdep_is_held(&config->lock) || !config->dev. In device_enabled_store(),
config->lock is dropped before vkms_create() sets config->dev = vkms_device
and calls vkms_output_init(), so neither config->lock nor rcu_read_lock()
is held during this loop, and vkms_connector_hot_add() sleeps while
iterating connector_cfg->possible_encoders. While config->lock is not
held, connector_release() and connector_possible_encoders_drop_link() can
concurrently unlink connector_cfg or erase entries from
connector_cfg->possible_encoders.
> + if (connector_cfg->enabled) {
> + connector_cfg->connector = vkms_connector_hot_add(vkmsdev, connector_cfg);
> +
> + if (IS_ERR(connector_cfg->connector))
> + return PTR_ERR(connector_cfg->connector);
> + }
> + }
[Severity: High]
Can connector_cfg->connector be left holding an ERR_PTR or a dangling
pointer that connector_possible_encoders_drop_link() later dereferences?
If vkms_connector_hot_add() fails here, connector_cfg->connector retains a
non-NULL ERR_PTR value. Likewise, when a device is torn down via
vkms_destroy(), drm_mode_config_cleanup() destroys dynamic connectors via
vkms_connector_dynamic_destroy() without clearing
vkms_connector->cfg->connector (and if connector_cfg->enabled is later set
to false before re-enabling the device, this loop skips it and leaves the
old pointer intact).
Because connector_possible_encoders_drop_link() only tests
connector->config->connector for non-NULL before calling
vkms_connector_hot_detach_encoder(connector->config->connector,
encoder->config->encoder), unlinking an encoder in configfs can
dereference an ERR_PTR or freed vkms_connector.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-vkms-all-config-v7-0-21194cda2468@bootlin.com?part=40
next prev parent reply other threads:[~2026-11-26 12:06 UTC|newest]
Thread overview: 81+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 11:28 [PATCH v7 00/43] VKMS: Introduce multiple configFS attributes Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 01/43] drm/vkms: Lock the config dump against concurrent configfs changes Louis Chauvet
2026-11-26 11:50 ` sashiko-bot
2026-11-26 11:28 ` [PATCH v7 02/43] drm/drm_mode_config: Add helper to get plane type name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 03/43] drm/blend: Get a rotation name from its bitfield Louis Chauvet
2026-11-26 11:40 ` sashiko-bot
2026-11-26 11:28 ` [PATCH v7 04/43] drm/tests: Add test cases for DRM rotation name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 05/43] drm/drm_color_mgmt: Expose drm_get_color_encoding_name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 06/43] drm/drm_color_mgmt: Expose drm_get_color_range_name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 07/43] drm/connector: Export drm_get_colorspace_name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 08/43] drm/drm_atomic_state_helper: Properly load default value for rotation Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 09/43] Documentation: ABI: vkms: Add current VKMS ABI documentation Louis Chauvet
2026-12-01 15:01 ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 10/43] drm/vkms: Reset config->dev when the device creation fails Louis Chauvet
2026-11-26 11:48 ` sashiko-bot
2026-11-27 7:21 ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 11/43] drm/vkms: Reference-count vkms_config and vkms_config_connector Louis Chauvet
2026-11-26 11:49 ` sashiko-bot
2026-11-26 11:28 ` [PATCH v7 12/43] drm/vkms: Add KUnit test for device lifecycle Louis Chauvet
2026-11-26 11:55 ` sashiko-bot
2026-11-27 10:24 ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 13/43] drm/vkms: Add error handling in plane config creation Louis Chauvet
2026-11-27 10:36 ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 14/43] drm/vkms: Simplify plane_release code Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 15/43] drm/vkms: Explicitly display plane type Louis Chauvet
2026-11-27 10:40 ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 16/43] drm/vkms: Use enabled/disabled instead of 1/0 for debug Louis Chauvet
2026-11-27 10:41 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 17/43] drm/vkms: Introduce config for plane name Louis Chauvet
2026-11-26 11:48 ` sashiko-bot
2026-11-27 11:39 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 18/43] drm/vkms: Use plane folder name as " Louis Chauvet
2026-11-27 11:40 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 19/43] drm/vkms: Introduce config for plane rotation Louis Chauvet
2026-11-26 11:46 ` sashiko-bot
2026-12-01 15:19 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 20/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-12-01 15:27 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 21/43] drm/vkms: Introduce config for plane color encoding Louis Chauvet
2026-11-26 11:48 ` sashiko-bot
2026-12-01 16:59 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 22/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:43 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 23/43] drm/vkms: Introduce config for plane color range Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 24/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:45 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 25/43] drm/vkms: Introduce config for plane format Louis Chauvet
2026-11-26 11:46 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 26/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:49 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 27/43] drm/vkms: Properly render plane using their zpos Louis Chauvet
2026-12-01 17:23 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 28/43] drm/vkms: Introduce config for plane zpos property Louis Chauvet
2026-11-26 11:46 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 29/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 30/43] drm/vkms: Introduce back pointer to connector Louis Chauvet
2026-11-26 11:55 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 31/43] drm/vkms: Introduce connector type Louis Chauvet
2026-11-27 7:15 ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 32/43] drm/vkms: Introduce configfs for " Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 33/43] drm/vkms: Rename vkms_connector_init to vkms_connector_init_static Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 34/43] drm/vkms: Introduce config for connector supported colorspace Louis Chauvet
2026-11-26 11:48 ` sashiko-bot
2026-11-26 16:44 ` kernel test robot
2026-11-26 11:29 ` [PATCH v7 35/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:50 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 36/43] drm/vkms: Introduce config for connector EDID Louis Chauvet
2026-11-26 11:51 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 37/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:59 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 38/43] drm/vkms: Store the enabled/disabled status for connector Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 39/43] drm/connector: Add a way to detach encoders Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 40/43] drm/vkms: Allow to hot-add connectors Louis Chauvet
2026-11-26 12:05 ` sashiko-bot [this message]
2026-11-26 11:29 ` [PATCH v7 41/43] drm/vkms: Introduce configfs for dynamic connector creation Louis Chauvet
2026-11-26 12:02 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 42/43] drm/vkms: Add connector parent configuration in vkms_config Louis Chauvet
2026-11-26 11:56 ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 43/43] drm/vkms: Add ConfigFS interface for connector parent and port_id Louis Chauvet
2026-11-26 11:52 ` sashiko-bot
2026-11-26 19:49 ` kernel test robot
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-235474@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=louis.chauvet@bootlin.com \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox