linux/drivers/video/fbdev/core
Thomas Zimmermann eb76d0f555 drm, fbcon, vga_switcheroo: Avoid race condition in fbcon setup
Protect vga_switcheroo_client_fb_set() with console lock. Avoids OOB
access in fbcon_remap_all(). Without holding the console lock the call
races with switching outputs.

VGA switcheroo calls fbcon_remap_all() when switching clients. The fbcon
function uses struct fb_info.node, which is set by register_framebuffer().
As the fb-helper code currently sets up VGA switcheroo before registering
the framebuffer, the value of node is -1 and therefore not a legal value.
For example, fbcon uses the value within set_con2fb_map() [1] as an index
into an array.

Moving vga_switcheroo_client_fb_set() after register_framebuffer() can
result in VGA switching that does not switch fbcon correctly.

Therefore move vga_switcheroo_client_fb_set() under fbcon_fb_registered(),
which already holds the console lock. Fbdev calls fbcon_fb_registered()
from within register_framebuffer(). Serializes the helper with VGA
switcheroo's call to fbcon_remap_all().

Although vga_switcheroo_client_fb_set() takes an instance of struct fb_info
as parameter, it really only needs the contained fbcon state. Moving the
call to fbcon initialization is therefore cleaner than before. Only amdgpu,
i915, nouveau and radeon support vga_switcheroo. For all other drivers,
this change does nothing.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://elixir.bootlin.com/linux/v6.17/source/drivers/video/fbdev/core/fbcon.c#L2942 # [1]
Fixes: 6a9ee8af34 ("vga_switcheroo: initial implementation (v15)")
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Cc: dri-devel@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Cc: amd-gfx@lists.freedesktop.org
Cc: linux-fbdev@vger.kernel.org
Cc: <stable@vger.kernel.org> # v2.6.34+
Link: https://patch.msgid.link/20251105161549.98836-1-tzimmermann@suse.de
2025-11-25 09:08:32 +01:00
..
Kconfig fbdev fixes and cleanups for 6.17-rc1: 2025-08-02 09:58:11 -07:00
Makefile
bitblit.c fbdev: bitblit: bound-check glyph index in bit_putcs* 2025-10-28 22:59:19 +01: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
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: Include <linux/export.h> 2025-06-16 09:06:19 +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
fb_io_fops.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
fb_logo.c
fb_notify.c
fb_procfs.c
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.c drm, fbcon, vga_switcheroo: Avoid race condition in fbcon setup 2025-11-25 09:08:32 +01:00
fbcon.h
fbcon_ccw.c
fbcon_cw.c
fbcon_rotate.c
fbcon_rotate.h
fbcon_ud.c
fbcvt.c fbdev: core: fbcvt: avoid division by 0 in fb_cvt_hperiod() 2025-05-31 10:24:02 +02:00
fbmem.c fbcon: Set fb_display[i]->mode to NULL when the mode is released 2025-10-28 22:59:19 +01:00
fbmon.c fbdev: Use string choices helpers 2025-09-30 23:21:34 +02:00
fbsysfs.c fbdev: Track display blanking state 2025-04-10 10:38:57 +01:00
modedb.c fbdev: Include <linux/export.h> 2025-06-16 09:06:19 +02:00
softcursor.c
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