From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 739B319049B; Mon, 23 Jun 2025 21:49:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715356; cv=none; b=biAQmYn6QuvTqVeWphT6JLssK2juxMnT4W5+INQsunie5QW16vSZnilOKlovOVOb8PWaiMI7BHKpus5HP5aACwrOKnytofkhrkWdRF/cx48FAT47gSirmuF/dpISxUkhjwpvav8vbeYEqmR8cctrwiRHjR5eQUaOFmsg5y5UOMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750715356; c=relaxed/simple; bh=NVH0hNQyImhhgVeS7Bi7nLP7bG+VazgxHa8c72NGSY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HtLD3yLhaYYvPp5QIUACtx3t3K3gBenopDWSG6WvsWF7227/ytUx/fUDUj+4txETU3xlu90ve24ARLSz1AQogjW4x7219ewMc8f5vdsEYgqzbHmMYYl+r1S2nYvSICbpM4P9K+bRn2051fOLP2CxBV7B/T+gyB0H0u6keyeoyDc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tkY3/JYu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tkY3/JYu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C02DC4CEED; Mon, 23 Jun 2025 21:49:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750715356; bh=NVH0hNQyImhhgVeS7Bi7nLP7bG+VazgxHa8c72NGSY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tkY3/JYufSU7yFQHOuL15iSzjQCDTY9HZzi0yFXKUHID4E3woreZ1bmfw0m3grPcz CJZ01TSD9YrZvZtyWwZpVGXzzPQ3CxmcPbV8vMmSzWY1hWsqh5bqQtqcOAhIxARoAp xdTBWOluw6AJYKZx/awElQVs8n65Djq6ZkJwI58E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+a7d4444e7b6e743572f7@syzkaller.appspotmail.com, Kees Cook , Helge Deller , Sasha Levin Subject: [PATCH 6.6 194/290] fbcon: Make sure modelist not set on unregistered console Date: Mon, 23 Jun 2025 15:07:35 +0200 Message-ID: <20250623130632.691117044@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130626.910356556@linuxfoundation.org> References: <20250623130626.910356556@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook [ Upstream commit cedc1b63394a866bf8663a3e40f4546f1d28c8d8 ] 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: syzbot+a7d4444e7b6e743572f7@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/679d0a8f.050a0220.163cdc.000c.GAE@google.com/ Signed-off-by: Kees Cook Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- drivers/video/fbdev/core/fbcon.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index 7a6f9a3cb3ba3..75996ef9992e4 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -115,9 +115,14 @@ static signed char con2fb_map_boot[MAX_NR_CONSOLES]; static struct fb_info *fbcon_info_from_console(int console) { + signed char fb; WARN_CONSOLE_UNLOCKED(); - return fbcon_registered_fb[con2fb_map[console]]; + fb = con2fb_map[console]; + if (fb < 0 || fb >= ARRAY_SIZE(fbcon_registered_fb)) + return NULL; + + return fbcon_registered_fb[fb]; } static int logo_lines; -- 2.39.5