All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: oushixiong1025@163.com
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/vkms: Fix gamma_lut size check
Date: Thu, 20 Aug 2026 08:41:12 +0000	[thread overview]
Message-ID: <20260820084112.86A401F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260820083123.544655-2-oushixiong1025@163.com>

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 the vkms_composer_worker accesses the currently committed CRTC state (crtc->state) asynchronously without locks, leading to a Time-of-Check to Time-of-Use (TOCTOU) race condition and Use-After-Free (UAF).
--

--- Patch [1]: [PATCH] drm/vkms: Fix gamma_lut size check ---
commit a52b4df7305f28acb171652e76fbc632383dbfb6
Author: Shixiong Ou <oushixiong@kylinos.cn>

drm/vkms: Fix gamma_lut size check
    
The gamma_lut size check in vkms_atomic_check() uses
sizeof(struct drm_color_lut *) instead of sizeof(struct drm_color_lut).
On 64-bit both happen to be 8 bytes, so the check works by accident.
On 32-bit sizeof(pointer) is 4 bytes while sizeof(struct drm_color_lut)
is 8 bytes, which would incorrectly reject valid 256-entry LUTs.

> diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
> index 5a640b531d88f..2db3971f72c31 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.c
> +++ b/drivers/gpu/drm/vkms/vkms_drv.c
> @@ -112,7 +112,7 @@ static int vkms_atomic_check(struct drm_device *dev, struct drm_atomic_commit *s
>  		if (!new_crtc_state->gamma_lut || !new_crtc_state->color_mgmt_changed)
>  			continue;
>  
> -		if (new_crtc_state->gamma_lut->length / sizeof(struct drm_color_lut *)
> +		if (new_crtc_state->gamma_lut->length / sizeof(struct drm_color_lut)
>  		    > VKMS_LUT_SIZE)
>  			return -EINVAL;

[Severity: High]
This isn't a bug introduced by this patch, but since we are looking at the
gamma_lut, is it possible for vkms_composer_worker() to hit a use-after-free
when accessing the LUT blob data?

In drivers/gpu/drm/vkms/vkms_composer.c:vkms_composer_worker():

	if (crtc->state->gamma_lut) {
		s64 max_lut_index_fp;
		s64 u16_max_fp = drm_int2fixp(0xffff);

		crtc_state->gamma_lut.base = (struct drm_color_lut *)crtc->state->gamma_lut->data;
		crtc_state->gamma_lut.lut_length =
			crtc->state->gamma_lut->length / sizeof(struct drm_color_lut);

The worker accesses the currently committed CRTC state (crtc->state)
asynchronously without locks, rather than using its own atomic state snapshot.

If userspace rapidly issues atomic commits that update or remove the CRTC's
gamma LUT, couldn't a concurrent atomic commit swap crtc->state and free
the LUT blob while the worker is executing?

This seems like it could create a large use-after-free window during the
blending phase in compose_active_planes(), or a direct NULL pointer
dereference in the setup phase.

>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260820083123.544655-2-oushixiong1025@163.com?part=1

  reply	other threads:[~2026-08-20  8:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20  8:31 [PATCH 1/2] drm/vkms: Cache composer line buffers in vkms_output oushixiong1025
2026-08-20  8:31 ` [PATCH] drm/vkms: Fix gamma_lut size check oushixiong1025
2026-08-20  8:41   ` sashiko-bot [this message]
2026-08-20  8:31 ` [PATCH] drm/vkms: Fix vertical read step for R1/R2/R4 formats oushixiong1025
2026-08-20  8:44   ` sashiko-bot
2026-08-20  8:31 ` [PATCH 2/2] drm/vkms: Skip pre_blend_color_transform when pipeline is all bypassed oushixiong1025
2026-08-20  8:45   ` sashiko-bot
2026-08-20  8:39 ` [PATCH 1/2] drm/vkms: Cache composer line buffers in vkms_output sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-02-04 14:15 [PATCH] drm/vkms: fix gamma LUT size check Renjun Wang
2026-02-06 13:53 ` Louis Chauvet
2026-02-12 15:04   ` Renjun Wang

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=20260820084112.86A401F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=oushixiong1025@163.com \
    --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.