From: Thomas Zimmermann <tzimmermann@suse.de>
To: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Cc: airlied@redhat.com, sean@poorly.run, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 6/9] drm/udl: Return error if vendor descriptor is too short
Date: Thu, 3 Apr 2025 09:28:10 +0200 [thread overview]
Message-ID: <6452ce55-b237-47b1-8893-15eceeeb4371@suse.de> (raw)
In-Reply-To: <CAMeQTsYcxHyFVn_BHUpxrfMsXZUX07Unm1rBmMYo6i1SMgj3VA@mail.gmail.com>
Hi
Am 02.04.25 um 15:16 schrieb Patrik Jakobsson:
> On Tue, Apr 1, 2025 at 6:23 PM Thomas Zimmermann <tzimmermann@suse.de> wrote:
>> There need to be least 5 bytes in the vendor descriptor. Return
>> an error otherwise. Also change the branching to early-out on
>> the error. Adjust indention of the rest of the parser function.
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> ---
>> drivers/gpu/drm/udl/udl_main.c | 72 +++++++++++++++++-----------------
>> 1 file changed, 36 insertions(+), 36 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/udl/udl_main.c b/drivers/gpu/drm/udl/udl_main.c
>> index 4291ddb7158c4..58d6065589d3a 100644
>> --- a/drivers/gpu/drm/udl/udl_main.c
>> +++ b/drivers/gpu/drm/udl/udl_main.c
>> @@ -45,43 +45,43 @@ static int udl_parse_vendor_descriptor(struct udl_device *udl)
>> goto unrecognized;
>> len = ret;
>>
>> - if (len > 5) {
>> - DRM_INFO("vendor descriptor length: %u data:%11ph\n",
>> - len, desc);
>> -
>> - if ((desc[0] != len) || /* descriptor length */
>> - (desc[1] != 0x5f) || /* vendor descriptor type */
>> - (desc[2] != 0x01) || /* version (2 bytes) */
>> - (desc[3] != 0x00) ||
>> - (desc[4] != len - 2)) /* length after type */
>> - goto unrecognized;
>> -
>> - desc_end = desc + len;
>> - desc += 5; /* the fixed header we've already parsed */
>> -
>> - while (desc < desc_end) {
>> - u8 length;
>> - u16 key;
>> -
>> - key = le16_to_cpu(*((u16 *) desc));
>> - desc += sizeof(u16);
>> - length = *desc;
>> - desc++;
>> -
>> - switch (key) {
>> - case 0x0200: { /* max_area */
>> - u32 max_area;
>> - max_area = le32_to_cpu(*((u32 *)desc));
>> - DRM_DEBUG("DL chip limited to %d pixel modes\n",
>> - max_area);
>> - udl->sku_pixel_limit = max_area;
>> - break;
>> - }
>> - default:
>> - break;
>> - }
>> - desc += length;
>> + if (len < 5)
> Hi Thomas,
>
> Shouldn't this be if (len <= 5)? The old code only parsed if the
> descriptor returned at least 6 bytes.
Right, I also noticed that. But I though it was a mistake. The header is
5 bytes and if there are no key-value pairs it's still a valid
descriptor AFAICT. Patch 9 of the series sets a default for the pixel
limit and the adapter would be usable. I rather not change the new
logic, but add an explanation to the commit description. Ok?
Best regards
Thomas
>
> -Patrik
>
>> + goto unrecognized;
>> +
>> + DRM_INFO("vendor descriptor length: %u data:%11ph\n", len, desc);
>> +
>> + if ((desc[0] != len) || /* descriptor length */
>> + (desc[1] != 0x5f) || /* vendor descriptor type */
>> + (desc[2] != 0x01) || /* version (2 bytes) */
>> + (desc[3] != 0x00) ||
>> + (desc[4] != len - 2)) /* length after type */
>> + goto unrecognized;
>> +
>> + desc_end = desc + len;
>> + desc += 5; /* the fixed header we've already parsed */
>> +
>> + while (desc < desc_end) {
>> + u8 length;
>> + u16 key;
>> +
>> + key = le16_to_cpu(*((u16 *)desc));
>> + desc += sizeof(u16);
>> + length = *desc;
>> + desc++;
>> +
>> + switch (key) {
>> + case 0x0200: { /* max_area */
>> + u32 max_area = le32_to_cpu(*((u32 *)desc));
>> +
>> + DRM_DEBUG("DL chip limited to %d pixel modes\n",
>> + max_area);
>> + udl->sku_pixel_limit = max_area;
>> + break;
>> + }
>> + default:
>> + break;
>> }
>> + desc += length;
>> }
>>
>> goto success;
>> --
>> 2.49.0
>>
--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
next prev parent reply other threads:[~2025-04-03 7:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 16:12 [PATCH 0/9] drm/udl: Support adapters without vendor firmware descriptor Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 1/9] drm/udl: Remove unused field dev from struct udl_device Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 2/9] drm/udl: Remove unused field gem_lock " Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 3/9] drm/udl: Improve type safety when using " Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 4/9] drm/udl: The number of pixels is always positive Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 5/9] drm/udl: Handle errors from usb_get_descriptor() Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 6/9] drm/udl: Return error if vendor descriptor is too short Thomas Zimmermann
2025-04-02 13:16 ` Patrik Jakobsson
2025-04-03 7:28 ` Thomas Zimmermann [this message]
2025-04-03 11:06 ` Patrik Jakobsson
2025-04-01 16:12 ` [PATCH 7/9] drm/udl: Treat vendor descriptor as u8 Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 8/9] drm/udl: Validate length in vendor-descriptor parser Thomas Zimmermann
2025-04-01 16:12 ` [PATCH 9/9] drm/udl: Support adapters without firmware descriptor Thomas Zimmermann
2025-04-03 11:03 ` Patrik Jakobsson
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=6452ce55-b237-47b1-8893-15eceeeb4371@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=patrik.r.jakobsson@gmail.com \
--cc=sean@poorly.run \
/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.