mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fbdev: bitblit: bound-check glyph index in bit_putcs*
@ 2025-10-19 23:53 Junjie Cao
  2025-10-20  8:21 ` Thomas Zimmermann
  0 siblings, 1 reply; 2+ messages in thread
From: Junjie Cao @ 2025-10-19 23:53 UTC (permalink / raw)
  To: Simona Vetter, Helge Deller, Zsolt Kajtar
  Cc: Albin Babu Varghese, linux-fbdev, dri-devel, linux-kernel,
	syzkaller-bugs, Junjie Cao, syzbot+793cf822d213be1a74f2

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: syzbot+793cf822d213be1a74f2@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=793cf822d213be1a74f2
Tested-by: syzbot+793cf822d213be1a74f2@syzkaller.appspotmail.com
Signed-off-by: Junjie Cao <junjie.cao@intel.com>
---
 drivers/video/fbdev/core/bitblit.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/core/bitblit.c b/drivers/video/fbdev/core/bitblit.c
index a9ec7f488522..710883831826 100644
--- a/drivers/video/fbdev/core/bitblit.c
+++ b/drivers/video/fbdev/core/bitblit.c
@@ -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);
-- 
2.48.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fbdev: bitblit: bound-check glyph index in bit_putcs*
  2025-10-19 23:53 [PATCH] fbdev: bitblit: bound-check glyph index in bit_putcs* Junjie Cao
@ 2025-10-20  8:21 ` Thomas Zimmermann
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Zimmermann @ 2025-10-20  8:21 UTC (permalink / raw)
  To: Junjie Cao, Simona Vetter, Helge Deller, Zsolt Kajtar
  Cc: Albin Babu Varghese, linux-fbdev, dri-devel, linux-kernel,
	syzkaller-bugs, syzbot+793cf822d213be1a74f2

Hi

Am 20.10.25 um 01:53 schrieb 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: syzbot+793cf822d213be1a74f2@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=793cf822d213be1a74f2
> Tested-by: syzbot+793cf822d213be1a74f2@syzkaller.appspotmail.com
> Signed-off-by: Junjie Cao <junjie.cao@intel.com>
> ---
>   drivers/video/fbdev/core/bitblit.c | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/video/fbdev/core/bitblit.c b/drivers/video/fbdev/core/bitblit.c
> index a9ec7f488522..710883831826 100644
> --- a/drivers/video/fbdev/core/bitblit.c
> +++ b/drivers/video/fbdev/core/bitblit.c
> @@ -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;

Indention looks off.

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

Same here.

Best regards
Thomas

>   
>   		if (attr) {
>   			update_attr(buf, src, attr, vc);

-- 
--
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)



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-20  8:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-19 23:53 [PATCH] fbdev: bitblit: bound-check glyph index in bit_putcs* Junjie Cao
2025-10-20  8:21 ` Thomas Zimmermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®