Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4436666pxu; Mon, 12 Oct 2020 20:27:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx98IpdETyoKmxXKyuCMuElkPfMuj91JY4b67PM+mh71G9IbkSiUMHx3B3KpZEKxCyDgwqd X-Received: by 2002:a50:d654:: with SMTP id c20mr6596775edj.54.1602559632296; Mon, 12 Oct 2020 20:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602559632; cv=none; d=google.com; s=arc-20160816; b=J54W9aMjDuTA5waoZSLuC70c2eX6sma5L3kRtN6yN2UeW7uYgWyuBR7TrMgEj+5Kjm EIMNXOTxd0FPlMcxHe/eRNjgF0wd38WVaRkh37C5UULQcRpWk+bEU0/NStQhk9BbD2mn YKtcvMwUDLDvBBh1e9U2jgj0ehwpwPar6Q+vUXFKzth6W7WoboOxS/lgAq33L7BgShp8 yZb/jdM5NNXfFc1jMzJbIaLksyouk7Kv7O1JBeGJJk2FkLiRwGYBY0FOm82qiOvzyXD6 Hzj1fh4xANKiDQtnoZpdp5pZw6f/5CwNmkBTJ+HXvx93muE6HzJDsPsUxeYGDlY0wtbF dqXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c917Wh6nnGGyd6cxkDaRg/jaX3oWqD6O43YDZ/XLlpw=; b=T91c6GvYi9fOiNMwJocXTKoDjSgKazw3APFZAa9YXFbzJAVrdGMBItBxoP95ezNrrq gb9i7bwp0QqE0b82tOOmw4zqW01GcWwr9RxHwNl0z5TtCqB2dtMJX/88Hjaq3CNt5xm8 zIAgZjaLvpoqf/406ICCgoPOFN7vHncZUyMSw5vSG0dzH6t82h7zB/i+l5PxzPO3o8jR Ssc0YR2xNx1BKRFiF6wWzI49btj0EcLqNNv4Yhd6S0wXyUlXNwX9/6ZxEJhdjLleI2I6 J+7oJsrtK9AfBANhz2EQLWSZPUdNuLdFIXGydWNdWK07ofgdSFkRDvRWYuOahmR32QMf 6gxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=upsZWYQB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n18si13518320edo.610.2020.10.12.20.26.33; Mon, 12 Oct 2020 20:27:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=upsZWYQB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391131AbgJLOGv (ORCPT + 99 others); Mon, 12 Oct 2020 10:06:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:36786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730190AbgJLNeX (ORCPT ); Mon, 12 Oct 2020 09:34:23 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 181D122228; Mon, 12 Oct 2020 13:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509649; bh=zL9izJMJB54pG1Dl+LvC5fpuv1reHJnvEC2ws5mv0Kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upsZWYQBcRLKEwEgoFxJezySYfctySyjnmGT720lvm2yqJYG9lftL1VQ/lF+U+DEf O1uCFO+qBB46OqTvWdWiaykFGBlcEpgEflP3t6BLQ7WB+9Ppcn2XOWemDd5NcNQVOR 4rnzDwbM376ubPkcFpnCJkXTV9LI43DN972MLdG0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peilin Ye , Daniel Vetter , syzbot+29d4ed7f3bdedf2aa2fd@syzkaller.appspotmail.com Subject: [PATCH 4.9 26/54] fbcon: Fix global-out-of-bounds read in fbcon_get_font() Date: Mon, 12 Oct 2020 15:26:48 +0200 Message-Id: <20201012132630.802633984@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132629.585664421@linuxfoundation.org> References: <20201012132629.585664421@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peilin Ye commit 5af08640795b2b9a940c9266c0260455377ae262 upstream. fbcon_get_font() is reading out-of-bounds. A malicious user may resize `vc->vc_font.height` to a large value, causing fbcon_get_font() to read out of `fontdata`. fbcon_get_font() handles both built-in and user-provided fonts. Fortunately, recently we have added FONT_EXTRA_WORDS support for built-in fonts, so fix it by adding range checks using FNTSIZE(). This patch depends on patch "fbdev, newport_con: Move FONT_EXTRA_WORDS macros into linux/font.h", and patch "Fonts: Support FONT_EXTRA_WORDS macros for built-in fonts". Cc: stable@vger.kernel.org Reported-and-tested-by: syzbot+29d4ed7f3bdedf2aa2fd@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=08b8be45afea11888776f897895aef9ad1c3ecfd Signed-off-by: Peilin Ye Reviewed-by: Greg Kroah-Hartman Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/b34544687a1a09d6de630659eb7a773f4953238b.1600953813.git.yepeilin.cs@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/video/console/fbcon.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/drivers/video/console/fbcon.c +++ b/drivers/video/console/fbcon.c @@ -2234,6 +2234,9 @@ static int fbcon_get_font(struct vc_data if (font->width <= 8) { j = vc->vc_font.height; + if (font->charcount * j > FNTSIZE(fontdata)) + return -EINVAL; + for (i = 0; i < font->charcount; i++) { memcpy(data, fontdata, j); memset(data + j, 0, 32 - j); @@ -2242,6 +2245,9 @@ static int fbcon_get_font(struct vc_data } } else if (font->width <= 16) { j = vc->vc_font.height * 2; + if (font->charcount * j > FNTSIZE(fontdata)) + return -EINVAL; + for (i = 0; i < font->charcount; i++) { memcpy(data, fontdata, j); memset(data + j, 0, 64 - j); @@ -2249,6 +2255,9 @@ static int fbcon_get_font(struct vc_data fontdata += j; } } else if (font->width <= 24) { + if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata)) + return -EINVAL; + for (i = 0; i < font->charcount; i++) { for (j = 0; j < vc->vc_font.height; j++) { *data++ = fontdata[0]; @@ -2261,6 +2270,9 @@ static int fbcon_get_font(struct vc_data } } else { j = vc->vc_font.height * 4; + if (font->charcount * j > FNTSIZE(fontdata)) + return -EINVAL; + for (i = 0; i < font->charcount; i++) { memcpy(data, fontdata, j); memset(data + j, 0, 128 - j);