Skip to contentSkip to conversation

fbdev: bitblit: bound-check glyph index in bit_putcs*

PATCH Superseded Junjie Cao 2 participants 2 messages Oct 19, 2025 – Oct 20, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Junjie Cao

author
#0 lore raw

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
index a9ec7f488522..710883831826 100644
@@ -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
#1 lore raw

Hi

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.

---
  drivers/video/fbdev/core/bitblit.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
drivers/video/fbdev/core/bitblit.c +1 -0
index a9ec7f488522..710883831826 100644
@@ -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 -2
  	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;

Indention looks off.

Quoted 10 lines
drivers/video/fbdev/core/bitblit.c +1 -0
  		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;

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 -2
  	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;

Same here.

Best regards
Thomas

Quoted 3 lines
drivers/video/fbdev/core/bitblit.c +0 -0
  		if (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)