Skip to content

Commit cedc1b6

Browse files
keeshdeller
authored andcommitted
fbcon: Make sure modelist not set on unregistered console
It looks like attempting to write to the "store_modes" sysfs node will run afoul of unregistered consoles: UBSAN: array-index-out-of-bounds in drivers/video/fbdev/core/fbcon.c:122:28 index -1 is out of range for type 'fb_info *[32]' ... fbcon_info_from_console+0x192/0x1a0 drivers/video/fbdev/core/fbcon.c:122 fbcon_new_modelist+0xbf/0x2d0 drivers/video/fbdev/core/fbcon.c:3048 fb_new_modelist+0x328/0x440 drivers/video/fbdev/core/fbmem.c:673 store_modes+0x1c9/0x3e0 drivers/video/fbdev/core/fbsysfs.c:113 dev_attr_store+0x55/0x80 drivers/base/core.c:2439 static struct fb_info *fbcon_registered_fb[FB_MAX]; ... static signed char con2fb_map[MAX_NR_CONSOLES]; ... static struct fb_info *fbcon_info_from_console(int console) ... return fbcon_registered_fb[con2fb_map[console]]; If con2fb_map contains a -1 things go wrong here. Instead, return NULL, as callers of fbcon_info_from_console() are trying to compare against existing "info" pointers, so error handling should kick in correctly. Reported-by: [email protected] Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Helge Deller <[email protected]>
1 parent 864f996 commit cedc1b6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/video/fbdev/core/fbcon.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,14 @@ static signed char con2fb_map_boot[MAX_NR_CONSOLES];
117117

118118
static struct fb_info *fbcon_info_from_console(int console)
119119
{
120+
signed char fb;
120121
WARN_CONSOLE_UNLOCKED();
121122

122-
return fbcon_registered_fb[con2fb_map[console]];
123+
fb = con2fb_map[console];
124+
if (fb < 0 || fb >= ARRAY_SIZE(fbcon_registered_fb))
125+
return NULL;
126+
127+
return fbcon_registered_fb[fb];
123128
}
124129

125130
static int logo_lines;

0 commit comments

Comments
 (0)