Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4361415pxu; Mon, 12 Oct 2020 17:34:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn8dEtMtbG4TtJEQGvQPgw1sCuQ7+92V2xnbb/CzBXDyR2rCeUwzaT3nJ3SFbn8zzU8Inx X-Received: by 2002:a17:906:b1c3:: with SMTP id bv3mr24310218ejb.445.1602549292825; Mon, 12 Oct 2020 17:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602549292; cv=none; d=google.com; s=arc-20160816; b=SJB1dg7G5yoNaWOC8t5eT+0cYgzvaPCr69heyKto5bBI2/2snNMoZNgMWvYtbPPc3b nfDXQrjTyZTAdTu3Oj2vydTs/n75KSQM67IGYaAlvnhd9kQbgPr7MIw42QOXTPrOm7++ 9sT2RI8Ei04JhqNAkezQ5sBLhnHxT6/IOgbG7wm0VWdASmzqKJcRu0TDoPc1h6diDgES vNB0Vhe3cMv2jVVlvZZps9xw+Nk7KvuoWdvnukwQglNEFHC5ht22bDvtkqaJgyLz/rjg g2bLV65ZD6fTctnghKHs6hWnvZbh6Hyl+OP/RAJgQFY0AtOMrCWdeUnP+Ylf/N/pe9Yv OPyA== 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=CV9YuF9+EmTUn7x8adjyxn2cuna5z6l47N8KZ5zRgo0=; b=XXI3NrVPZB7flHGiI1ywJFBHYyVtpZC0eOoeqVoH2Pi29ePcWrctXIJxqUxI4UNste dT3PiDWwSbDbK08eNaZnbbvJ2XFjEX1NFd8/nJWXOQp64BRsrz2v0A2rkaGOndxRV0Xw 1cZUtPS9Nxfc7MU20b2KOd+T11yshRPUcagDuPAVHFW+yi7+bsYYvpUE0WcDmO1yslTe sdlB20z0TB4bYjXCHdZEdsnT8eMP2WUd2t8/jHdOoz1aeYsedY2Cs6L7d+4MQCcvnYnm as3rZPSjlhj7QC9DitbTZK8a8ZVqhyXW4GDNNpbOSwRYCmVwkwENb5fjWAqN53bBytSG fgzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1irbWeGt; 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 x18si15136737ejd.43.2020.10.12.17.34.30; Mon, 12 Oct 2020 17:34:52 -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=1irbWeGt; 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 S2390701AbgJLN6f (ORCPT + 99 others); Mon, 12 Oct 2020 09:58:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:43770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731464AbgJLNk4 (ORCPT ); Mon, 12 Oct 2020 09:40:56 -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 4980C22247; Mon, 12 Oct 2020 13:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510029; bh=wocJRq6DpbhI1Rx1kC1XD3zfBIuT/XQUgzDfHPElZvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1irbWeGtLWz7Wr1TDpjHro/Sp4Z2GxX+eAZCziaOisTzBZLTm9QSnD4ahLoATUDqc DVZ1uMkdpL17++AnQON1tA+ktxr/fFpckKCQ9AB4AutfWHVpElXlan+ALVdr+bhdSS Lp3fayMoxeJtIACg/Zj1b0plueLI5a5QkiQhNQ/0= 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 5.4 03/85] fbcon: Fix global-out-of-bounds read in fbcon_get_font() Date: Mon, 12 Oct 2020 15:26:26 +0200 Message-Id: <20201012132633.024150331@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132632.846779148@linuxfoundation.org> References: <20201012132632.846779148@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/fbdev/core/fbcon.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2292,6 +2292,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); @@ -2300,6 +2303,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); @@ -2307,6 +2313,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]; @@ -2319,6 +2328,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);