From: sashiko-bot@kernel.org
To: "Luca Ceresoli" <luca.ceresoli@bootlin.com>
Cc: dri-devel@lists.freedesktop.org, imx@lists.linux.dev,
Frank.Li@kernel.org
Subject: Re: [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug
Date: Wed, 25 Nov 2026 18:28:52 +0000 [thread overview]
Message-ID: <sashiko-outbox-233990@kernel.org> (raw)
In-Reply-To: <20261125-drm-bridge-hotplug-v4-30-822722850492@bootlin.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/bridge: UAF of shared encoder-bridge container in
drm_bridge_remove()
- [High] drm/bridge: TOCTOU race and NULL deref on encoder in
drm_bridge_remove()
- [High] drm/bridge: cross-thread stack tmplist corruption in
drm_bridge_detach_from()
- [Medium] drm/bridge: bridge left on bridge_list during detach in
drm_bridge_remove()
--
commit ed101139b3ca92ec58e58cfca1356ce33f6b56c4
Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug
This commit shuts down the encoder pipeline and detaches the removed
bridge and any downstream bridges from the encoder chain when
drm_bridge_remove() is called on an attached bridge.
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index d82e81b26ace2..d942c776db1a9 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
[ ... ]
> @@ -547,9 +548,17 @@ static void drm_bridge_detach_from(struct drm_bridge *bridge)
> * it won't be found by users via of_drm_find_and_get_bridge(), and add it
> * to the lingering bridge list, to keep track of it until its allocated
> * memory is eventually freed.
> + *
> + * If the bridge is currently attached, also shut down the encoder pipeline
> + * and detach this bridge and the following ones.
> */
> void drm_bridge_remove(struct drm_bridge *bridge)
> {
> + if (bridge->encoder) {
> + drm_atomic_shutdown_encoder(bridge->encoder);
> + drm_bridge_detach_from(bridge);
> + }
[Severity: High]
Does detaching the bridge in drm_bridge_remove() cause a use-after-free of
the encoder in drivers that embed struct drm_bridge and struct drm_encoder
in the same devm_drm_bridge_alloc() container, such as tidss and meson?
drivers/gpu/drm/tidss/tidss_encoder.c:tidss_encoder_create() {
t_enc = devm_drm_bridge_alloc(tidss->dev, struct tidss_encoder,
bridge, &tidss_bridge_funcs);
if (IS_ERR(t_enc))
return PTR_ERR(t_enc);
ret = drm_encoder_init(&tidss->ddev, &t_enc->encoder,
&tidss_encoder_funcs, encoder_type, NULL);
...
}
In tidss, devm_drm_dev_alloc() and drmm_mode_config_init() are registered
before tidss_encoder_create() calls devm_drm_bridge_alloc(),
drm_encoder_init(), devm_drm_bridge_add(), and drm_bridge_attach().
On driver unbind or post-encoder probe failure, devres releases actions in
reverse order: drm_bridge_remove_void() now detaches t_enc->bridge and
drops both the attach and add references, and then drm_bridge_put_void()
drops the final allocation reference. __drm_bridge_free() calls
kfree(bridge->container), freeing t_enc while t_enc->encoder is still on
mode_config.encoder_list. When devm_drm_dev_init_release() later runs
drm_mode_config_cleanup(), it calls drm_encoder_cleanup() on the freed
t_enc->encoder.
[Severity: High]
Can a concurrent upstream bridge removal clear bridge->encoder while
drm_atomic_shutdown_encoder() is sleeping, causing a NULL pointer
dereference in drm_bridge_detach_from()?
CPU0 (downstream bridge B) CPU1 (upstream bridge A)
drm_bridge_remove(B)
if (B->encoder)
drm_atomic_shutdown_encoder()
drm_bridge_remove(A)
...
drm_bridge_detach_from(A)
drm_bridge_detach(B)
B->encoder = NULL
drm_bridge_detach_from(B)
encoder = B->encoder
mutex_lock(&encoder->bridge_chain_mutex)
<-- NULL pointer dereference
drm_bridge_detach_from() re-reads bridge->encoder without a NULL check
before locking encoder->bridge_chain_mutex. Similarly, if
drm_bridge_remove() races with drm_encoder_cleanup(), the encoder and its
mutex can be destroyed and freed before drm_bridge_detach_from() locks it;
and if it races with drm_bridge_attach() after bridge->encoder is assigned
but before bridge->chain_node is added to encoder->bridge_chain,
drm_bridge_detach_from() sees list_empty(&bridge->chain_node) and leaves
the removed bridge attached.
[Severity: High]
Can concurrent calls to drm_bridge_detach_from() on two bridges in the
same chain corrupt the stack list head in the upstream caller?
drivers/gpu/drm/drm_bridge.c:drm_bridge_detach_from() {
...
mutex_lock(&encoder->bridge_chain_mutex);
if (!list_empty(&bridge->chain_node))
list_for_each_entry_safe_from(bridge, next, &encoder->bridge_chain, chain_node)
list_move_tail(&bridge->chain_node, &tmplist);
mutex_unlock(&encoder->bridge_chain_mutex);
while (!list_empty(&tmplist))
drm_bridge_detach(list_first_entry(&tmplist, struct drm_bridge, chain_node));
}
When drm_bridge_detach_from() moves bridge A and downstream bridge B onto
its stack-allocated tmplist and drops encoder->bridge_chain_mutex, B's
chain_node is still non-empty (linked into that stack tmplist) and
B->encoder is still non-NULL until drm_bridge_detach(B) reaches
list_del_init(&B->chain_node):
CPU0 (upstream bridge A) CPU1 (downstream bridge B)
drm_bridge_detach_from(A)
mutex_lock(&bridge_chain_mutex)
/* moves A and B to CPU0 tmplist */
mutex_unlock(&bridge_chain_mutex)
drm_bridge_detach(A)
drm_atomic_private_obj_fini()
drm_bridge_remove(B)
...
drm_bridge_detach_from(B)
mutex_lock(&bridge_chain_mutex)
if (!list_empty(&B->chain_node))
list_for_each_entry_safe_from(...)
list_move_tail(..., &tmplist)
<-- walks CPU0 tmplist past
its stack list head
Because B->chain_node is on CPU0's tmplist rather than
encoder->bridge_chain, CPU1's list_for_each_entry_safe_from() never sees
&encoder->bridge_chain as the termination head. It moves CPU0's stack
tmplist head onto CPU1's tmplist and passes a bogus struct drm_bridge
pointer derived from CPU0's stack frame to drm_bridge_detach().
> +
> mutex_lock(&bridge_lock);
> list_move_tail(&bridge->list, &bridge_lingering_list);
> mutex_unlock(&bridge_lock);
[Severity: Medium]
Should bridge->list be moved to bridge_lingering_list before shutting down
the encoder and detaching the bridge?
Leaving the bridge on bridge_list until after drm_bridge_detach_from()
means the bridge is still discoverable via of_drm_find_and_get_bridge() or
drm_bridge_get_next() while drm_bridge_detach() emits DRM_BRIDGE_DETACHED
and clears bridge->dev and bridge->encoder, allowing a concurrent lookup
to find and re-attach the bridge right before drm_bridge_remove() moves it
to bridge_lingering_list and destroys its HPD mutexes.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-drm-bridge-hotplug-v4-0-822722850492@bootlin.com?part=30
next prev parent reply other threads:[~2026-11-25 18:28 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 01/32] drm/display: hdmi-cec-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:08 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 03/32] drm/display: hdmi-cec-notifier-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:07 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 05/32] drm/connector: split drmm_connector_hdmi_init() in 3 parts Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
2026-11-25 18:10 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 07/32] drm/display: bridge-connector: split allocation code from initialization code Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
2026-11-25 18:03 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector Luca Ceresoli
2026-11-25 18:21 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically Luca Ceresoli
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter Luca Ceresoli
2026-11-25 17:59 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 12/32] drm/bridge: initialize chain_node list head on allocation Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 13/32] drm/bridge: initialize chain_node list head on detach and attach errors Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug Luca Ceresoli
2026-11-25 18:16 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list Luca Ceresoli
2026-11-25 18:12 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable Luca Ceresoli
2026-11-25 18:10 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 17/32] drm: event-notifier: add mechanism to notify about hotplug events Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 18/32] drm/bridge: notify about added and detached bridges Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 19/32] drm/mipi-dsi: notify about DSI attach Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 20/32] drm/bridge: add drm_bridge_get_next() and supporting func Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 21/32] drm/panel: implement .get_next_bridge Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 22/32] drm/bridge: display-connector: " Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: " Luca Ceresoli
2026-11-25 18:18 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 25/32] drm/bridge: samsung-dsim: " Luca Ceresoli
2026-11-25 18:15 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from() Luca Ceresoli
2026-11-25 18:15 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder() Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 28/32] drm/tests: atomic: add tests for drm_atomic_shutdown_encoder() Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 29/32] drm/bridge: clear bridge->encoder on detach Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug Luca Ceresoli
2026-11-25 18:28 ` sashiko-bot [this message]
2026-11-25 17:50 ` [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Luca Ceresoli
2026-11-25 18:30 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 32/32] drm/mxsfb/lcdif: enable " Luca Ceresoli
2026-11-25 18:31 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-233990@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=imx@lists.linux.dev \
--cc=luca.ceresoli@bootlin.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox