linux/drivers/video/fbdev/core
Rik van Riel e033cbf397 fbdev: bitblit: bound-check glyph index in bit_cursor()
bit_cursor() fetches the glyph under the cursor with

	c = scr_readw(vc_pos);
	src = vc_font.data + ((c & charmask) * w * height);

where charmask is 0x1ff when vc_hi_font_mask is set. The screen buffer
value comes directly from scr_readw() and may be larger than the current
font's glyph count.

Syzkaller triggers this via vcs_write(). The Call Trace shows
vcs_write() in vc_screen.c writing an arbitrary 16-bit value with
writev() to /dev/vcsa, which vcs_write_buf() in vc_screen.c stores via
vcs_scr_writew() without checking charcount. The stored value is later
read in bit_cursor() in bitblit.c.

When the font is changed from a font with 512 glyphs to a font with
256 glyphs, the screen buffer can retain characters with the high
bit set from the previous mode, which could also produce the same
out-of-bounds access.

  BUG: KASAN: global-out-of-bounds in soft_cursor+0x378/0x6bc drivers/video/fbdev/core/softcursor.c:70
  Read of size 16 at addr ffff800086c57970

  Call Trace:
   soft_cursor+0x378/0x6bc drivers/video/fbdev/core/softcursor.c:70
   bit_cursor+0xa90/0x1108 drivers/video/fbdev/core/bitblit.c:365
   fbcon_cursor+0x344/0x498 drivers/video/fbdev/core/fbcon.c:1427
   hide_cursor+0xdc/0x2d0 drivers/tty/vt/vt.c:883
   update_region+0x100/0x18c drivers/tty/vt/vt.c:669
   vcs_write+0x8ec/0xaf0 drivers/tty/vt/vc_screen.c:685

bit_putcs_aligned() and bit_putcs_unaligned() already clamp the glyph
index to vc_font.charcount. Apply the same clamp in bit_cursor() after
extracting the attribute and masking, before indexing fontdata.

The fix completes the bounds checking started in commit 18c4ef4e76
("fbdev: bitblit: bound-check glyph index in bit_putcs*"), which missed
the cursor path.

This change should be safe because the clamp reuses the existing
contract from fbcon: charcount is maintained under console_lock in
con_font_set() and fbcon_font_set(), and hi_font_mask is cleared when
switching from 512 to 256 glyphs. When stale screen data with high bits
remains after a font switch, or when vcs_write() stores an arbitrary
value, clamping the index to 0 prevents the out-of-bounds read without
changing cursor semantics — the same fallback bit_putcs uses.

Reported-by: syzbot+61b1db46218109869c14@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=61b1db46218109869c14
Link: https://lore.kernel.org/all/6a75205c.01d0871a.3a0d52.0032.GAE@google.com/
Fixes: 18c4ef4e76 ("fbdev: bitblit: bound-check glyph index in bit_putcs*")
Cc: stable@vger.kernel.org
Assisted-by: Hermes:muse-spark-1.2 syzkaller
Signed-off-by: Rik van Riel <riel@surriel.com>
Signed-off-by: Helge Deller <deller@gmx.de>
2026-08-08 08:08:58 +02:00
..
bitblit.c fbdev: bitblit: bound-check glyph index in bit_cursor() 2026-08-08 08:08:58 +02:00
cfbcopyarea.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
cfbfillrect.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
cfbimgblt.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
cfbmem.h fbdev: Refactoring the fbcon packed pixel drawing routines 2025-03-26 22:39:21 +01:00
fb_backlight.c backlight: Replace fb events with a dedicated function call 2025-04-10 10:39:03 +01:00
fb_chrdev.c fbdev: Do not export fbcon from fbdev 2026-06-09 16:00:11 +02:00
fb_cmdline.c fbdev: Fix logic error in "offb" name match 2025-10-10 00:31:13 +02:00
fb_copyarea.h fbdev: Refactoring the fbcon packed pixel drawing routines 2025-03-26 22:39:21 +01:00
fb_ddc.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
fb_defio.c fbdev: defio: Remove duplicate include of linux/module.h 2026-04-28 14:18:51 +02:00
fb_draw.h fbdev: Refactoring the fbcon packed pixel drawing routines 2025-03-26 22:39:21 +01:00
fb_fillrect.h fbdev: core: Fix ubsan warning in pixel_to_pat 2025-09-30 23:21:34 +02:00
fb_imageblit.h fbdev: Refactoring the fbcon packed pixel drawing routines 2025-03-26 22:39:21 +01:00
fb_info.c fbdev: Track display blanking state 2025-04-10 10:38:57 +01:00
fb_internal.h fbdev: Wrap user-invoked calls to fb_blank() in helper 2026-06-09 16:00:10 +02:00
fb_io_fops.c fbdev: core: Fix pointer desynchronization in fb_io_read() 2026-08-08 08:08:58 +02:00
fb_logo.c fbdev/core: Remove empty internal helpers from fb_logo.c 2023-09-11 15:12:37 +02:00
fb_notify.c
fb_procfs.c fbdev/core: Move procfs code to separate file 2023-06-27 09:58:51 +02:00
fb_sys_fops.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
fbcmap.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
fbcon_ccw.c fbcon: Put font-rotation state into separate struct 2026-04-07 17:38:07 +02:00
fbcon_cw.c fbcon: Put font-rotation state into separate struct 2026-04-07 17:38:07 +02:00
fbcon_rotate.c fbcon: Put font-rotation state into separate struct 2026-04-07 17:38:07 +02:00
fbcon_rotate.h lib/fonts: Implement glyph rotation 2026-04-07 17:38:07 +02:00
fbcon_ud.c fbcon: Put font-rotation state into separate struct 2026-04-07 17:38:07 +02:00
fbcon.c fbdev: Fix out-of-bounds access when rotating console after font resize 2026-08-08 08:08:58 +02:00
fbcon.h fbdev: Do not export fbcon from fbdev 2026-06-09 16:00:11 +02:00
fbcvt.c fbdev: core: fbcvt: avoid division by 0 in fb_cvt_hperiod() 2025-05-31 10:24:02 +02:00
fbmem.c fbdev: clear fb_info->mode before deleting a videomode 2026-08-08 08:08:58 +02:00
fbmon.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
fbsysfs.c fbdev: serialize mode sysfs access with lock_fb_info() 2026-08-08 08:08:58 +02:00
Kconfig fbdev: Turn FB_MODE_HELPERS into an internal config option 2025-09-23 15:56:04 +02:00
Makefile fbdev: Rename FB_SYS_FOPS token to FB_SYSMEM_FOPS 2023-11-29 12:20:42 +01:00
modedb.c fbdev: modedb: Fix misaligned fields in the 1920x1080-60 mode 2026-06-12 23:23:43 +02:00
softcursor.c fbcon: Rename struct fbcon_ops to struct fbcon_par 2025-09-19 10:04:02 +02:00
svgalib.c fbdev fixes and cleanups for 6.17-rc1: 2025-08-02 09:58:11 -07:00
syscopyarea.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
sysfillrect.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
sysimgblt.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
sysmem.h fbdev: Refactoring the fbcon packed pixel drawing routines 2025-03-26 22:39:21 +01:00
tileblit.c fbcon: Move fbcon callbacks into struct fbcon_bitops 2025-09-19 10:04:05 +02:00