cfb_console: fix RLE bitmap drawing code
PATCH 1/1 cfb_console: fix RLE bitmap drawing code
There seems to be tools producing incorrect 'end of bitmap data' markers '0100' in a RLE bitmap. Drawing such bitmaps can result in overwriting memory above the frame buffer. E.g. on MPC5121e based boards this memory can contain U-Boot environment.
We may not rely on the correct end of bitmap data marker 0001 only, but also have to check whether we are going to draw a valid frame buffer scan line.
The patch provides a simple fix by checking the row index:
we finish the drawing if the row index becomes negative.
--- drivers/video/cfb_console.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
drivers/video/cfb_console.c +8 -1
@@ -938,7 +938,10 @@ static int display_rle8_bitmap (bmp_image_t *img, int xoff, int yoff,/* scan line end marker */ bm +=2 ; x =0 ; - y--; +if (--y <0 ) { + decode =0 ; +continue ; + } fbp = (unsigned char *) ((unsigned int)video_fb_address + (((y + yoff) * VIDEO_COLS) +
@@ -952,6 +955,10 @@ static int display_rle8_bitmap (bmp_image_t *img, int xoff, int yoff,/* run offset marker */ x += bm[2 ]; y -= bm[3 ]; +if (y <0 ) { + decode =0 ; +continue ; + } fbp = (unsigned char *) ((unsigned int)video_fb_address + (((y + yoff) * VIDEO_COLS) +
Signature · 1 line
1.7.1
PATCH v2 1/1 cfb_console: fix RLE bitmap drawing code
There seems to be tools producing incorrect 'end of bitmap data' markers '0100' in a RLE bitmap. Drawing such bitmaps can result in overwriting memory above the frame buffer. E.g. on MPC5121e based boards this memory can contain U-Boot environment.
We may not rely on the correct end of bitmap data marker 0001 only, but also have to check whether we are going to draw a valid frame buffer scan line.
The patch provides a fix by maintaining a pixel counter which is incremented by the amount of pixels we are going to draw. If the counter exceeds frame buffer pixels limit we stop the drawing with the error message.
--- drivers/video/cfb_console.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-)
drivers/video/cfb_console.c +15 -4
@@ -882,6 +882,8 @@ static int display_rle8_bitmap (bmp_image_t *img, int xoff, int yoff,struct palette p[256 ];bmp_color_table_entry_t cte;int green_shift, red_off; +int limit =VIDEO_COLS *VIDEO_ROWS ; +int pixels =0 ; x =0 ; y =__le32_to_cpu (img->header.height) -1 ;
@@ -962,6 +964,10 @@ static int display_rle8_bitmap (bmp_image_t *img, int xoff, int yoff,/* unencoded run */ cnt = bm[1 ]; runlen = cnt; + pixels += cnt; +if (pixels > limit) + goto error; + bm +=2 ;if (y < height) {if (x >= width) {
@@ -970,7 +976,6 @@ static int display_rle8_bitmap (bmp_image_t *img, int xoff, int yoff, }if (x + runlen > width) cnt = width - x; -draw_bitmap (&fbp, bm, p, cnt,0 ); x += runlen; }
@@ -982,9 +987,13 @@ next_run:break ;default :/* encoded run */ + cnt = bm[0 ]; + runlen = cnt; + pixels += cnt; +if (pixels > limit) + goto error; +if (y < height) {/* only draw into visible area */ - cnt = bm[0 ]; - runlen = cnt;if (x >= width) { x += runlen; bm +=2 ;
@@ -992,7 +1001,6 @@ next_run: }if (x + runlen > width) cnt = width - x; -draw_bitmap (&fbp, bm, p, cnt,1 ); x += runlen; }
@@ -1001,6 +1009,9 @@ next_run: } }return 0 ; +error: +printf ("Error: Too much encoded pixel data, validate your bitmap\n" ); +return -1 ; }#endif
Signature · 1 line
1.7.1
PATCH v2 1/1 cfb_console: fix RLE bitmap drawing code
Quoted 14 lines · On Thu, 28 Apr 2011 21:53:11 +0200 Anatolij Gustschin <[email protected]> wrote:
There seems to be tools producing incorrect 'end of bitmap data' markers '0100' in a RLE bitmap. Drawing such bitmaps can result in overwriting memory above the frame buffer. E.g. on MPC5121e based boards this memory can contain U-Boot environment.
We may not rely on the correct end of bitmap data marker 0001 only, but also have to check whether we are going to draw a valid frame buffer scan line.
The patch provides a fix by maintaining a pixel counter which is incremented by the amount of pixels we are going to draw. If the counter exceeds frame buffer pixels limit we stop the drawing with the error message.
Quoted 6 lines
Reported-by Michael Weiss <[email protected]>Signed-off-by Anatolij Gustschin <[email protected]>Tested-by Anatolij Gustschin <[email protected]>--- drivers/video/cfb_console.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-)
applied to u-boot-video/master.