Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but there is a Use-After-Free vulnerability on the error path of `rk3066_hdmi_bind()`. If `rk3066_hdmi_register()` fails, the code jumps to `err_disable_hclk`, skipping the encoder cleanup label `err_cleanup_hdmi`. Since the DRM encoder was added to the DRM device's list during `drm_encoder_init()` but is not removed, and the `hdmi` struct containing the encoder is freed by devres upon bind failure, the DRM core retains a dangling pointer. This will cause a Use-After-Free when the DRM core later iterates over the encoder list or during teardown.
--
--- Patch [1]: [PATCH v2] drm/rockchip: rk3066_hdmi: convert to devm_drm_bridge_alloc() API ---
commit bdad67e77f8f693946bd674b1a40ce7af3ce54c3
Author: Hüseyin BIYIK <[email protected]>
drm/rockchip: rk3066_hdmi: convert to devm_drm_bridge_alloc() API
This commit converts the rk3066_hdmi driver to use devm_drm_bridge_alloc()
for allocating DRM bridges. This conversion was missed during the initial
conversion of all bridges to the new API.
> diff --git a/drivers/gpu/drm/rockchip/rk3066_hdmi.c b/drivers/gpu/drm/rockchip/rk3066_hdmi.c
> index f28d6a883e099..39c65ee07caac 100644
> --- a/drivers/gpu/drm/rockchip/rk3066_hdmi.c
> +++ b/drivers/gpu/drm/rockchip/rk3066_hdmi.c
[ ... ]
> @@ -747,9 +746,10 @@ static int rk3066_hdmi_bind(struct device *dev, struct device *master,
> int irq;
> int ret;
>
> - hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
> - if (!hdmi)
> - return -ENOMEM;
> + hdmi = devm_drm_bridge_alloc(dev, struct rk3066_hdmi, bridge,
> + &rk3066_hdmi_bridge_funcs);
> + if (IS_ERR(hdmi))
> + return PTR_ERR(hdmi);
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the
allocation of the hdmi struct in rk3066_hdmi_bind() inside
drivers/gpu/drm/rockchip/rk3066_hdmi.c, I noticed a potential
use-after-free on the error path.
If rk3066_hdmi_register() fails after drm_encoder_init() has been called,
the error path in rk3066_hdmi_bind() jumps to err_disable_hclk:
ret = rk3066_hdmi_register(drm, hdmi);
if (ret)
goto err_disable_hclk;
This bypasses the err_cleanup_hdmi label which destroys the encoder:
err_cleanup_hdmi:
hdmi->encoder.encoder.funcs->destroy(&hdmi->encoder.encoder);
err_disable_hclk:
clk_disable_unprepare(hdmi->hclk);
Since the encoder was added to the DRM device's internal lists during
drm_encoder_init(), and the devm-allocated hdmi struct will be freed when
rk3066_hdmi_bind() returns an error, does this leave a dangling pointer in
the DRM core that will cause a use-after-free when the list is iterated or
torn down?
>
> hdmi->dev = dev;
> hdmi->drm_dev = drm;
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.