All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ho Jie Feng" <hjf3108@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/format-helper: Add XRGB8888 to UYVY conversion
Date: Mon, 12 Oct 2026 17:16:21 +0000	[thread overview]
Message-ID: <sashiko-outbox-168448@kernel.org> (raw)
In-Reply-To: <20261012170857.199561-1-hjf3108@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm: heap buffer overflow in drm_fb_xrgb8888_to_uyvy_line() on odd clip width
--

commit 4e505b4602c1fdbf4570529c2dce5fc08ba8b249
Author: Ho Jie Feng <hjf3108@gmail.com>
Subject: drm/format-helper: Add XRGB8888 to UYVY conversion

This commit adds a new format helper function, drm_fb_xrgb8888_to_uyvy(),
to convert XRGB8888 framebuffers to UYVY format. It is intended for devices
that use packed UYVY natively but need to support XRGB8888 framebuffers.

> diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
> index 6cddf05c493bd..606733ca43fb4 100644
> --- a/drivers/gpu/drm/drm_format_helper.c
> +++ b/drivers/gpu/drm/drm_format_helper.c
[ ... ]
> +static void drm_fb_xrgb8888_to_uyvy_line(void *dbuf, const void *sbuf, unsigned int width)
> +{
> +	u8 *transfer_buffer = dbuf;
> +	const __le32 *temp_buffer = sbuf;
> +	unsigned int i, dst_offset = 0;
> +	unsigned int pixel1, pixel2;
> +	unsigned int r1, g1, b1, r2, g2, b2;
> +	unsigned int r, g, b;
> +	unsigned int v, y1, u, y2;
> +
> +	for (i = 0; i < width; i += 2) {
> +		pixel1 = le32_to_cpup(&temp_buffer[i]);
> +		pixel2 = le32_to_cpup(&temp_buffer[i + 1]);

[Severity: High]
Does this code perform an out-of-bounds read if the damage clip width is odd?

If userspace provides a damage clip where the width is an odd number, on the
final iteration of this loop, it appears we will unconditionally read
temp_buffer[i + 1] past the end of the source buffer.

> +
> +		r1 = (pixel1 & 0x00ff0000) >> 16;
> +		g1 = (pixel1 & 0x0000ff00) >> 8;
> +		b1 =  pixel1 & 0x000000ff;
> +		r2 = (pixel2 & 0x00ff0000) >> 16;
> +		g2 = (pixel2 & 0x0000ff00) >> 8;
> +		b2 =  pixel2 & 0x000000ff;
> +
> +		y1 = drm_pixel_rgb_to_y_bt601(r1, g1, b1);
> +		y2 = drm_pixel_rgb_to_y_bt601(r2, g2, b2);
> +
> +		r = r1 + r2;
> +		g = g1 + g2;
> +		b = b1 + b2;
> +
> +		v = drm_pixel_rgb2_to_v_bt601(r, g, b);
> +		u = drm_pixel_rgb2_to_u_bt601(r, g, b);
> +
> +		transfer_buffer[dst_offset++] = u;
> +		transfer_buffer[dst_offset++] = y1;
> +		transfer_buffer[dst_offset++] = v;
> +		transfer_buffer[dst_offset++] = y2;

[Severity: High]
Can this write overflow the destination buffer boundary?

Since the destination line buffer size is calculated based on dst_pixsize = 2,
it expects 2 bytes per pixel. For an odd width, writing a 4-byte UYVY
macropixel (u, y1, v, y2) on the final iteration writes 4 bytes when only
2 bytes are expected for that final odd pixel. 

This appears to overflow the destination buffer by 2 bytes per line,
potentially corrupting adjacent lines or causing a kernel heap buffer overflow
on the final line.

> +	}
> +}
[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012170857.199561-1-hjf3108@gmail.com?part=1

  reply	other threads:[~2026-10-12 17:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 17:08 [PATCH] drm/format-helper: Add XRGB8888 to UYVY conversion Ho Jie Feng
2026-10-12 17:16 ` sashiko-bot [this message]
2026-10-13  7:11 ` Thomas Zimmermann
2026-10-13 12:17   ` Jie Feng
2026-10-13 12:32     ` Thomas Zimmermann
2026-10-13 13:07       ` Jie Feng

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-168448@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hjf3108@gmail.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.