fbdev: bitblit: bound-check glyph index in bit_putcs*
Subsystems (5)
PATCH v2 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.
---
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changes
drivers/video/fbdev/core/bitblit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/video/fbdev/core/bitblit.c +12 -4
@@ -79,12 +79,16 @@ 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 +116,18 @@ 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
Hi
Am 20.10.25 um 15:47 schrieb Junjie Cao:
Quoted 11 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]>
Thanks for fixing the bug.
Best regards
Thomas
Quoted 53 lines
---
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changesdrivers/video/fbdev/core/bitblit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/video/fbdev/core/bitblit.c +12
-4@@ -79,12 +79,16 @@ 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 +116,18 @@ 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 · 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)
Quoted 16 lines · Thomas Zimmermann
Hi
Am 20.10.25 um 15:47 schrieb Junjie Cao:
Quoted 11 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]>Reviewed-by Thomas Zimmermann <[email protected]>
...
Quoted 7 lines
Quoted 7 lines
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changes
drivers/video/fbdev/core/bitblit.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)
applied.
Thanks!
Helge
Dear linux-fbdev, stable,
Quoted 11 lines · Junjie Cao
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]>
This commit is applied to v5.10.247 and causes a regression: when switching VT with ctrl-alt-f2 the screen is blank or completely filled with angle characters, then new text is not appearing (or not visible).
This commit is found with git bisect from v5.10.246 to v5.10.247:
0998a6cb232674408a03e8561dc15aa266b2f53b is the first bad commit commit 0998a6cb232674408a03e8561dc15aa266b2f53b
Author: Junjie Cao <[email protected]>
AuthorDate: 2025-10-20 21:47:01 +0800
Commit: Greg Kroah-Hartman <[email protected]>
CommitDate: 2025-12-07 06:08:07 +0900
fbdev: bitblit: bound-check glyph index in bit_putcs*
commit 18c4ef4e765a798b47980555ed665d78b71aeadf upstream.
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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
The minimal reproducer in cli, after kernel is booted:
date >/dev/tty2; chvt 2
and the date does not appear.
Thanks,
#regzbot introduced: 0998a6cb232674408a03e8561dc15aa266b2f53b
Quoted 56 lines
---
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changesdrivers/video/fbdev/core/bitblit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/video/fbdev/core/bitblit.c +12
-4@@ -79,12 +79,16 @@ 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 +116,18 @@ 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
Dear linux-fbdev, stable,
Quoted 69 lines · Vitaly Chikunov
Quoted 11 lines · Junjie Cao
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]>This commit is applied to v5.10.247 and causes a regression: when switching VT with ctrl-alt-f2 the screen is blank or completely filled with angle characters, then new text is not appearing (or not visible).
This commit is found with git bisect from v5.10.246 to v5.10.247:
0998a6cb232674408a03e8561dc15aa266b2f53bis the first bad commit commit0998a6cb232674408a03e8561dc15aa266b2f53b
Author: Junjie Cao <[email protected]>
AuthorDate: 2025-10-20 21:47:01 +0800
Commit: Greg Kroah-Hartman <[email protected]>
CommitDate: 2025-12-07 06:08:07 +0900fbdev: bitblit: bound-check glyph index in bit_putcs*
commit
18c4ef4e765a798b47980555ed665d78b71aeadfupstream.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]>Reviewed-by Thomas Zimmermann <[email protected]>Signed-off-by Helge Deller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>drivers/video/fbdev/core/bitblit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)The minimal reproducer in cli, after kernel is booted:
date >/dev/tty2; chvt 2
and the date does not appear.
Thanks,
#regzbot introduced:
0998a6cb232674408a03e8561dc15aa266b2f53bQuoted 9 lines
---
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changesdrivers/video/fbdev/core/bitblit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
Quoted 9 lines
drivers/video/fbdev/core/bitblit.c static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info, · line 82
Quoted 9 lines
drivers/video/fbdev/core/bitblit.c +1
-0@@ -79,12 +79,16 @@ 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;
Perhaps, vc->vc_font.charcount (which is relied upon in the following comparison) is not always set correctly in v5.10.247. At least two commits that set vc_font.charcount are missing from v5.10.247:
a1ac250a82a5 ("fbcon: Avoid using FNTCHARCNT() and hard-coded built-in font charcount") a5a923038d70 ("fbdev: fbcon: Properly revert changes when vc_resize() failed")
Thanks,
Quoted 38 lines
Quoted 38 lines
drivers/video/fbdev/core/bitblit.c +11
-4u32 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 +116,18 @@ 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
Quoted 86 lines · Vitaly Chikunov
Dear linux-fbdev, stable,
Quoted 69 lines · Vitaly Chikunov
Quoted 11 lines · Junjie Cao
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]>This commit is applied to v5.10.247 and causes a regression: when switching VT with ctrl-alt-f2 the screen is blank or completely filled with angle characters, then new text is not appearing (or not visible).
This commit is found with git bisect from v5.10.246 to v5.10.247:
0998a6cb232674408a03e8561dc15aa266b2f53bis the first bad commit commit0998a6cb232674408a03e8561dc15aa266b2f53b
Author: Junjie Cao <[email protected]>
AuthorDate: 2025-10-20 21:47:01 +0800
Commit: Greg Kroah-Hartman <[email protected]>
CommitDate: 2025-12-07 06:08:07 +0900fbdev: bitblit: bound-check glyph index in bit_putcs*
commit
18c4ef4e765a798b47980555ed665d78b71aeadfupstream.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]>Reviewed-by Thomas Zimmermann <[email protected]>Signed-off-by Helge Deller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
drivers/video/fbdev/core/bitblit.c| 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)The minimal reproducer in cli, after kernel is booted:
date >/dev/tty2; chvt 2and the date does not appear.
Thanks,
#regzbot introduced:
0998a6cb232674408a03e8561dc15aa266b2f53bQuoted 9 lines
---
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changesdrivers/video/fbdev/core/bitblit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)Quoted 9 lines
drivers/video/fbdev/core/bitblit.c static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info, · line 82
Quoted 9 lines
drivers/video/fbdev/core/bitblit.c +1
-0@@ -79,12 +79,16 @@ 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;Perhaps,
vc->vc_font.charcount(which is relied upon in the following comparison) is not always set correctly in v5.10.247. At least two commits that set vc_font.charcount are missing from v5.10.247:
Quoted 4 lines
a1ac250a82a5("fbcon: Avoid usingFNTCHARCNT()and hard-coded built-in font charcount")a5a923038d70("fbdev: fbcon: Properly revert changes whenvc_resize()failed")Thanks,
I was just about to report this.
I found two ways to fix this bug. One is to revert this patch; the other is to apply the following 3 patches, which are already present in 5.11 and later:
7a089ec7d77fe7d50f6bb7b178fa25eec9fd822b
console: Delete unused con_font_copy() callback implementations
4ee573086bd88ff3060dda07873bf755d332e9ba
Fonts: Add charcount field to font_desc
a1ac250a82a5e97db71f14101ff7468291a6aaef
fbcon: Avoid using FNTCHARCNT() and hard-coded built-in font charcount
(Oh, by the way, this same regression also affects 5.4.302, and the same 3 patches fix the regression on 5.4 as well, once you manually fix merge conflicts. Maybe it would be better to backport other additional commits instead of fixing the merge conflicts manually, but since 5.4 is now EOL I didn't dig that deep.)
Once these 3 patches are applied, I wonder if a5a923038d70 now becomes necessary for 5.10.y. For what it's worth, it applies fine and the resulting kernel seems to run OK in brief testing.
Signature · 1 line
-Barry K. Nathan <[email protected]>
[Top posting to make this easy processable]
TWIMC, Ben (now CCed) meanwhile reported the problem as well:
https://lore.kernel.org/all/[email protected]/
There he wrote
"""
This can be fixed by backporting the following commits from 5.11:
7a089ec7d77f console: Delete unused con_font_copy() callback implementations 259a252c1f4e console: Delete dummy con_font_set() and con_font_default() callback implementations4ee573086bd8 Fonts: Add charcount field to font_desc 4497364e5f61 parisc/sticore: Avoid hard-coding built-in font charcount a1ac250a82a5 fbcon: Avoid using FNTCHARCNT() and hard-coded built-in font charcount
These all apply without fuzz and builds cleanly for x86_64 and parisc64. """
Ciao, Thorsten
Quoted 130 lines · Barry K. Nathan
Quoted 96 lines · Vitaly Chikunov
Dear linux-fbdev, stable,
Quoted 77 lines · Vitaly Chikunov
Quoted 6 lines · Junjie Cao
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.Quoted 6 lines
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]>This commit is applied to v5.10.247 and causes a regression: when switching VT with ctrl-alt-f2 the screen is blank or completely filled with angle characters, then new text is not appearing (or not visible).
This commit is found with git bisect from v5.10.246 to v5.10.247:
0998a6cb232674408a03e8561dc15aa266b2f53bis the first bad commit commit0998a6cb232674408a03e8561dc15aa266b2f53bAuthor: Junjie Cao <[email protected]>
AuthorDate: 2025-10-20 21:47:01 +0800
Commit: Greg Kroah-Hartman <[email protected]>
CommitDate: 2025-12-07 06:08:07 +0900fbdev: bitblit: bound-check glyph index in bit_putcs*
commit
18c4ef4e765a798b47980555ed665d78b71aeadfupstream.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]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]>Signed-off-by Greg Kroah-Hartman <[email protected]>
drivers/video/fbdev/core/bitblit.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)The minimal reproducer in cli, after kernel is booted:
date >/dev/tty2; chvt 2
and the date does not appear.
Thanks,
#regzbot introduced:
0998a6cb232674408a03e8561dc15aa266b2f53bQuoted 11 lines
---
v1: https://lore.kernel.org/linux-fbdev/5d237d1a-a528-4205-
[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changes
drivers/video/fbdev/core/bitblit.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)Quoted 11 lines
drivers/video/fbdev/core/bitblit.c static inline void bit_putcs_aligned(struct · line 83
Quoted 11 lines
drivers/video/ renamed from drivers/video/fbdev/core/bitblit.c +0
-0
fbdev/core/bitblit.c
index9d2e59796c3e..085ffb44c51a100644drivers/video/fbdev/core/bitblit.c +1
-0@@ -79,12 +79,16 @@ 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;Perhaps,
vc->vc_font.charcount(which is relied upon in the following comparison) is not always set correctly in v5.10.247. At least two commits that set vc_font.charcount are missing from v5.10.247:Quoted 6 lines
a1ac250a82a5("fbcon: Avoid usingFNTCHARCNT()and hard-coded built-in font charcount")
a5a923038d70("fbdev: fbcon: Properly revert changes whenvc_resize()failed")Thanks,
I was just about to report this.
I found two ways to fix this bug. One is to revert this patch; the other is to apply the following 3 patches, which are already present in 5.11 and later:
7a089ec7d77fe7d50f6bb7b178fa25eec9fd822b
console: Delete unusedcon_font_copy()callback implementations
4ee573086bd88ff3060dda07873bf755d332e9ba
Fonts: Add charcount field tofont_desc
a1ac250a82a5e97db71f14101ff7468291a6aaef
fbcon: Avoid usingFNTCHARCNT()and hard-coded built-in font charcount(Oh, by the way, this same regression also affects 5.4.302, and the same 3 patches fix the regression on 5.4 as well, once you manually fix merge conflicts. Maybe it would be better to backport other additional commits instead of fixing the merge conflicts manually, but since 5.4 is now EOL I didn't dig that deep.)
Once these 3 patches are applied, I wonder if
a5a923038d70now becomes necessary for 5.10.y. For what it's worth, it applies fine and the resulting kernel seems to run OK in brief testing.
Quoted 111 lines · Vitaly Chikunov
Dear linux-fbdev, stable,
Quoted 11 lines · Junjie Cao
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]>This commit is applied to v5.10.247 and causes a regression: when switching VT with ctrl-alt-f2 the screen is blank or completely filled with angle characters, then new text is not appearing (or not visible).
This commit is found with git bisect from v5.10.246 to v5.10.247:
0998a6cb232674408a03e8561dc15aa266b2f53bis the first bad commit commit0998a6cb232674408a03e8561dc15aa266b2f53b
Author: Junjie Cao <[email protected]>
AuthorDate: 2025-10-20 21:47:01 +0800
Commit: Greg Kroah-Hartman <[email protected]>
CommitDate: 2025-12-07 06:08:07 +0900fbdev: bitblit: bound-check glyph index in bit_putcs*
commit
18c4ef4e765a798b47980555ed665d78b71aeadfupstream.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]>Reviewed-by Thomas Zimmermann <[email protected]>Signed-off-by Helge Deller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
drivers/video/fbdev/core/bitblit.c| 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)The minimal reproducer in cli, after kernel is booted:
date >/dev/tty2; chvt 2and the date does not appear.
Thanks,
#regzbot introduced:
0998a6cb232674408a03e8561dc15aa266b2f53bQuoted 51 lines
---
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changesdrivers/video/fbdev/core/bitblit.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/video/fbdev/core/bitblit.c +12
-4@@ -79,12 +79,16 @@ 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 +116,18 @@ 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;
Quoted 5 lines
Quoted 5 lines
drivers/video/fbdev/core/bitblit.c +0
-0if (attr) {update_attr (buf, src, attr, vc);Signature · 1 line
2.48.1
I have done the same bisecting work, too bad I did not notice Vitaly's work earlier :-(
There is a "cheap" workaround for systems before 5.11, (not addressing the root issue but) working:
drivers/video/fbdev/core/bitblit.c +0 -0
@@ -86,7 +86,7 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info,
while (cnt--) {
u16 ch = scr_readw(s++) & charmask;
- if (ch >= charcnt)
+ if (charcnt && ch >= charcnt)
ch = 0;
src = vc->vc_font.data + (unsigned int)ch * cellsize;
@@ -125,7 +125,7 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, while (cnt--) {
u16 ch = scr_readw(s++) & charmask;
- if (ch >= charcnt)
+ if (charcnt && ch >= charcnt)
ch = 0;
src = vc->vc_font.data + (unsigned int)ch * cellsize;
I will try next to go full backport from 5.11 as Thorsten has suggested.
However the bigger problem is that the fbdev patch has landed in the 5.4.302 EOL, and essentially the 5.4 EOL kernel is now hanging broken :-(
Thanks, Woody
Quoted 143 lines · Woody Suwalski
Quoted 106 lines · Vitaly Chikunov
Dear linux-fbdev, stable,
Quoted 11 lines · Junjie Cao
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]>This commit is applied to v5.10.247 and causes a regression: when switching VT with ctrl-alt-f2 the screen is blank or completely filled with angle characters, then new text is not appearing (or not visible).
This commit is found with git bisect from v5.10.246 to v5.10.247:
0998a6cb232674408a03e8561dc15aa266b2f53bis the first bad commit commit0998a6cb232674408a03e8561dc15aa266b2f53bAuthor: Junjie Cao <[email protected]>
AuthorDate: 2025-10-20 21:47:01 +0800
Commit: Greg Kroah-Hartman <[email protected]>
CommitDate: 2025-12-07 06:08:07 +0900fbdev: bitblit: bound-check glyph index in bit_putcs*
commit
18c4ef4e765a798b47980555ed665d78b71aeadfupstream.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]>Reviewed-by Thomas Zimmermann <[email protected]>Signed-off-by Helge Deller <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
drivers/video/fbdev/core/bitblit.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)The minimal reproducer in cli, after kernel is booted:
date >/dev/tty2; chvt 2
and the date does not appear.
Thanks,
#regzbot introduced:
0998a6cb232674408a03e8561dc15aa266b2f53bQuoted 46 lines
---
v1: https://lore.kernel.org/linux-fbdev/[email protected]/
v1 -> v2:
- Fix indentation and add blank line after declarations with the .pl helper
- No functional changes
drivers/video/fbdev/core/bitblit.c| 16 ++++++++++++----1 file changed, 12 insertions(+), 4 deletions(-)drivers/video/fbdev/core/bitblit.c +9
-4@@ -79,12 +79,16 @@ 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 +116,18 @@ static inline void bit_putcs_unaligned(structvc_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; +Quoted 8 lines
Quoted 8 lines
drivers/video/fbdev/core/bitblit.c +3
-0+ 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.1I have done the same bisecting work, too bad I did not notice Vitaly's work earlier :-(
There is a "cheap" workaround for systems before 5.11, (not addressing the root issue but) working:
drivers/video/fbdev/core/bitblit.c +2
-2@@ -86,7 +86,7 @@ static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info *info, while (cnt--) { u16 ch = scr_readw(s++) & charmask; - if (ch >= charcnt) + if (charcnt && ch >= charcnt) ch = 0; src = vc->vc_font.data + (unsigned int)ch * cellsize;@@ -125,7 +125,7 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, while (cnt--) { u16 ch = scr_readw(s++) & charmask; - if (ch >= charcnt) + if (charcnt && ch >= charcnt) ch = 0; src = vc->vc_font.data + (unsigned int)ch * cellsize;
Quoted 6 lines
I will try next to go full backport from 5.11 as Thorsten has suggested.
However the bigger problem is that the fbdev patch has landed in the 5.4.302 EOL, and essentially the 5.4 EOL kernel is now hanging broken :-(
Thanks, Woody
I have tested the solution of backporting the series of patches from 5.11, it seems to be working OK.
However for the soon-to-be-EOL 5.10 and already EOL'ed 5.4 I would suggest a simpler solution where we replace most of the logic from 5.11 with a hardcoded charcnt=256, if charcnt not set. This would take advantage of the bugfix from Junjie, and be a minimal change for the 5.10 kernel (works on 5.4 as well)
drivers/video/fbdev/core/bitblit.c 2026-01-10 16:32:51.356236549 -0500 renamed from drivers/video/fbdev/core/bitblit.c 2026-01-10 16:28:37.438569812 -0500 +0 -0
@@ -86,6 +86,8 @@ static inline void bit_putcs_aligned(str
while (cnt--) {
u16 ch = scr_readw(s++) & charmask;
+ if (charcnt == 0)
+ charcnt = 256;
if (ch >= charcnt)
ch = 0;
src = vc->vc_font.data + (unsigned int)ch * cellsize; @@ -125,6 +127,8 @@ static inline void bit_putcs_unaligned(s while (cnt--) {
u16 ch = scr_readw(s++) & charmask;
+ if (charcnt == 0)
+ charcnt = 256;
if (ch >= charcnt)
ch = 0;
src = vc->vc_font.data + (unsigned int)ch * cellsize;
Thanks, Woody