Skip to content

Commit 18c4ef4

Browse files
Junjie650hdeller
authored andcommitted
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. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=793cf822d213be1a74f2 Tested-by: [email protected] Signed-off-by: Junjie Cao <[email protected]> Reviewed-by: Thomas Zimmermann <[email protected]> Signed-off-by: Helge Deller <[email protected]> Cc: [email protected]
1 parent 5f566c0 commit 18c4ef4

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

drivers/video/fbdev/core/bitblit.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
7979
struct fb_image *image, u8 *buf, u8 *dst)
8080
{
8181
u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
82+
unsigned int charcnt = vc->vc_font.charcount;
8283
u32 idx = vc->vc_font.width >> 3;
8384
u8 *src;
8485

8586
while (cnt--) {
86-
src = vc->vc_font.data + (scr_readw(s++)&
87-
charmask)*cellsize;
87+
u16 ch = scr_readw(s++) & charmask;
88+
89+
if (ch >= charcnt)
90+
ch = 0;
91+
src = vc->vc_font.data + (unsigned int)ch * cellsize;
8892

8993
if (attr) {
9094
update_attr(buf, src, attr, vc);
@@ -112,14 +116,18 @@ static inline void bit_putcs_unaligned(struct vc_data *vc,
112116
u8 *dst)
113117
{
114118
u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
119+
unsigned int charcnt = vc->vc_font.charcount;
115120
u32 shift_low = 0, mod = vc->vc_font.width % 8;
116121
u32 shift_high = 8;
117122
u32 idx = vc->vc_font.width >> 3;
118123
u8 *src;
119124

120125
while (cnt--) {
121-
src = vc->vc_font.data + (scr_readw(s++)&
122-
charmask)*cellsize;
126+
u16 ch = scr_readw(s++) & charmask;
127+
128+
if (ch >= charcnt)
129+
ch = 0;
130+
src = vc->vc_font.data + (unsigned int)ch * cellsize;
123131

124132
if (attr) {
125133
update_attr(buf, src, attr, vc);

0 commit comments

Comments
 (0)