linux/drivers/video/fbdev/core
Jiri Slaby (SUSE) 00d6a284fc fbcon: always restore the old font data in fbcon_do_set_font()
Commit a5a923038d (fbdev: fbcon: Properly revert changes when
vc_resize() failed) started restoring old font data upon failure (of
vc_resize()). But it performs so only for user fonts. It means that the
"system"/internal fonts are not restored at all. So in result, the very
first call to fbcon_do_set_font() performs no restore at all upon
failing vc_resize().

This can be reproduced by Syzkaller to crash the system on the next
invocation of font_get(). It's rather hard to hit the allocation failure
in vc_resize() on the first font_set(), but not impossible. Esp. if
fault injection is used to aid the execution/failure. It was
demonstrated by Sirius:
  BUG: unable to handle page fault for address: fffffffffffffff8
  #PF: supervisor read access in kernel mode
  #PF: error_code(0x0000) - not-present page
  PGD cb7b067 P4D cb7b067 PUD cb7d067 PMD 0
  Oops: 0000 [#1] PREEMPT SMP KASAN
  CPU: 1 PID: 8007 Comm: poc Not tainted 6.7.0-g9d1694dc91ce #20
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
  RIP: 0010:fbcon_get_font+0x229/0x800 drivers/video/fbdev/core/fbcon.c:2286
  Call Trace:
   <TASK>
   con_font_get drivers/tty/vt/vt.c:4558 [inline]
   con_font_op+0x1fc/0xf20 drivers/tty/vt/vt.c:4673
   vt_k_ioctl drivers/tty/vt/vt_ioctl.c:474 [inline]
   vt_ioctl+0x632/0x2ec0 drivers/tty/vt/vt_ioctl.c:752
   tty_ioctl+0x6f8/0x1570 drivers/tty/tty_io.c:2803
   vfs_ioctl fs/ioctl.c:51 [inline]
  ...

So restore the font data in any case, not only for user fonts. Note the
later 'if' is now protected by 'old_userfont' and not 'old_data' as the
latter is always set now. (And it is supposed to be non-NULL. Otherwise
we would see the bug above again.)

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Fixes: a5a923038d ("fbdev: fbcon: Properly revert changes when vc_resize() failed")
Reported-and-tested-by: Ubisectech Sirius <bugreport@ubisectech.com>
Cc: Ubisectech Sirius <bugreport@ubisectech.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Helge Deller <deller@gmx.de>
Cc: linux-fbdev@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20240208114411.14604-1-jirislaby@kernel.org
History 2024-02-26 16:47:02 +01:00
..
bitblit.c fbcon: Fix null-ptr-deref in soft_cursor 2023-05-27 19:18:59 +02:00
cfbcopyarea.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01:00
cfbfillrect.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01:00
cfbimgblt.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01:00
fb_backlight.c fbdev/core: Move framebuffer and backlight helpers into separate files 2023-06-27 09:58:51 +02:00
fb_chrdev.c fbdev: Remove default file-I/O implementations 2023-11-29 12:20:53 +01:00
fb_cmdline.c fbdev: Handle video= parameter in video/cmdline.c 2023-02-20 14:56:48 +01:00
fb_ddc.c fbdev: remove I2C_CLASS_DDC support 2024-01-18 21:10:41 +01:00
fb_defio.c fbdev fixes and cleanups for 6.8-rc1: 2024-01-12 14:38:08 -08:00
fb_draw.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
fb_info.c fbdev: Document that framebuffer_alloc() returns zero'ed data 2023-07-24 16:50:39 +02:00
fb_internal.h fbdev/core: Move logo functions into separate source file 2023-09-11 15:12:35 +02:00
fb_io_fops.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01: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 video: fbdev: core: Fix kernel-doc warnings in fbmon + fb_notify 2020-12-08 18:31:56 +01:00
fb_procfs.c fbdev/core: Move procfs code to separate file 2023-06-27 09:58:51 +02:00
fb_sys_fops.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01:00
fbcmap.c fbdev: zero-fill colormap in fbcmap.c 2021-04-10 11:12:08 +02:00
fbcon.c fbcon: always restore the old font data in fbcon_do_set_font() 2024-02-26 16:47:02 +01:00
fbcon.h fbcon: Replace FBCON_FLAGS_INIT with a boolean 2022-04-07 16:52:13 +02:00
fbcon_ccw.c fbcon: Add option to enable legacy hardware acceleration 2022-02-02 15:16:26 +01:00
fbcon_cw.c fbcon: Add option to enable legacy hardware acceleration 2022-02-02 15:16:26 +01:00
fbcon_rotate.c fbcon: Drop EXPORT_SYMBOL 2020-11-17 11:00:43 +01:00
fbcon_rotate.h fbcon: Add option to enable legacy hardware acceleration 2022-02-02 15:16:26 +01:00
fbcon_ud.c fbcon: Add option to enable legacy hardware acceleration 2022-02-02 15:16:26 +01:00
fbcvt.c video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name() 2022-01-30 21:19:22 +01:00
fbmem.c fbdev/core: Clean up include statements in fbmem.c 2023-09-11 15:12:38 +02:00
fbmon.c fbdev: fbmon: fix function name in kernel-doc 2023-01-16 09:37:31 +01:00
fbsysfs.c fbdev/core: Use list_for_each_entry() helper 2023-08-31 22:54:34 +02:00
Kconfig fbdev: Remove default file-I/O implementations 2023-11-29 12:20:53 +01:00
Makefile fbdev: Rename FB_SYS_FOPS token to FB_SYSMEM_FOPS 2023-11-29 12:20:42 +01:00
modedb.c fbdev/core: Use list_for_each_entry() helper 2023-08-31 22:54:34 +02:00
softcursor.c fbcon: Drop EXPORT_SYMBOL 2020-11-17 11:00:43 +01:00
svgalib.c drm/i915: Move abs_diff() to math.h 2023-08-18 10:18:59 -07:00
syscopyarea.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01:00
sysfillrect.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01:00
sysimgblt.c fbdev: Warn on incorrect framebuffer access 2023-11-29 12:20:50 +01:00
tileblit.c Revert "fbdev: Garbage collect fbdev scrolling acceleration, part 1 (from TODO list)" 2022-02-02 15:14:56 +01:00