All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Fei Shao" <fshao@chromium.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/mediatek: Validate gamma_lut size
Date: Thu, 05 Nov 2026 09:20:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-198756@kernel.org> (raw)
In-Reply-To: <20261105091054.3993611-1-fshao@chromium.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/mediatek: NULL pointer dereference in mtk_crtc_atomic_check()
--

commit 9fd51aa9fb3e494d751bd1b62a30a2b909f46ef6
Author: Fei Shao <fshao@chromium.org>

drm/mediatek: Validate gamma_lut size

This commit adds mtk_crtc_atomic_check() to validate that any non-NULL
gamma_lut blob matches the hardware LUT size of the CRTC's DDP components,
preventing out-of-bounds reads in mtk_gamma_set() and mtk_aal_gamma_set().

> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index 2920f3198ef6a..fd9b51fd00eaa 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -880,6 +880,26 @@ static void mtk_crtc_atomic_flush(struct drm_crtc *crtc,
>  	mtk_crtc_update_config(mtk_crtc, !!mtk_crtc->event);
>  }
>  
> +static int mtk_crtc_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state)
> +{
> +	struct mtk_crtc *mtk_crtc = to_mtk_crtc(crtc);
> +	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
> +	struct drm_property_blob *gamma_lut = crtc_state->gamma_lut;
> +	unsigned int lut_size;
> +	int i;
> +
> +	if (!gamma_lut)
> +		return 0;
> +
> +	for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
> +		lut_size = mtk_ddp_gamma_get_lut_size(mtk_crtc->ddp_comp[i]);
> +		if (lut_size && gamma_lut->length != lut_size * sizeof(struct drm_color_lut))
> +			return -EINVAL;
> +	}

[Severity: High]
Can mtk_crtc->ddp_comp[i] be NULL here when conn_routes is used?

In mtk_crtc_create(), when conn_routes is non-NULL, mtk_crtc->ddp_comp is
allocated with path_len + 1 entries and mtk_crtc->ddp_comp_nr is incremented
at the end:

drivers/gpu/drm/mediatek/mtk_crtc.c:mtk_crtc_create() {
	...
	if (conn_routes) {
		...
		mtk_crtc->num_conn_routes = num_conn_routes;
		mtk_crtc->conn_routes = conn_routes;

		/* increase ddp_comp_nr at the end of mtk_crtc_create */
		mtk_crtc->ddp_comp_nr++;
	}
}

The last slot in mtk_crtc->ddp_comp[mtk_crtc->ddp_comp_nr - 1] remains NULL
until mtk_crtc_update_output() populates it during mtk_crtc_atomic_enable().

Because mtk_crtc_atomic_check() runs during the atomic check phase before
mtk_crtc_atomic_enable() (for example on the initial modeset, a
DRM_MODE_ATOMIC_TEST_ONLY commit, or when setting GAMMA_LUT while the CRTC is
disabled), passing a valid gamma_lut blob will reach the final iteration of
the loop and pass NULL to mtk_ddp_gamma_get_lut_size():

drivers/gpu/drm/mediatek/mtk_ddp_comp.h:mtk_ddp_gamma_get_lut_size() {
	if (comp->funcs && comp->funcs->gamma_get_lut_size)
		return comp->funcs->gamma_get_lut_size(comp->dev);

	return 0;
}

Unlike mtk_ddp_comp_mode_valid(), which checks if comp is non-NULL before
dereferencing comp->funcs, mtk_ddp_gamma_get_lut_size() dereferences comp
unconditionally. Should mtk_ddp_gamma_get_lut_size() or
mtk_crtc_atomic_check() guard against a NULL comp pointer?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261105091054.3993611-1-fshao@chromium.org?part=1

  reply	other threads:[~2026-11-05  9:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05  9:10 [PATCH] drm/mediatek: Validate gamma_lut size Fei Shao
2026-11-05  9:10 ` Fei Shao
2026-11-05  9:20 ` sashiko-bot [this message]
2026-11-05  9:32 ` AngeloGioacchino Del Regno

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-198756@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=fshao@chromium.org \
    --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 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.