fbdev: bitblit: bound-check glyph index in bit_putcs*
Subsystems (3)
PATCH 1/1 fbdev: bitblit: bound-check glyph index in bit_putcs*
bit_putcs_aligned()/unaligned() derived the glyph pointer from the character value masked by 0xff/0x1ff, which may exceed the actual font's glyph count and read past the end of the built-in font array. Clamp the index to the actual glyph count before computing the address.
This fixes a global out-of-bounds read reported by syzbot.
--- drivers/video/fbdev/core/bitblit.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/video/fbdev/core/bitblit.c +10 -4
@@ -79,12 +79,15 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info, struct fb_image *image, u8 *buf, u8 *dst) { u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; +unsigned int charcnt = vc->vc_font.charcount;u32 idx = vc->vc_font.width >>3 ;u8 *src;while (cnt--) { - src = vc->vc_font.data + (scr_readw (s++)& - charmask)*cellsize; +u16 ch =scr_readw (s++) & charmask; +if (ch >= charcnt) + ch =0 ; + src = vc->vc_font.data + (unsigned int )ch * cellsize;if (attr) {update_attr (buf, src, attr, vc);
@@ -112,14 +115,17 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, u8 *dst) {u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ; +unsigned int charcnt = vc->vc_font.charcount;u32 shift_low =0 , mod = vc->vc_font.width %8 ;u32 shift_high =8 ;u32 idx = vc->vc_font.width >>3 ;u8 *src;while (cnt--) { - src = vc->vc_font.data + (scr_readw (s++)& - charmask)*cellsize; +u16 ch =scr_readw (s++) & charmask; +if (ch >= charcnt) + ch =0 ; + src = vc->vc_font.data + (unsigned int )ch * cellsize;if (attr) {update_attr (buf, src, attr, vc);
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerHi
Am 20.10.25 um 01:53 schrieb Junjie Cao:
Quoted 24 lines
bit_putcs_aligned()/unaligned() derived the glyph pointer from the character value masked by 0xff/0x1ff, which may exceed the actual font's glyph count and read past the end of the built-in font array. Clamp the index to the actual glyph count before computing the address.
This fixes a global out-of-bounds read reported by syzbot.
Reported-by [email protected]Tested-by [email protected]Signed-off-by Junjie Cao <[email protected]>--- drivers/video/fbdev/core/bitblit.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/video/fbdev/core/bitblit.c +1
-0@@ -79,12 +79,15 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info, struct fb_image *image, u8 *buf, u8 *dst) { u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; +unsigned int charcnt = vc->vc_font.charcount;
drivers/video/fbdev/core/bitblit.c static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info, · line 90
Quoted 10 lines
drivers/video/fbdev/core/bitblit.c +4
-2u32 idx = vc->vc_font.width >>3 ;u8 *src;while (cnt--) { - src = vc->vc_font.data + (scr_readw (s++)& - charmask)*cellsize; +u16 ch =scr_readw (s++) & charmask; +if (ch >= charcnt) + ch =0 ; + src = vc->vc_font.data + (unsigned int )ch * cellsize;
Indention looks off.
Quoted 10 lines
drivers/video/fbdev/core/bitblit.c +1
-0if (attr) {update_attr (buf, src, attr, vc);@@ -112,14 +115,17 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, u8 *dst) {u16 charmask = vc->vc_hi_font_mask ?0x1ff :0xff ; +unsigned int charcnt = vc->vc_font.charcount;u32 shift_low =0 , mod = vc->vc_font.width %8 ;u32 shift_high =8 ;
drivers/video/fbdev/core/bitblit.c static inline void bit_putcs_unaligned(struct vc_data *vc, · line 128
Quoted 10 lines
drivers/video/fbdev/core/bitblit.c +4
-2u32 idx = vc->vc_font.width >>3 ;u8 *src;while (cnt--) { - src = vc->vc_font.data + (scr_readw (s++)& - charmask)*cellsize; +u16 ch =scr_readw (s++) & charmask; +if (ch >= charcnt) + ch =0 ; + src = vc->vc_font.data + (unsigned int )ch * cellsize;
Same here.
Best regards
Thomas
Quoted 3 lines
drivers/video/fbdev/core/bitblit.c +0
-0if (attr) {update_attr (buf, src, attr, vc);
Signature · 7 lines
-- 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)