Rockchip DRM use-after-free & null-ptr-deref fixes
Subsystems (6)
v2 cover Rockchip DRM use-after-free & null-ptr-deref fixes
The first three patches in the series are fixes for use-after-free & null-ptr-deref related issues found in dw_dp and inno-hdmi Rockchip DRM drivers.
The following three patches provide a few minor improvements to dw_dp and dw_hdmi_qp, while the remaining two address use-after-free and memory allocation in DW DP core library.
---
Changes in v2:
- Fixed conflicts while rebasing onto latest drm-misc-next
- Added two more patches:
* drm/bridge: synopsys: dw-dp: Unregister AUX channel on bridge detach
* drm/bridge: synopsys: dw-dp: Drop useless memory allocation
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Cristian Ciocaltea (8):
drm/rockchip: inno-hdmi: Switch to drmm_kzalloc() drm/rockchip: dw_dp: Switch to drmm_kzalloc() drm/rockchip: dw_dp: Fix null-ptr-deref in dw_dp_remove() drm/rockchip: dw_dp: Simplify error handling drm/rockchip: dw_dp: Drop unnecessary #include drm/rockchip: dw_hdmi_qp: Switch to drmm_encoder_init() drm/bridge: synopsys: dw-dp: Unregister AUX channel on bridge detach drm/bridge: synopsys: dw-dp: Drop useless memory allocation
drivers/gpu/drm/bridge/synopsys/dw-dp.c | 12 ++++++--- drivers/gpu/drm/rockchip/dw_dp-rockchip.c | 35 ++++++++++---------------- drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 13 +++++----- drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c | 3 ++- 4 files changed, 29 insertions(+), 34 deletions(-)
---
base-commit: bfb18fd193e2413f02ad934e46887f415f0ce4ec
change-id: 20260122-drm-rk-fixes-a7622c71553e
PATCH v2 1/8 drm/rockchip: inno-hdmi: Switch to drmm_kzalloc()
Driver makes use of drmm_encoder_init() to initialize the encoder and automatically handle the cleanup by registering drm_encoder_cleanup() with drmm_add_action().
However, the internal structure containing the encoder part gets allocated with devm_kzalloc(), which happens while component_bind_all() is being called from Rockchip DRM driver. The component framework further ensures it is deallocated as part of releasing all the resources claimed during bind, which is triggered from component_unbind_all().
When the reference to the DRM device gets eventually dropped via drm_dev_put() in rockchip_drm_unbind(), drmm_encoder_alloc_release() attempts to access the now released encoder structure, leading to use-after-free.
Ensure driver's internal structure is still reachable on encoder cleanup by switching from a device-managed allocation to a drm-managed one.
--- drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/inno_hdmi-rockchip.c +2 -1
@@ -14,6 +14,7 @@#include <drm/bridge/inno_hdmi.h> #include <drm/drm_bridge_connector.h> +#include <drm/drm_managed.h> #include <drm/drm_of.h> #include "rockchip_drm_drv.h"
@@ -90,7 +91,7 @@ static int inno_hdmi_rockchip_bind(struct device *dev, struct device *master, voconst struct inno_hdmi_plat_data *plat_data;int ret; - hdmi =devm_kzalloc (dev,sizeof (*hdmi),GFP_KERNEL ); + hdmi =drmm_kzalloc (drm,sizeof (*hdmi),GFP_KERNEL );if (!hdmi)return -ENOMEM ;
Signature · 1 line
2.52.0
PATCH v2 2/8 drm/rockchip: dw_dp: Switch to drmm_kzalloc()
In reply to Cristian CiocalteaDriver makes use of drmm_encoder_init() to initialize the encoder and automatically handle the cleanup by registering drm_encoder_cleanup() with drmm_add_action().
However, the internal structure containing the encoder part gets allocated with devm_kzalloc(), which happens while component_bind_all() is being called from Rockchip DRM driver. The component framework further ensures it is deallocated as part of releasing all the resources claimed during bind, which is triggered from component_unbind_all().
When the reference to the DRM device gets eventually dropped via drm_dev_put() in rockchip_drm_unbind(), drmm_encoder_alloc_release() attempts to access the now released encoder structure, leading to use-after-free.
Ensure driver's internal structure is still reachable on encoder cleanup by switching from a device-managed allocation to a drm-managed one.
--- drivers/gpu/drm/rockchip/dw_dp-rockchip.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/dw_dp-rockchip.c +2 -1
@@ -13,6 +13,7 @@#include <drm/drm_atomic_helper.h> #include <drm/drm_bridge.h> #include <drm/drm_bridge_connector.h> +#include <drm/drm_managed.h> #include <drm/drm_of.h> #include <drm/drm_print.h> #include <drm/drm_probe_helper.h>
@@ -82,7 +83,7 @@ static int dw_dp_rockchip_bind(struct device *dev, struct device *master, void *struct drm_connector *connector;int ret; - dp =devm_kzalloc (dev,sizeof (*dp),GFP_KERNEL ); + dp =drmm_kzalloc (drm_dev,sizeof (*dp),GFP_KERNEL );if (!dp)return -ENOMEM ;
Signature · 1 line
2.52.0
PATCH v2 3/8 drm/rockchip: dw_dp: Fix null-ptr-deref in dw_dp_remove()
In reply to Cristian CiocalteaAttempting to access driver data in the platform driver ->remove() callback may lead to a null pointer dereference since there is no guaranty that the component ->bind() callback invoking platform_set_drvdata() was executed.
A common scenario is when Rockchip DRM driver didn't manage to run component_bind_all() because of an (unrelated) error causing early return from rockchip_drm_bind().
Drop the unnecessary call to platform_get_drvdata() and, instead, reference the target device structure via platform_device.
--- drivers/gpu/drm/rockchip/dw_dp-rockchip.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/rockchip/dw_dp-rockchip.c +1 -3
@@ -133,9 +133,7 @@ static int dw_dp_probe(struct platform_device *pdev)static void dw_dp_remove (struct platform_device *pdev) { -struct rockchip_dw_dp *dp =platform_get_drvdata (pdev); - -component_del (dp->dev, &dw_dp_rockchip_component_ops); +component_del (&pdev->dev, &dw_dp_rockchip_component_ops); }static const struct dw_dp_plat_data rk3588_dp_plat_data = {
Signature · 1 line
2.52.0
PATCH v2 4/8 drm/rockchip: dw_dp: Simplify error handling
In reply to Cristian CiocalteaMake the code a bit more compact by getting rid of the superfluous assignments around PTR_ERR().
While at it, also drop dev assignment in dw_dp_probe().
--- drivers/gpu/drm/rockchip/dw_dp-rockchip.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
drivers/gpu/drm/rockchip/dw_dp-rockchip.c +7 -14
@@ -104,20 +104,15 @@ static int dw_dp_rockchip_bind(struct device *dev, struct device *master, void *drm_encoder_helper_add (encoder, &dw_dp_encoder_helper_funcs); dp->base =dw_dp_bind (dev, encoder, plat_data); -if (IS_ERR (dp->base)) { - ret =PTR_ERR (dp->base); -return ret; - } +if (IS_ERR (dp->base)) +return PTR_ERR (dp->base); connector =drm_bridge_connector_init (drm_dev, encoder); -if (IS_ERR (connector)) { - ret =PTR_ERR (connector); -return dev_err_probe (dev, ret,"Failed to init bridge connector" ); - } +if (IS_ERR (connector)) +return dev_err_probe (dev,PTR_ERR (connector), +"Failed to init bridge connector" ); -drm_connector_attach_encoder (connector, encoder); - -return 0 ; +return drm_connector_attach_encoder (connector, encoder); }static const struct component_ops dw_dp_rockchip_component_ops = {
@@ -126,9 +121,7 @@ static const struct component_ops dw_dp_rockchip_component_ops = {static int dw_dp_probe (struct platform_device *pdev) { -struct device *dev = &pdev->dev; - -return component_add (dev, &dw_dp_rockchip_component_ops); +return component_add (&pdev->dev, &dw_dp_rockchip_component_ops); }static void dw_dp_remove (struct platform_device *pdev)
Signature · 1 line
2.52.0
PATCH v2 5/8 drm/rockchip: dw_dp: Drop unnecessary #include
In reply to Cristian CiocalteaIncluded header "rockchip_drm_vop.h" is not directly used, drop it.
While at it, ensure #include directives are ordered alphabetically.
--- drivers/gpu/drm/rockchip/dw_dp-rockchip.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/rockchip/dw_dp-rockchip.c +3 -4
@@ -7,8 +7,11 @@*/ #include <linux/component.h> +#include <linux/media-bus-format.h> #include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/videodev2.h> +#include <drm/bridge/dw_dp.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_bridge.h>
@@ -19,11 +22,7 @@#include <drm/drm_probe_helper.h> #include <drm/drm_simple_kms_helper.h> -#include <linux/media-bus-format.h> -#include <linux/videodev2.h> -#include "rockchip_drm_drv.h" -#include "rockchip_drm_vop.h" struct rockchip_dw_dp {struct dw_dp *base;
Signature · 1 line
2.52.0
PATCH v2 6/8 drm/rockchip: dw_hdmi_qp: Switch to drmm_encoder_init()
In reply to Cristian CiocalteaSimplify encoder initialization and cleanup by making use of drmm_encoder_init(), which takes care of registering drm_encoder_cleanup() with drmm_add_action().
--- drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +6 -7
@@ -21,6 +21,7 @@#include <drm/bridge/dw_hdmi_qp.h> #include <drm/display/drm_hdmi_helper.h> #include <drm/drm_bridge_connector.h> +#include <drm/drm_managed.h> #include <drm/drm_of.h> #include <drm/drm_probe_helper.h> #include <drm/drm_simple_kms_helper.h>
@@ -477,7 +478,7 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,if (!pdev->dev.of_node)return -ENODEV ; - hdmi =devm_kzalloc (&pdev->dev,sizeof (*hdmi),GFP_KERNEL ); + hdmi =drmm_kzalloc (drm,sizeof (*hdmi),GFP_KERNEL );if (!hdmi)return -ENOMEM ;
@@ -586,16 +587,16 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,return ret;drm_encoder_helper_add (encoder, &dw_hdmi_qp_rockchip_encoder_helper_funcs); -drm_simple_encoder_init (drm, encoder,DRM_MODE_ENCODER_TMDS ); + ret =drmm_encoder_init (drm, encoder,NULL ,DRM_MODE_ENCODER_TMDS ,NULL ); +if (ret) +return dev_err_probe (hdmi->dev, ret,"Failed to init encoder" );platform_set_drvdata (pdev, hdmi); hdmi->hdmi =dw_hdmi_qp_bind (pdev, encoder, &plat_data); -if (IS_ERR (hdmi->hdmi)) { -drm_encoder_cleanup (encoder); +if (IS_ERR (hdmi->hdmi))return dev_err_probe (hdmi->dev,PTR_ERR (hdmi->hdmi),"Failed to bind dw-hdmi-qp" ); - } connector =drm_bridge_connector_init (drm, encoder);if (IS_ERR (connector))
@@ -612,8 +613,6 @@ static void dw_hdmi_qp_rockchip_unbind(struct device *dev,struct rockchip_hdmi_qp *hdmi =dev_get_drvdata (dev);cancel_delayed_work_sync (&hdmi->hpd_work); - -drm_encoder_cleanup (&hdmi->encoder.encoder); }static const struct component_ops dw_hdmi_qp_rockchip_ops = {
Signature · 1 line
2.52.0
PATCH v2 7/8 drm/bridge: synopsys: dw-dp: Unregister AUX channel on bridge detach
In reply to Cristian CiocalteaThe DisplayPort AUX channel gets initialized and registered during dw_dp_bind(), but it is never unregistered, which may lead to resource leaks and/or use-after-free:
[ 224.661371] BUG: KASAN: slab-use-after-free in device_is_dependent+0xe0/0x2b0 [ 224.662015] Read of size 8 at addr ffff00011aee8550 by task modprobe/658 ... [ 224.662796] device_is_dependent+0xe0/0x2b0 [ 224.662802] device_is_dependent+0x108/0x2b0 [ 224.662808] device_link_add+0x1f8/0x10b0 [ 224.662813] devm_of_phy_get_by_index+0x120/0x200 [ 224.662819] dw_dp_bind+0x34c/0xb10 [dw_dp] [ 224.662830] dw_dp_rockchip_bind+0x194/0x250 [rockchipdrm] [ 224.662864] component_bind_all+0x3a8/0x720 [ 224.662869] rockchip_drm_bind+0x120/0x390 [rockchipdrm] [ 224.662899] try_to_bring_up_aggregate_device+0x76c/0x838 [ 224.662904] component_master_add_with_match+0x1f4/0x230 [ 224.662909] rockchip_drm_platform_probe+0x420/0x538 [rockchipdrm] [ 224.662939] platform_probe+0xe8/0x168 [ 224.662945] really_probe+0x340/0x828 [ 224.662950] __driver_probe_device+0x2e0/0x350 [ 224.662954] driver_probe_device+0x80/0x140 [ 224.662959] __driver_attach+0x398/0x460 [ 224.662964] bus_for_each_dev+0xe0/0x198 [ 224.662968] driver_attach+0x50/0x68 [ 224.662972] bus_add_driver+0x2a0/0x4c0 [ 224.662977] driver_register+0x294/0x360 [ 224.662982] __platform_driver_register+0x7c/0x98 [ 224.662987] rockchip_drm_init+0xc4/0xff8 [rockchipdrm]
...
Unregister the AUX adapter on bridge detach.
--- drivers/gpu/drm/bridge/synopsys/dw-dp.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/bridge/synopsys/dw-dp.c +8 -0
@@ -1751,6 +1751,13 @@ static const struct drm_edid *dw_dp_bridge_edid_read(struct drm_bridge *bridge,return edid; } +static void dw_dp_bridge_detach (struct drm_bridge *bridge) +{ +struct dw_dp *dp =bridge_to_dp (bridge); + +drm_dp_aux_unregister (&dp->aux); +} + static u32 *dw_dp_bridge_atomic_get_output_bus_fmts(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state, struct drm_crtc_state *crtc_state,
@@ -1824,6 +1831,7 @@ static const struct drm_bridge_funcs dw_dp_bridge_funcs = { .atomic_disable = dw_dp_bridge_atomic_disable, .detect = dw_dp_bridge_detect, .edid_read = dw_dp_bridge_edid_read, + .detach = dw_dp_bridge_detach, };static int dw_dp_link_retrain (struct dw_dp *dp)
Signature · 1 line
2.52.0
Heiko Stuebner
maintainerRe: [PATCH v2 7/8] drm/bridge: synopsys: dw-dp: Unregister AUX channel on bridge detach
Am Montag, 9. März 2026, 23:44:35 Mitteleuropäische Normalzeit schrieb Cristian Ciocaltea:
Quoted 29 lines
The DisplayPort AUX channel gets initialized and registered during
dw_dp_bind(), but it is never unregistered, which may lead to resource leaks and/or use-after-free:[ 224.661371] BUG: KASAN: slab-use-after-free in device_is_dependent+0xe0/0x2b0 [ 224.662015] Read of size 8 at addr ffff00011aee8550 by task modprobe/658 ... [ 224.662796] device_is_dependent+0xe0/0x2b0 [ 224.662802] device_is_dependent+0x108/0x2b0 [ 224.662808] device_link_add+0x1f8/0x10b0 [ 224.662813] devm_of_phy_get_by_index+0x120/0x200 [ 224.662819] dw_dp_bind+0x34c/0xb10 [dw_dp] [ 224.662830] dw_dp_rockchip_bind+0x194/0x250 [rockchipdrm] [ 224.662864] component_bind_all+0x3a8/0x720 [ 224.662869] rockchip_drm_bind+0x120/0x390 [rockchipdrm] [ 224.662899] try_to_bring_up_aggregate_device+0x76c/0x838 [ 224.662904] component_master_add_with_match+0x1f4/0x230 [ 224.662909] rockchip_drm_platform_probe+0x420/0x538 [rockchipdrm] [ 224.662939] platform_probe+0xe8/0x168 [ 224.662945] really_probe+0x340/0x828 [ 224.662950] __driver_probe_device+0x2e0/0x350 [ 224.662954] driver_probe_device+0x80/0x140 [ 224.662959] __driver_attach+0x398/0x460 [ 224.662964] bus_for_each_dev+0xe0/0x198 [ 224.662968] driver_attach+0x50/0x68 [ 224.662972] bus_add_driver+0x2a0/0x4c0 [ 224.662977] driver_register+0x294/0x360 [ 224.662982] __platform_driver_register+0x7c/0x98 [ 224.662987] rockchip_drm_init+0xc4/0xff8 [rockchipdrm]
Quoted 3 lines
...
Unregister the AUX adapter on bridge detach.
that sounds sort of asymmetrical though. drm_bridge_funcs has attach and detach callbacks and the component-framework also has bind and unbind callbacks.
This might cause confusion later on I guess, especially as I don't know if there could be a bridge attach, after the detach that unregisters the aux adapter.
Looking at the AnalogixDP for example, it does the the register and unregister in the bind/unbind callbacks of the core driver.
So I guess the in my eyes cleaner way would be to introduce a dw_dp_unbind() function and put the aux unregister there?
At least that way, everything would be at the same "level".
Heiko
Re: [PATCH v2 7/8] drm/bridge: synopsys: dw-dp: Unregister AUX channel on bridge detach
Hello Heiko,
Quoted 42 lines · Heiko Stuebner
Am Montag, 9. März 2026, 23:44:35 Mitteleuropäische Normalzeit schrieb Cristian Ciocaltea:
Quoted 29 lines
The DisplayPort AUX channel gets initialized and registered during
dw_dp_bind(), but it is never unregistered, which may lead to resource leaks and/or use-after-free:[ 224.661371] BUG: KASAN: slab-use-after-free in device_is_dependent+0xe0/0x2b0 [ 224.662015] Read of size 8 at addr ffff00011aee8550 by task modprobe/658 ... [ 224.662796] device_is_dependent+0xe0/0x2b0 [ 224.662802] device_is_dependent+0x108/0x2b0 [ 224.662808] device_link_add+0x1f8/0x10b0 [ 224.662813] devm_of_phy_get_by_index+0x120/0x200 [ 224.662819] dw_dp_bind+0x34c/0xb10 [dw_dp] [ 224.662830] dw_dp_rockchip_bind+0x194/0x250 [rockchipdrm] [ 224.662864] component_bind_all+0x3a8/0x720 [ 224.662869] rockchip_drm_bind+0x120/0x390 [rockchipdrm] [ 224.662899] try_to_bring_up_aggregate_device+0x76c/0x838 [ 224.662904] component_master_add_with_match+0x1f4/0x230 [ 224.662909] rockchip_drm_platform_probe+0x420/0x538 [rockchipdrm] [ 224.662939] platform_probe+0xe8/0x168 [ 224.662945] really_probe+0x340/0x828 [ 224.662950] __driver_probe_device+0x2e0/0x350 [ 224.662954] driver_probe_device+0x80/0x140 [ 224.662959] __driver_attach+0x398/0x460 [ 224.662964] bus_for_each_dev+0xe0/0x198 [ 224.662968] driver_attach+0x50/0x68 [ 224.662972] bus_add_driver+0x2a0/0x4c0 [ 224.662977] driver_register+0x294/0x360 [ 224.662982] __platform_driver_register+0x7c/0x98 [ 224.662987] rockchip_drm_init+0xc4/0xff8 [rockchipdrm]Quoted 3 lines
...
Unregister the AUX adapter on bridge detach.
that sounds sort of asymmetrical though.
drm_bridge_funcshas attach and detach callbacks and the component-framework also has bind and unbind callbacks.This might cause confusion later on I guess, especially as I don't know if there could be a bridge attach, after the detach that unregisters the aux adapter.
Quoted 7 lines
Looking at the AnalogixDP for example, it does the the register and unregister in the bind/unbind callbacks of the core driver.
So I guess the in my eyes cleaner way would be to introduce a
dw_dp_unbind()function and put the aux unregister there?At least that way, everything would be at the same "level".
You are right. As a matter of fact exporting the *_unbind() in the library was my first thought, but for some reason I went with the "auto" approach.
I've just handled this in v3 [1].
Thanks for reviewing and picking the rest of the patches!
Regards,
Cristian
PATCH v2 8/8 drm/bridge: synopsys: dw-dp: Drop useless memory allocation
In reply to Cristian CiocalteaThe bridge gets allocated and initialized implicitly via the devm_drm_bridge_alloc() helper in dw_dp_bind(). However, this is preceded by an explicit allocation for the same dw_dp struct, which is never used anywhere as the return from devm_kzalloc() gets immediately overwritten by the aforementioned helper.
Get rid of the unnecessary and confusing memory allocation.
--- drivers/gpu/drm/bridge/synopsys/dw-dp.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-dp.c +0 -4
@@ -1977,10 +1977,6 @@ struct dw_dp *dw_dp_bind(struct device *dev, struct drm_encoder *encoder,void __iomem *res;int ret; - dp =devm_kzalloc (dev,sizeof (*dp),GFP_KERNEL ); -if (!dp) -return ERR_PTR (-ENOMEM ); - dp = devm_drm_bridge_alloc(dev, struct dw_dp, bridge, &dw_dp_bridge_funcs);if (IS_ERR (dp))return ERR_CAST (dp);
Signature · 1 line
2.52.0
Re: (subset) [PATCH v2 0/8] Rockchip DRM use-after-free & null-ptr-deref fixes
In reply to Cristian CiocalteaQuoted 9 lines · Cristian Ciocaltea
The first three patches in the series are fixes for use-after-free & null-ptr-deref related issues found in
dw_dpand inno-hdmi Rockchip DRM drivers.The following three patches provide a few minor improvements to
dw_dpanddw_hdmi_qp, while the remaining two address use-after-free and memory allocation in DW DP core library.[...]
Applied, thanks!
[1/8] drm/rockchip: inno-hdmi: Switch to drmm_kzalloc()
commit: 3cc50e7f73fcf79f28660b9d91566b13cb62e520
[2/8] drm/rockchip: dw_dp: Switch to drmm_kzalloc()
commit: ed9da8d23020352ad24c528db09b5acdd78b81fd
[3/8] drm/rockchip: dw_dp: Fix null-ptr-deref in dw_dp_remove()
commit: 9456381d8b60bb7dd42f2f04afe5ee4ce6e0bc12
[4/8] drm/rockchip: dw_dp: Simplify error handling
commit: 26cb3e26efa7cc84289966cab871889f6ca93616
[5/8] drm/rockchip: dw_dp: Drop unnecessary #include
commit: 31a98842a11fcb52a2db9b1b498d5ac11793e35f
[6/8] drm/rockchip: dw_hdmi_qp: Switch to drmm_encoder_init()
commit: e1f7b7cbd74c6561944f5dda345dab59ad391acb
[8/8] drm/bridge: synopsys: dw-dp: Drop useless memory allocation
commit: 971a6d5d41315f3bfe1e1207f24da9a191c949ffBest regards,
Signature · 1 line
Heiko Stuebner <[email protected]>