Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/bridge: trilinear: unlocked device_link_remove() UAF on
  dp->dev
- [Medium] drm/bridge: trilinear: missing dp->released check in
  dptx_bridge_mode_set()
- [Low] drm/cix: bridge glue placed in top-level drm/cix/ instead of
  drm/bridge/
--

commit 1e4145188b36c3532088673583ce49d4b100b5b9
Author: Luo Liu <[email protected]>

drm/cix: add the Sky1 DisplayPort platform glue

This commit adds the Cix Sky1 platform glue driver that maps the RCSU video
adapter registers and binds the shared Trilinear DisplayPort bridge driver.

[ ... ]

> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
> index 61111d50b1c65..a1808db8b9c8a 100644
> --- a/drivers/gpu/drm/Kconfig
> +++ b/drivers/gpu/drm/Kconfig
> @@ -311,6 +311,7 @@ source "drivers/gpu/drm/aspeed/Kconfig"
>  source "drivers/gpu/drm/ast/Kconfig"
>  source "drivers/gpu/drm/atmel-hlcdc/Kconfig"
>  source "drivers/gpu/drm/bridge/Kconfig"
> +source "drivers/gpu/drm/cix/Kconfig"
>  source "drivers/gpu/drm/etnaviv/Kconfig"
>  source "drivers/gpu/drm/exynos/Kconfig"
>  source "drivers/gpu/drm/fsl-dcu/Kconfig"
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 2c6bc093a923a..6ed7456bb993a 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -169,6 +169,7 @@ obj-y                     += tests/
>  obj-$(CONFIG_DRM_MIPI_DBI) += drm_mipi_dbi.o
>  obj-$(CONFIG_DRM_MIPI_DSI) += drm_mipi_dsi.o
>  obj-y                        += arm/
> +obj-y                        += cix/
>  obj-y                        += clients/
>  obj-y                        += display/
>  obj-$(CONFIG_DRM_TTM)        += ttm/

[Severity: Low]
Should this bridge platform glue live under drivers/gpu/drm/bridge/ (or
drivers/gpu/drm/bridge/trilinear/) rather than a new top-level
drivers/gpu/drm/cix/ directory?

drivers/gpu/drm/cix/ contains no drm_driver, only a single 181-line wrapper
for the Trilinear bridge driver.  Putting it at the top level exposes
DRM_CIX_DP outside the Display Interface Bridges menu and adds four extra
Kconfig/Makefile files, whereas comparable SoC bridge wrappers such as
drivers/gpu/drm/bridge/th1520-dw-hdmi.c and
drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-j721e.c sit under
drivers/gpu/drm/bridge/.

[ ... ]

> diff --git a/drivers/gpu/drm/cix/dptx/cix_dptx.c 
> b/drivers/gpu/drm/cix/dptx/cix_dptx.c
> new file mode 100644
> index 0000000000000..e25b3b365d7b8
> --- /dev/null
> +++ b/drivers/gpu/drm/cix/dptx/cix_dptx.c

[ ... ]

> +static void cix_dptx_remove(struct platform_device *pdev)
> +{
> +     trilinear_dptx_remove(platform_get_drvdata(pdev));
> +}

[Severity: Medium]
Can cix_dptx_remove() allow dp->dev to be freed while dptx_bridge_detach()
is still about to pass it to device_link_remove()?

CPU0 (bridge detach)              CPU1 (platform device delete)
dptx_bridge_detach()
  lock(&dp->lock)
  consumer = dp->link_consumer
  dp->link_consumer = NULL
  unlock(&dp->lock)
                                  device_unregister(dp->dev)
                                    device_del(dp->dev)
                                      cix_dptx_remove()
                                        dptx_deinit()
                                          lock(&dp->lock)
                                          /* link_consumer == NULL */
                                          unlock(&dp->lock)
                                      device_links_purge(dp->dev)
                                    put_device(dp->dev) /* freed */
  device_link_remove(consumer,
                     dp->dev)  <-- use-after-free

trilinear_dptx_probe() stores dp->dev without taking a device reference, and
dptx_bridge_attach() adds a DL_FLAG_STATELESS link, so removing the supplier
device does not unbind the consumer first.  Because dptx_bridge_detach()
clears dp->link_consumer and drops dp->lock before calling
device_link_remove(), dptx_deinit() returns immediately and device_del()
purges the link and frees dp->dev before device_link_remove() walks
supplier->links.consumers.

Calling device_link_remove() while still holding dp->lock in
dptx_bridge_detach() (matching the dp->lock -> device_links_write_lock
ordering already used in dptx_bridge_attach()) would serialize link removal
with dptx_deinit().

[Severity: Medium]
Can dptx_bridge_mode_set() dereference a freed dp->dev if cix_dptx_remove()
runs between dp->ops->detect() and reacquiring dp->lock?

CPU0 (modeset)                    CPU1 (platform device delete)
dptx_bridge_mode_set()
  dp->ops->detect(dp)
    /* locks, checks released,
       unlocks */
                                  device_unregister(dp->dev)
                                    cix_dptx_remove()
                                      dptx_deinit()
                                        dp->released = true
                                        device_link_remove(...)
                                    put_device(dp->dev) /* freed */
  guard(mutex)(&dp->lock)
  /* no dp->released check */
  dev_dbg(dp->dev, ...)  <-- use-after-free

dptx_bridge_mode_set() releases dp->lock when dp->ops->detect() returns and
does not re-check dp->released after reacquiring it.  Because dp->bridge
keeps dp alive after dp->dev is freed, dptx_bridge_mode_set() mutates state
on a released bridge and dereferences freed dp->dev in dev_dbg() when
dynamic debug is enabled.

Checking dp->released and returning -ENODEV immediately after acquiring
dp->lock in dptx_bridge_mode_set() would close this window.

-- 
Sashiko AI review · 
https://sashiko.dev/#/patchset/[email protected]?part=5

Reply via email to