Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/vkms: NULL dereference in drm_colorop_cleanup() on failed
  colorop init
--

commit 19fa2bf1e8d2d6f8cce50424490f5da439214e86
Author: Oarora Etimis <[email protected]>

drm/vkms: free the colorop whose initialization failed

This commit extends the error cleanup loop in
vkms_initialize_color_pipeline() to include ops[i] so that a colorop
whose initialization fails is cleaned up and freed.

> diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c 
> b/drivers/gpu/drm/vkms/vkms_colorop.c
> index 9424b1994239a..ed557a1c6a056 100644
> --- a/drivers/gpu/drm/vkms/vkms_colorop.c
> +++ b/drivers/gpu/drm/vkms/vkms_colorop.c
> @@ -126,7 +126,7 @@ static int vkms_initialize_color_pipeline(struct 
> drm_plane *plane, struct drm_pr
>       return 0;
>  
>  cleanup:
> -     for (j = 0; j < i; j++) {
> +     for (j = 0; j <= i && j < ARRAY_SIZE(ops); j++) {
>               if (ops[j]) {
>                       drm_colorop_cleanup(ops[j]);
>                       kfree(ops[j]);

[Severity: Medium]
Can calling drm_colorop_cleanup(ops[i]) after a failed
drm_plane_colorop_*_init() cause a NULL pointer dereference?

Each drm_plane_colorop_*_init() helper delegates to
drm_plane_colorop_init(), which can fail in drm_mode_object_add() before
initializing colorop->dev or linking colorop->head:

drivers/gpu/drm/drm_colorop.c:drm_plane_colorop_init() {
        ret = drm_mode_object_add(dev, &colorop->base, DRM_MODE_OBJECT_COLOROP);
        if (ret)
                return ret;

        colorop->base.properties = &colorop->properties;
        colorop->dev = dev;
        ...
        list_add_tail(&colorop->head, &config->colorop_list);
        colorop->index = config->num_colorop++;

When drm_mode_object_add() fails, ops[i]->dev and ops[i]->head are still
zeroed, so drm_colorop_cleanup(ops[i]) dereferences NULL in
list_del(&colorop->head) and config->num_colorop--.  Freeing ops[i] with
kfree() without calling drm_colorop_cleanup() on the failed entry avoids
this.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=2

Reply via email to