Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/display: missing cec.mutex in
  drm_connector_hdmi_cec_notifier_unregister()
--

commit 524d66733b09456c82258b5e235e9f87be3e61c7
Author: Luca Ceresoli <[email protected]>

drm/display: hdmi-cec-notifier-helper: add non-drmm API variant

This commit adds non-drmm register and unregister helpers for the HDMI CEC
notifier so that hotpluggable HDMI bridges can dynamically register and
unregister their CEC notifiers.

> diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c 
> b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
> index 47662bdc5d08f..2f30844fcdad9 100644
> --- a/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
> +++ b/drivers/gpu/drm/display/drm_hdmi_cec_notifier_helper.c
[ ... ]
> @@ -58,6 +57,27 @@ int drmm_connector_hdmi_cec_notifier_register(struct 
> drm_connector *connector,
>  
>       mutex_unlock(&connector->cec.mutex);
>  
> +     return 0;
> +}
> +EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_register);
> +
> +void drm_connector_hdmi_cec_notifier_unregister(struct drm_connector 
> *connector)
> +{
> +     cec_notifier_conn_unregister(connector->cec.data);
> +     connector->cec.data = NULL;
> +}
> +EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_unregister);

[Severity: Medium]
Should drm_connector_hdmi_cec_notifier_unregister() take
connector->cec.mutex and also clear connector->cec.funcs?

drm_connector_hdmi_cec_notifier_register() sets connector->cec.data and
connector->cec.funcs under connector->cec.mutex, and
drm_connector_cec_phys_addr_set() and
drm_connector_cec_phys_addr_invalidate() hold the same mutex while calling
those callbacks.  When a hotpluggable bridge unregisters its notifier at
runtime while connector detection runs concurrently, the lack of locking
allows a use-after-free on struct cec_notifier:

CPU0                                    CPU1
drm_connector_hdmi_cec_notifier_unregister()
  cec_notifier_conn_unregister(connector->cec.data)
    cec_notifier_put(n)  [frees n]
                                        drm_connector_cec_phys_addr_set()
                                          mutex_lock(&connector->cec.mutex)
                                          ...->phys_addr_set()
                                            cec_notifier_set_phys_addr(
                                              connector->cec.data, ...)
                                              mutex_lock(&n->lock)
                                                <-- use-after-free
  connector->cec.data = NULL;

Leaving connector->cec.funcs non-NULL also allows subsequent physical
address updates on the connector to keep invoking the notifier callbacks
with a NULL connector->cec.data pointer.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=4

Reply via email to