* [PATCH] drm/kmb: Fix potential invalid free of plane objects
@ 2026-11-18 14:15 Guangshuo Li
2026-11-18 14:22 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-11-18 14:15 UTC (permalink / raw)
To: Anitha Chrisanthus, David Airlie, Simona Vetter
Cc: dri-devel, linux-kernel, stable
Plane objects use drmm_kzalloc() but their destroy callback frees them
with kfree(). The managed allocation can also be released before mode
configuration cleanup accesses the embedded plane.
Use ordinary allocations, matching the existing plane destroy callback.
This issue was found by our static analysis tool under development.
Fixes: 7f7b96a8a0a1 ("drm/kmb: Add support for KeemBay Display")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/gpu/drm/kmb/kmb_plane.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/kmb/kmb_plane.c b/drivers/gpu/drm/kmb/kmb_plane.c
index 1742c2c6dfd8..7c908ca23e5b 100644
--- a/drivers/gpu/drm/kmb/kmb_plane.c
+++ b/drivers/gpu/drm/kmb/kmb_plane.c
@@ -581,7 +581,7 @@ struct kmb_plane *kmb_plane_init(struct drm_device *drm)
BIT(DRM_MODE_BLEND_COVERAGE);
for (i = 0; i < KMB_MAX_PLANES; i++) {
- plane = drmm_kzalloc(drm, sizeof(*plane), GFP_KERNEL);
+ plane = kzalloc_obj(*plane);
if (!plane) {
drm_err(drm, "Failed to allocate plane\n");
@@ -636,6 +636,6 @@ struct kmb_plane *kmb_plane_init(struct drm_device *drm)
return primary;
cleanup:
- drmm_kfree(drm, plane);
+ kfree(plane);
return ERR_PTR(ret);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/kmb: Fix potential invalid free of plane objects
2026-11-18 14:15 [PATCH] drm/kmb: Fix potential invalid free of plane objects Guangshuo Li
@ 2026-11-18 14:22 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-18 14:22 UTC (permalink / raw)
To: Guangshuo Li; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] drm/kmb: invalid CRTC and mode_config cleanup on kmb_probe()
error path [1]
--
commit ea7f217c42f68c4024aad8e879735018a1ecdb10
Author: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
drm/kmb: Fix potential invalid free of plane objects
This commit replaces drmm_kzalloc() and drmm_kfree() with kzalloc_obj()
and kfree() in kmb_plane_init() so plane allocations match the kfree() in
kmb_plane_destroy().
> diff --git a/drivers/gpu/drm/kmb/kmb_plane.c b/drivers/gpu/drm/kmb/kmb_plane.c
> index 1742c2c6dfd89..7c908ca23e5ba 100644
> --- a/drivers/gpu/drm/kmb/kmb_plane.c
> +++ b/drivers/gpu/drm/kmb/kmb_plane.c
> @@ -581,7 +581,7 @@ struct kmb_plane *kmb_plane_init(struct drm_device *drm)
> BIT(DRM_MODE_BLEND_COVERAGE);
>
> for (i = 0; i < KMB_MAX_PLANES; i++) {
> - plane = drmm_kzalloc(drm, sizeof(*plane), GFP_KERNEL);
> + plane = kzalloc_obj(*plane);
>
> if (!plane) {
> drm_err(drm, "Failed to allocate plane\n");
> @@ -636,6 +636,6 @@ struct kmb_plane *kmb_plane_init(struct drm_device *drm)
>
> return primary;
> cleanup:
> - drmm_kfree(drm, plane);
> + kfree(plane);
> return ERR_PTR(ret);
> }
[Severity: High]
This problem wasn't introduced by this patch, but if kmb_plane_init() or
an earlier step in kmb_setup_mode_config() fails, doesn't the err_free
path in kmb_probe() still perform invalid CRTC and mode_config cleanup
[1]?
drivers/gpu/drm/kmb/kmb_drv.c:kmb_probe() {
...
ret = kmb_setup_mode_config(&kmb->drm);
if (ret)
goto err_free;
...
err_free:
drm_crtc_cleanup(&kmb->crtc);
drm_mode_config_cleanup(&kmb->drm);
...
}
When kmb_setup_mode_config() fails before drm_crtc_init_with_planes()
initializes kmb->crtc (for example when kmb_plane_init() returns an
error), drm_crtc_cleanup(&kmb->crtc) dereferences an uninitialized
crtc->head list entry, causing a NULL pointer dereference. In addition,
because kmb_setup_mode_config() uses drmm_mode_config_init(), calling
drm_mode_config_cleanup() explicitly at err_free causes it to run a second
time when devm_drm_dev_alloc() unwinds.
[1] https://sashiko.dev/#/bug/linux-d222f5e7-17ec-4c5d-8774-adf4a0718282
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-324f82bd41-drm-kmb-0@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 14:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 14:15 [PATCH] drm/kmb: Fix potential invalid free of plane objects Guangshuo Li
2026-11-18 14:22 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.