Skip to contentSkip to conversation

drm_edid: potential range checking issue?

PATCH In review Dan Carpenter 2 participants 5 messages Mar 28, 2010 – May 18, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi list, :)

Just going through some Smatch warnings.

drivers/gpu/drm/drm_edid.c +1032 add_detailed_modes() 'data->data.timings' 5 <= 5
1027 /* Six modes per detailed section */
1028 for (i = 0; i < 6; i++) {
1029 struct std_timing *std;
1030 struct drm_display_mode *newmode;
1031

  1032                          std = &data->data.timings[i];
                                      ^^^^^^^^^^^^^^^^^^^^^^

In include/drm/drm_edid.h this array has 5 elements not 6.

struct detailed_non_pixel {
        u8 pad1;
        u8 type; /* ff=serial, fe=string, fd=monitor range, fc=monitor name
                    fb=color point data, fa=standard timing data,
                    f9=undefined, f8=mfg. reserved */
        u8 pad2;
        union {         
                struct detailed_data_string str;
                struct detailed_data_monitor_range range;
                struct detailed_data_wpindex color;
                struct std_timing timings[5];
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                struct cvt_timing cvt[4];
        } data; 
} __attribute__((packed));

regards,
dan carpenter

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--

#1 lore raw

Ping. This off-by-one overflow is still there in -next.

I'm not sure how to fix it because both the declaraion and the use in add_detailed_modes() look deliberate.

regards,
dan carpenter

Quoted 31 lines · Dan Carpenter

Hi list, :)

Just going through some Smatch warnings.

drivers/gpu/drm/drm_edid.c +1032 add_detailed_modes() 'data->data.timings' 5 <= 5
1027 /* Six modes per detailed section */
1028 for (i = 0; i < 6; i++) {
1029 struct std_timing *std;
1030 struct drm_display_mode *newmode;
1031

  1032                          std = &data->data.timings[i];
                                      ^^^^^^^^^^^^^^^^^^^^^^

In include/drm/drm_edid.h this array has 5 elements not 6.

struct detailed_non_pixel {
        u8 pad1;
        u8 type; /* ff=serial, fe=string, fd=monitor range, fc=monitor name
                    fb=color point data, fa=standard timing data,
                    f9=undefined, f8=mfg. reserved */
        u8 pad2;
        union {         
                struct detailed_data_string str;
                struct detailed_data_monitor_range range;
                struct detailed_data_wpindex color;
                struct std_timing timings[5];
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                struct cvt_timing cvt[4];
        } data; 
} __attribute__((packed));
Quoted 2 lines

regards,
dan carpenter

------------------------------------------------------------------------------

--

#2 lore raw
Quoted 14 lines · Dan Carpenter
Quoted 14 lines

In include/drm/drm_edid.h this array has 5 elements not 6.

struct detailed_non_pixel {
        u8 pad1;
        u8 type; /* ff=serial, fe=string, fd=monitor range, fc=monitor name
                    fb=color point data, fa=standard timing data,
                    f9=undefined, f8=mfg. reserved */
        u8 pad2;
        union {         
                struct detailed_data_string str;
                struct detailed_data_monitor_range range;
                struct detailed_data_wpindex color;
                struct std_timing timings[5];
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This decl is wrong, should be 6. From the 1.4 spec:

"Six additional Standard Timings may be listed as a display descriptor (tag #FAh)."

The 1.3 spec is a little less explicit about it, but does show 6 standard timing codes in the 0xFA detailed subblock, terminated by 0x0A in the 18th byte. I don't have the docs for 1.2 or earlier, but we're paranoid enough about not adding broken timings that we should be fine.

- ajax

------------------------------------------------------------------------------

--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel

#3 lore raw

PATCH 1/1 drm_edid: There should be 6 Standard Timings

Smatch complained that we initialize 6 elements in add_detailed_modes() but the timings[] array is declared with 5 elements. Adam Jackson verified that 6 is the correct number of timings.

Quoted 5 lines · Adam Jackson
Quoted 2 lines
Quoted 2 lines
                struct std_timing timings[5];
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This decl is wrong, should be 6. From the 1.4 spec:

Quoted 7 lines

"Six additional Standard Timings may be listed as a display descriptor (tag #FAh)."

The 1.3 spec is a little less explicit about it, but does show 6 standard timing codes in the 0xFA detailed subblock, terminated by 0x0A in the 18th byte. I don't have the docs for 1.2 or earlier, but we're paranoid enough about not adding broken timings that we should be fine.

This patch is basically a clean up, because timings[] is declared inside a union and increasing the number of elements here doesn't change the overall size of the union.

---
This patch applies to drm-next.

include/drm/drm_edid.h +1 -1
index d33c3e0..39e2cc5 100644
@@ -120,7 +120,7 @@ struct detailed_non_pixel {
 		struct detailed_data_string str;
 		struct detailed_data_monitor_range range;
 		struct detailed_data_wpindex color;
-		struct std_timing timings[5];
+		struct std_timing timings[6];
 		struct cvt_timing cvt[4];
 	} data;
 } __attribute__((packed));

------------------------------------------------------------------------------

--

Reviewed-by on v1 1/1
#4 lore raw

Re: [patch] drm_edid: There should be 6 Standard Timings

Quoted 18 lines · Dan Carpenter

Smatch complained that we initialize 6 elements in add_detailed_modes() but the timings[] array is declared with 5 elements. Adam Jackson verified that 6 is the correct number of timings.

Quoted 5 lines · Adam Jackson
Quoted 2 lines
Quoted 2 lines
                struct std_timing timings[5];
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This decl is wrong, should be 6. From the 1.4 spec:

Quoted 7 lines

"Six additional Standard Timings may be listed as a display descriptor (tag #FAh)."

The 1.3 spec is a little less explicit about it, but does show 6 standard timing codes in the 0xFA detailed subblock, terminated by 0x0A in the 18th byte. I don't have the docs for 1.2 or earlier, but we're paranoid enough about not adding broken timings that we should be fine.

Quoted 5 lines

This patch is basically a clean up, because timings[] is declared inside a union and increasing the number of elements here doesn't change the overall size of the union.

- ajax

------------------------------------------------------------------------------

--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel