Re: [PATCH v6 02/43] drm/vkms: Lock the config dump against concurrent configfs changes
From: Oarora Etimis
Date: Mon Nov 23 2026 - 06:27:37 EST
Hello Louis,
> The vkms_config debugfs dump iterates the configuration lists while
> configfs can concurrently mutate or free them, which leads to a
> use-after-free. Move the configuration lock into struct vkms_config and
> run the dump under it.
>
> Fixes: 13fc9b9745cc ("drm/vkms: Add and remove VKMS instances via configfs")
> Signed-off-by: Louis Chauvet <louis.chauvet@xxxxxxxxxxx>
>
> @@ -347,6 +349,14 @@ static int vkms_config_show(struct seq_file *m, void *data)
> struct vkms_config_crtc *crtc_cfg;
> struct vkms_config_encoder *encoder_cfg;
> struct vkms_config_connector *connector_cfg;
> + struct vkms_config *config = (struct vkms_config *)vkmsdev->config;
> +
> + /*
> + * The configuration lists and fields are concurrently mutated by
> + * configfs (creation, removal, attribute stores); iterate under the
> + * configuration lock to keep the iteration coherent.
> + */
> + guard(mutex)(&config->lock);
>
> @@ -711,7 +709,7 @@ static ssize_t device_enabled_store(struct config_item *item, const char *page,
> if (kstrtobool(page, &enabled))
> return -EINVAL;
>
> - scoped_guard(mutex, &dev->lock) {
> + scoped_guard(mutex, &dev->config->lock) {
> if (!dev->enabled && enabled) {
> if (!vkms_config_is_valid(dev->config))
> return -EINVAL;
Now that the dump takes the same lock, holding it across
vkms_create()/vkms_destroy() closes a cycle. vkms_destroy() calls
drm_dev_unregister(), which removes the vkms_config debugfs file and
waits for its readers to drain, while a reader in vkms_config_show() is
waiting for that same lock:
echo 0 > enabled : holds config->lock, waits for the debugfs readers
cat vkms_config : holds a debugfs read, waits for config->lock
Also, vkms_connector_detect() reads cfg->status without taking
config->lock, while connector_status_store() writes it under the lock
and still allows the write after the device is enabled. The kref in
detect only keeps the object alive, so these two are a data race on the
same field.
By the way, Fixes: 13fc9b9745cc looks wrong -- the device cannot be
enabled at that commit, 64229b846a7e looks like the first reachable
point.
Thanks,
Oarora Etimis