Re: [PATCH] drm/gud: validate TV mode names before creating enum property

Ruben Wauters <[email protected]>
Newsgroups org.freedesktop.lists.dri-devel,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
On Wed, 2026-08-19 at 15:28 +0800, Tao Yu wrote:
> The GUD protocol returns TV mode names as fixed-size
> GUD_CONNECTOR_TV_MODE_NAME_LEN entries and requires each name to be
> NUL-terminated.
> 
> gud_connector_add_tv_mode() currently passes each fixed-size entry
> directly to drm_mode_create_tv_properties_legacy(), which eventually
> reaches drm_property_add_enum() and strlen(). If a device returns an
> entry without a terminating NUL byte, strlen() reads past the end of
> the slot and can run beyond the allocated buffer, triggering an
> out-of-bounds read.
> 
> Validate that each returned TV mode name contains a NUL terminator
> within its fixed-size slot before passing it to the DRM property code.
> If a malformed entry is found, reject the device response with -EIO.

Hello, Thank you for the patch. An earlier patch that fixes this issue
has been merged, however, this does look like a better fix of the
issue, so I will apply this one over the other one, as this does not
truncate the data.
> 
> This fixes the out-of-bounds read without changing the handling of
> valid devices, and avoids silently truncating malformed protocol data.
> 
> Reported-by: [email protected]
> Fixes: 40e1a70b4aed ("drm: Add GUD USB Display driver")
> Signed-off-by: Tao Yu <[email protected]>
Reviewed-by: Ruben Wauters <[email protected]>
> ---
>  drivers/gpu/drm/gud/gud_connector.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/gud/gud_connector.c b/drivers/gpu/drm/gud/gud_connector.c
> index ea0cca58b7c89..8141c3a1e30ad 100644
> --- a/drivers/gpu/drm/gud/gud_connector.c
> +++ b/drivers/gpu/drm/gud/gud_connector.c
> @@ -396,8 +396,16 @@ static int gud_connector_add_tv_mode(struct gud_device *gdrm, struct drm_connect
>  	}
>  
>  	num_modes = ret / GUD_CONNECTOR_TV_MODE_NAME_LEN;
> -	for (i = 0; i < num_modes; i++)
> -		modes[i] = &buf[i * GUD_CONNECTOR_TV_MODE_NAME_LEN];
> +	for (i = 0; i < num_modes; i++) {
> +		char *mode = &buf[i * GUD_CONNECTOR_TV_MODE_NAME_LEN];
> +
> +		if (!memchr(mode, '\0', GUD_CONNECTOR_TV_MODE_NAME_LEN)) {
> +			ret = -EIO;
> +			goto free;
> +		}
> +
> +		modes[i] = mode;
> +	}
>  
>  	ret = drm_mode_create_tv_properties_legacy(connector->dev, num_modes, modes);
>  free:
signature.asc (application/pgp-signature, 870 B)
-----BEGIN PGP SIGNATURE-----

iQJPBAABCAA5FiEE3obNNdPQ9V5CQi2Y0n5QwFCuDOEFAmqLGFMbFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMiwyAAoJENJ+UMBQrgzh+BUP/0D/2OlETvV/w/F4uVzl
/ctw4ilsscGIMXHPtRPoE/B3XF5qavJg0vpB2SvXRbwFCxZ7COfl369a/osuLFzy
K/iArRyMYxuQ0LY0kNRlI6hrHYy01L5Ovfpak+Y9OmcXzJhXFFZkv8NbsKGwR0DF
wRGbDyfgPwY8wghjBrAJMfm+0/U8f73iSydMUq3TMcbX3hMCf8Mquylf3k3Cxjzk
kzMOuK3u1fGsVdPz8JiwgOJorNLiL41b0DHIWrxpJMhoNCigXZZij690lNx7bpUU
VQIP9IAtIaDVwEy/1Ej51ekV2V2ECWeZNAwoj53ja01xOtb3AJ/9RhnZUJ9nkDYz
ZUw2KxvGn7KutUHVJIxL+lAiaq2SnA48srBSndBPAZUzMz9Qk951inwqThCd2uXO
LzeLP2BOCfDRd1x+cvhYL7w4G6+/FTBkLiqAdAJZpGzYXxd+sqh1E0iQ17eFR1Bv
vE9NAFC57Ae+vMZ0qbAK3KQmoxlAFqLDIsuGWI4MZLrY+eR/I+4nl4/PrNWlBSND
QshONgc8zdoBBPDyZUROYFVkZX97OKWkk+w7EIJ5EGzVvaspvgpwBu1zkLTKCLBE
DvtM8xMsQpZCDurpXX3ut21lJa7GifFrAohNCwX5iSYhaQeRfKmIuUuuik9iuOjq
TjhqT+/zIbC633DQlpOJA5g0
=+o1y
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.