Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/bridge: ti-sn65dsi83: use-after-free in
  sn65dsi83_get_next_bridge()
--

commit 07f44b5de19c58e65f65432a2a999004dd04f3ae
Author: Luca Ceresoli <[email protected]>

drm/bridge: ti-sn65dsi83: implement .get_next_bridge

This commit implements the .get_next_bridge callback for the ti-sn65dsi83
bridge driver to return a reference to ctx->panel_bridge.

> diff --git a/drivers/gpu/drm/bridge/ti-sn65dsi83.c 
> b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
> index 77ef1613c5f51..9e9cf0dda92d8 100644
> --- a/drivers/gpu/drm/bridge/ti-sn65dsi83.c
> +++ b/drivers/gpu/drm/bridge/ti-sn65dsi83.c
> @@ -295,6 +295,13 @@ static struct sn65dsi83 *bridge_to_sn65dsi83(struct 
> drm_bridge *bridge)
>       return container_of(bridge, struct sn65dsi83, bridge);
>  }
>  
> +static struct drm_bridge *sn65dsi83_get_next_bridge(struct drm_bridge 
> *bridge)
> +{
> +     struct sn65dsi83 *ctx = bridge_to_sn65dsi83(bridge);
> +
> +     return ctx->panel_bridge ? drm_bridge_get(ctx->panel_bridge) : 
> ERR_PTR(-ENODEV);
> +}

[Severity: High]
Can sn65dsi83_get_next_bridge() cause a use-after-free on
ctx->panel_bridge?

sn65dsi83_parse_dt() acquires ctx->panel_bridge via
devm_drm_of_get_bridge() -> drm_of_find_panel_or_bridge():

drivers/gpu/drm/drm_panel.c:drm_of_find_panel_or_bridge() {
        ...
        if (bridge) {
                ...
                *bridge = of_drm_find_bridge(remote);
                if (*bridge)
                        return 0;
        }
        ...
}

When the remote DT node is a non-panel bridge, of_drm_find_bridge() drops
the bridge reference before returning, so ctx->panel_bridge holds no
reference.  If the downstream bridge is later removed and freed while
sn65dsi83 stays bound, drm_bridge_get(ctx->panel_bridge) increments the
refcount on freed memory and returns a dangling pointer.

Even when the remote node is a drm_panel, devm_drm_panel_bridge_add() is
registered on ctx->dev after devm_drm_bridge_alloc(), so on unbind devres
puts ctx->panel_bridge before ctx->bridge is destroyed without clearing
ctx->panel_bridge; a concurrent holder of ctx->bridge calling
drm_bridge_get_next() can then access ctx->panel_bridge after its
reference was dropped.  Acquiring the downstream bridge with
of_drm_get_bridge_by_endpoint() and storing it in ctx->bridge.next_bridge
(or releasing it in a bridge .destroy callback) would keep the reference
alive for the lifetime of ctx->bridge.

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

Reply via email to