Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4361013pxu; Mon, 12 Oct 2020 17:34:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjwxNVn7Onm4+kTUJm0USF9b2KX5S8aL4gv+wkb2fZ7ic77n/i7+r3y+nlsVzIGmFlOIsW X-Received: by 2002:a50:88c6:: with SMTP id d64mr17533145edd.141.1602549246038; Mon, 12 Oct 2020 17:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602549246; cv=none; d=google.com; s=arc-20160816; b=zwW6qb2sRvrPIL0Vha8vl7JOHmTrCx9rYiSp5jT5SzkRq97sakOju0omR1EsYCQ7JH 4C7fAQueB/CU3/fbthVajFIOKIDV6yBaYF3vGIsy79HTxQK/ae+OnMHZ5TZagYcABjl+ 8AuRIIrFaA30tNfSq5EThKn5NSmsAcm7YOj6+P3rKVyZq1OMsz9TbD5f8+s8vKB8bGIC rbvIM/I7oCvXRPUvA9XOtsDkPJ6j5KZcJwBtL+1tS+6LTxot+6tHmciDti91ofLzeuP9 FH5yFAta5NPpUfo6Wgol/GYqQJH/9Bn8mGTuQdbTdk5V465xpJjHL9u8/me+zkqqfhjk XKNA== 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=AJfsGcTr+jzXVk53vR+xw5Q7FDnOp1cpgOKWumVDLGI=; b=As17hwy6O2kIO3m/isH6MxOifVfK4GywTY9fxwvC5fSlC+9U40jTTPrkuTlpuUyTqC abYIbY6+hco/mpFHuiKjttX9Ap3aSC3TSSyCXiOVmU5iVuP5L8EiNDF5frdpOmEdEDGu RhB7DOMOBw7tKkkIxF0n/YXQ8IaPpuzdTDQTaRPMGHfW7ZXG+0Uhl/cdPsIoiBhv4jd6 gB7fKY/OzkRiE79G5IzTUyxI6Slep2tmvPXCf7bw+srQ1F7c00FgWdtlGFvrcGzwbzoQ ReTqSZ6a1FbyRW8XVqDfRSRQlDfDgZqSSvRq+nrTxGg89Js/4l9hDmkYqDu0+d7U9htE RiyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=V4YcvTGt; 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 j10si1813343edt.142.2020.10.12.17.33.43; Mon, 12 Oct 2020 17:34:06 -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=V4YcvTGt; 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 S2390522AbgJLNzm (ORCPT + 99 others); Mon, 12 Oct 2020 09:55:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:46220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389643AbgJLNpk (ORCPT ); Mon, 12 Oct 2020 09:45:40 -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 513172087E; Mon, 12 Oct 2020 13:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510245; bh=mCbgcj8kRpd5U7BBE7SastqiYn1fJeaKaWSGhKT3fK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V4YcvTGt1mK21AGqrHeNFcmfwembvSHCzVymqletqPAEQA7/mpMxV6VYYbp0e1u5E 8IIz1qz5gXxl/FY61hpnZQdX27uS+YtZr52wvMw0MriNSWt8XF+WUe6t76wvG/BVVo vCVQt+u87OAezs3xjaVe9STacipX+YPxEx6zwd3Q= 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.8 003/124] fbcon: Fix global-out-of-bounds read in fbcon_get_font() Date: Mon, 12 Oct 2020 15:30:07 +0200 Message-Id: <20201012133147.010934560@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012133146.834528783@linuxfoundation.org> References: <20201012133146.834528783@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 @@ -2299,6 +2299,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); @@ -2307,6 +2310,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); @@ -2314,6 +2320,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]; @@ -2326,6 +2335,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);