Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/bridge: tda998x: tda998x_detect_work() drops HPD before detect() - [Medium] drm/bridge: tda998x: unreferenced bridge_connector UAF in tda998x_audio_get_eld() - [Medium] drm/bridge: tda998x: tda998x_remove() destroys hpd_mutex before detect_work --
commit 5c61daf84ccbb8e21901c3e3a497e52ae6903d78 Author: Luo Liu <[email protected]> drm/bridge: tda998x: fix DRM_BRIDGE_ATTACH_NO_CONNECTOR support This commit caches the connector passed to the bridge detect and EDID read callbacks so mode setting, ELD retrieval, and hotplug work use the external bridge connector when attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, and sets bridge.interlace_allowed. > diff --git a/drivers/gpu/drm/bridge/tda998x_drv.c > b/drivers/gpu/drm/bridge/tda998x_drv.c > index 0b966c9844e70..40379d74a53ac 100644 > --- a/drivers/gpu/drm/bridge/tda998x_drv.c > +++ b/drivers/gpu/drm/bridge/tda998x_drv.c [ ... ] > @@ -778,10 +800,11 @@ static void tda998x_detect_work(struct work_struct > *work) > { > struct tda998x_priv *priv = > container_of(work, struct tda998x_priv, detect_work); > - struct drm_device *dev = priv->connector.dev; > > - if (dev) > - drm_kms_helper_hotplug_event(dev); > + if (priv->bridge_connector) > + drm_bridge_hpd_notify(&priv->bridge, tda998x_conn_detect(priv)); [Severity: Medium] Can tda998x_detect_work() lock priv->bridge.hpd_mutex after tda998x_remove() has destroyed it? tda998x_remove() calls drm_bridge_remove(), which runs mutex_destroy(&bridge->hpd_mutex), before disabling the HPD interrupt and canceling edid_delay_timer and detect_work: CPU0 CPU1 (kworker) tda998x_remove() drm_bridge_remove(&priv->bridge) mutex_destroy(&bridge->hpd_mutex) tda998x_detect_work() drm_bridge_hpd_notify() mutex_lock(&bridge->hpd_mutex) <-- use-after-destroy ... cancel_work_sync(&priv->detect_work) > + else if (priv->connector.dev) > + drm_kms_helper_hotplug_event(priv->connector.dev); > } [Severity: Medium] Does gating drm_bridge_hpd_notify() on priv->bridge_connector drop hotplug events before tda998x_bridge_detect() or tda998x_bridge_edid_read() has been called? When attached with DRM_BRIDGE_ATTACH_NO_CONNECTOR, priv->connector.dev is NULL and priv->bridge_connector stays NULL until .detect() or .edid_read() runs. With client->irq present, drm_bridge_connector_init() sets DRM_CONNECTOR_POLL_HPD and registers the HPD callback without calling .detect() or .edid_read(), so an HPD interrupt arriving before the first connector probe takes neither branch and is lost. Since drm_bridge_hpd_notify() does not use priv->bridge_connector, checking priv->connector.dev first and calling drm_bridge_hpd_notify() in the else branch would avoid dropping early HPD events. [ ... ] > @@ -1152,10 +1176,10 @@ static int tda998x_audio_get_eld(struct device *dev, > void *data, > uint8_t *buf, size_t len) > { > struct tda998x_priv *priv = dev_get_drvdata(dev); > + struct drm_connector *connector = tda998x_get_connector(priv); > > mutex_lock(&priv->audio_mutex); > - memcpy(buf, priv->connector.eld, > - min(sizeof(priv->connector.eld), len)); > + memcpy(buf, connector->eld, min(sizeof(connector->eld), len)); > mutex_unlock(&priv->audio_mutex); > > return 0; > } [ ... ] > @@ -1390,6 +1406,8 @@ static void tda998x_bridge_detach(struct drm_bridge > *bridge) > { > struct tda998x_priv *priv = bridge_to_tda998x_priv(bridge); > > + priv->bridge_connector = NULL; > + > if (priv->connector.dev) > drm_connector_cleanup(&priv->connector); > } [Severity: Medium] Can tda998x_audio_get_eld() read from a freed priv->bridge_connector when the display driver unbinds? priv->audio_pdev lives until tda998x_remove(), while the external connector created by drm_bridge_connector_init() is allocated with drmm_kzalloc() after the mode_config and encoder cleanup actions are registered. During DRM teardown, drm_managed_release() runs in reverse order and frees the drm_bridge_connector before drm_encoder_cleanup() calls tda998x_bridge_detach(). In addition, tda998x_get_connector() and tda998x_bridge_detach() access priv->bridge_connector without holding priv->audio_mutex or taking a connector reference: CPU0 CPU1 tda998x_audio_get_eld() connector = tda998x_get_connector() drm_managed_release() free_dr() /* frees bridge_connector */ ... drm_encoder_cleanup() tda998x_bridge_detach() priv->bridge_connector = NULL mutex_lock(&priv->audio_mutex) memcpy(buf, connector->eld, ...) <-- use-after-free -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
