Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4272188pxu; Mon, 12 Oct 2020 14:28:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOZzjrMAGyLc6Mon6/Y9GcNE13aG4gi+XrTPK+cDWYzxNZppN1mpBnbQ37uPKao3or+g8n X-Received: by 2002:a17:906:1411:: with SMTP id p17mr30972265ejc.102.1602538127760; Mon, 12 Oct 2020 14:28:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602538127; cv=none; d=google.com; s=arc-20160816; b=SS3gwjxe8fG44AjWebk/i93yJBypJhi0uMn66wOxmrYSOLAOy6WEpoCtACM0IpTOrn M649M1wa3Sjkkgno96jq6/6TExADhkra5edxUjOM9Hi2ptM09PHktjojBVpJAZ6vj2VE Wz8qd/RGWg6WV342WfBgFwI9azAbGYWObq7JI3LkRkUHq0jq2SxwdSQIEaYd/QPxiqQZ b7C54BirxeSibKPriQuZw52bHo1lSdAqb+RLaE5jQW23zsmIOFwxiAV2yKDhC1bhx/GJ KzzXDpF9CuMMJ+NXgyTYbDhaDAja+z5n508Aznvm+8Wi6V3oRspoatqLYfXHKlrKbh1u WSyg== 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=JlUfgqfIwWICJy2PvB/aktGKQ/ORWV7HyErcHhQRQT8=; b=VYnCxcSq8damAEG5uhiyXZ7pwtUm0oflK3+G8hnasZ/uM0k3i6zLA2iWDPPhKiQAQr SGYvlizZbgV/nQXgTrKY1OmOcHqxCiP8nGx0iPCVEOuDr7MA24uTQTy63LYFbqpAd0eQ 5oH+XTMmEvzM8fjC9g6JnV+UnDi5NFfWIeFz3Tga9PyojR5uwgh/c0GMoHlPbMvdRn0f kbCpI8vVSFBxNv/g8DHkR4YYJJ20E7fyWAFexNH1TzJWOJwSJr7ZQNSCC4DWjArdBu52 TyWI1NSCBMJ2To0/tuqL0yNGCMKY65G473j/1udYYqsfoA40xWsCVzZGrZzdN5iazfAF W4Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zq4PAp49; 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 ce16si13200828edb.302.2020.10.12.14.28.25; Mon, 12 Oct 2020 14:28:47 -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=zq4PAp49; 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 S2387598AbgJLNhf (ORCPT + 99 others); Mon, 12 Oct 2020 09:37:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:40114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730988AbgJLNhN (ORCPT ); Mon, 12 Oct 2020 09:37:13 -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 A092B21D7F; Mon, 12 Oct 2020 13:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509802; bh=DvBUtomStvPH7EQ2GJ8INeOih+pYltsSERFv1VWue5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zq4PAp49OQXPErYNRbljxdtdTn8f1p6L4Hzf4qQL16MPoFVJuy5IqvsYCfj5WHn25 dulcndyBIDXR9d6qe4iKALN1DLs3SkrVZ/yF9BRutqNb7C4lcoNq86v0x4Z+VfLVvP QLDq2Ws1KYzhhjzkkgcDrtZPBDRWd689lVgwjzNQ= 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.14 35/70] fbcon: Fix global-out-of-bounds read in fbcon_get_font() Date: Mon, 12 Oct 2020 15:26:51 +0200 Message-Id: <20201012132631.865773331@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132630.201442517@linuxfoundation.org> References: <20201012132630.201442517@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 @@ -2248,6 +2248,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); @@ -2256,6 +2259,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); @@ -2263,6 +2269,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]; @@ -2275,6 +2284,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);