Message ID | 20230126004921.616264824@ens-lyon.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp31409wrn; Wed, 25 Jan 2023 17:21:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXv1b8KEq2YCXnL1rt4Y1sufTVaUUT/+JtoqCfcUFqWEGxPBzx71b0cAwaVzSTu7fHfmcQFf X-Received: by 2002:a05:6a20:45b:b0:b9:5fc4:6e3b with SMTP id b27-20020a056a20045b00b000b95fc46e3bmr22166008pzb.34.1674696061827; Wed, 25 Jan 2023 17:21:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674696061; cv=none; d=google.com; s=arc-20160816; b=nID2t0r44qpilrKnH+9iL1qdU9SOxvigplvao2ZiB2O1F9cNNn/FpjzMxLBpZTAvOj 4ux0ALgp+l5Hyinzimei/l33ie71agz8wL2esGBqVb37n0P2y68mloc2GRPEVhvmQFfv h2arJBOvWNxoOPj0PTpsji/679GrjoB/PaZwWSa2OaQie7WXcVwuPFr4y+7mdFhtZfbm BqrG6B0fTM/t1pTsmv9tT53dCSw6XOJ1f05U+TKhnE73afYqf/5iko40zQjDCZQvAjAV f6QccBVhx26X9cRa0CJE6Vj60vENi5bKk9f4eRlU0tldzzHsZCPmz0DAjTQS7oM1lytP UxtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=og5n8htuvVJNM/KZ7OQf99H+yksaOKo3tr28YTPQTbo=; b=Xy1V/MXqPF+rwrQPEPkyx1YFDT/d9OyavVHNBYfxEq2osnGUWo3vJWzdCV96CEHcez bn923TYCn7ZqIKnzaEyD8x769oeHF+/7bbToGBoyTOQj7bOVmAO4l+w54PmH3UOeiEmA bKyH9/vkMhcmE7eD0a73LVHB37eecvLrj/LMzkM1S0VElxIrmAMmr8EVHOOsty7x7eam 86PTyB7jmm99ZcOI5O6ddNtH6lMe2Vowbyk6Sq+pDEGEbxzFsENCh7CDVCbk3nDpDlDb qK9GLKAxd1xJM7r05+LdZJdnDsq6eSPvpVo1EJVsLPeybWiRRGYkYcc814RagDYvbJ9z es1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m19-20020a656a13000000b004792f347556si7634029pgu.623.2023.01.25.17.20.50; Wed, 25 Jan 2023 17:21:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236411AbjAZAuP (ORCPT <rfc822;lekhanya01809@gmail.com> + 99 others); Wed, 25 Jan 2023 19:50:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbjAZAuN (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 25 Jan 2023 19:50:13 -0500 Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE4F1FF14; Wed, 25 Jan 2023 16:50:12 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 2F8632013E; Thu, 26 Jan 2023 01:50:10 +0100 (CET) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DyMmoyeiM7Ic; Thu, 26 Jan 2023 01:50:10 +0100 (CET) Received: from begin (adijon-658-1-86-31.w86-204.abo.wanadoo.fr [86.204.233.31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id C20302013C; Thu, 26 Jan 2023 01:50:09 +0100 (CET) Received: from samy by begin with local (Exim 4.96) (envelope-from <samuel.thibault@ens-lyon.org>) id 1pKqSv-00HVPW-0x; Thu, 26 Jan 2023 01:50:09 +0100 Message-ID: <20230126004921.616264824@ens-lyon.org> User-Agent: quilt/0.66 Date: Thu, 26 Jan 2023 01:49:12 +0100 From: Samuel Thibault <samuel.thibault@ens-lyon.org> To: gregkh@linuxfoundation.org, Daniel Vetter <daniel@ffwll.ch>, Helge Deller <deller@gmx.de> Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Sanan Hasanov <sanan.hasanov@Knights.ucf.edu>, Samuel Thibault <samuel.thibault@ens-lyon.org> Subject: [PATCH] fbcon: Check font dimension limits References: <20230126004911.869923511@ens-lyon.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756046067825542679?= X-GMAIL-MSGID: =?utf-8?q?1756046097582287845?= |
Series |
fbcon: Check font dimension limits
|
|
Commit Message
Samuel Thibault
Jan. 26, 2023, 12:49 a.m. UTC
blit_x and blit_y are uint32_t, so fbcon currently cannot support fonts
larger than 32x32.
The 32x32 case also needs shifting an unsigned int, to properly set bit
31, otherwise we get "UBSAN: shift-out-of-bounds in fbcon_set_font",
as reported on
http://lore.kernel.org/all/IA1PR07MB98308653E259A6F2CE94A4AFABCE9@IA1PR07MB9830.namprd07.prod.outlook.com
Kernel Branch: 6.2.0-rc5-next-20230124
Kernel config: https://drive.google.com/file/d/1F-LszDAizEEH0ZX0HcSR06v5q8FPl2Uv/view?usp=sharing
Reproducer: https://drive.google.com/file/d/1mP1jcLBY7vWCNM60OMf-ogw-urQRjNrm/view?usp=sharing
Reported-by: Sanan Hasanov <sanan.hasanov@Knights.ucf.edu>
Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Comments
On Thu, Jan 26, 2023 at 01:49:12AM +0100, Samuel Thibault wrote: > blit_x and blit_y are uint32_t, so fbcon currently cannot support fonts > larger than 32x32. "u32" you mean, right? > The 32x32 case also needs shifting an unsigned int, to properly set bit > 31, otherwise we get "UBSAN: shift-out-of-bounds in fbcon_set_font", > as reported on > > http://lore.kernel.org/all/IA1PR07MB98308653E259A6F2CE94A4AFABCE9@IA1PR07MB9830.namprd07.prod.outlook.com Odd blank line? > Kernel Branch: 6.2.0-rc5-next-20230124 > Kernel config: https://drive.google.com/file/d/1F-LszDAizEEH0ZX0HcSR06v5q8FPl2Uv/view?usp=sharing > Reproducer: https://drive.google.com/file/d/1mP1jcLBY7vWCNM60OMf-ogw-urQRjNrm/view?usp=sharing What are all of these lines for? > > Reported-by: Sanan Hasanov <sanan.hasanov@Knights.ucf.edu> > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> What commit id does this fix? Should it go to stable kernels? > > Index: linux-6.0/drivers/video/fbdev/core/fbcon.c > =================================================================== > --- linux-6.0.orig/drivers/video/fbdev/core/fbcon.c > +++ linux-6.0/drivers/video/fbdev/core/fbcon.c > @@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_data > h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres)) > return -EINVAL; > > + if (font->width > 32 || font->height > 32) > + return -EINVAL; > + > /* Make sure drawing engine can handle the font */ > - if (!(info->pixmap.blit_x & (1 << (font->width - 1))) || > - !(info->pixmap.blit_y & (1 << (font->height - 1)))) > + if (!(info->pixmap.blit_x & (1U << (font->width - 1))) || > + !(info->pixmap.blit_y & (1U << (font->height - 1)))) Are you sure this is still needed with the above check added? If so, why? What is the difference in the compiled code? thanks, greg k-h
On 26. 01. 23, 1:49, Samuel Thibault wrote: > blit_x and blit_y are uint32_t, so fbcon currently cannot support fonts > larger than 32x32. > > The 32x32 case also needs shifting an unsigned int, to properly set bit > 31, otherwise we get "UBSAN: shift-out-of-bounds in fbcon_set_font", > as reported on > > http://lore.kernel.org/all/IA1PR07MB98308653E259A6F2CE94A4AFABCE9@IA1PR07MB9830.namprd07.prod.outlook.com > Kernel Branch: 6.2.0-rc5-next-20230124 > Kernel config: https://drive.google.com/file/d/1F-LszDAizEEH0ZX0HcSR06v5q8FPl2Uv/view?usp=sharing > Reproducer: https://drive.google.com/file/d/1mP1jcLBY7vWCNM60OMf-ogw-urQRjNrm/view?usp=sharing > > Reported-by: Sanan Hasanov <sanan.hasanov@Knights.ucf.edu> > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> > > Index: linux-6.0/drivers/video/fbdev/core/fbcon.c > =================================================================== > --- linux-6.0.orig/drivers/video/fbdev/core/fbcon.c > +++ linux-6.0/drivers/video/fbdev/core/fbcon.c > @@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_data > h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres)) > return -EINVAL; > > + if (font->width > 32 || font->height > 32) > + return -EINVAL; > + > /* Make sure drawing engine can handle the font */ > - if (!(info->pixmap.blit_x & (1 << (font->width - 1))) || > - !(info->pixmap.blit_y & (1 << (font->height - 1)))) > + if (!(info->pixmap.blit_x & (1U << (font->width - 1))) || > + !(info->pixmap.blit_y & (1U << (font->height - 1)))) So use BIT() properly then? That should be used in all these shifts anyway. Exactly to avoid UB. thanks,
On 26. 01. 23, 8:43, Greg KH wrote: >> --- linux-6.0.orig/drivers/video/fbdev/core/fbcon.c >> +++ linux-6.0/drivers/video/fbdev/core/fbcon.c >> @@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_data >> h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres)) >> return -EINVAL; >> >> + if (font->width > 32 || font->height > 32) >> + return -EINVAL; >> + >> /* Make sure drawing engine can handle the font */ >> - if (!(info->pixmap.blit_x & (1 << (font->width - 1))) || >> - !(info->pixmap.blit_y & (1 << (font->height - 1)))) >> + if (!(info->pixmap.blit_x & (1U << (font->width - 1))) || >> + !(info->pixmap.blit_y & (1U << (font->height - 1)))) > > Are you sure this is still needed with the above check added? If so, > why? What is the difference in the compiled code? For font->{width,height} == 32, definitely. IMO, 1 << 31 is undefined as 1 << 31 cannot be represented by an (signed) int.
Jiri Slaby, le jeu. 26 janv. 2023 10:02:55 +0100, a ecrit: > On 26. 01. 23, 1:49, Samuel Thibault wrote: > > Index: linux-6.0/drivers/video/fbdev/core/fbcon.c > > =================================================================== > > --- linux-6.0.orig/drivers/video/fbdev/core/fbcon.c > > +++ linux-6.0/drivers/video/fbdev/core/fbcon.c > > @@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_data > > h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres)) > > return -EINVAL; > > + if (font->width > 32 || font->height > 32) > > + return -EINVAL; > > + > > /* Make sure drawing engine can handle the font */ > > - if (!(info->pixmap.blit_x & (1 << (font->width - 1))) || > > - !(info->pixmap.blit_y & (1 << (font->height - 1)))) > > + if (!(info->pixmap.blit_x & (1U << (font->width - 1))) || > > + !(info->pixmap.blit_y & (1U << (font->height - 1)))) > > So use BIT() properly then? That should be used in all these shifts anyway. > Exactly to avoid UB. Right, I'll use that in next version. Samuel
Greg KH, le jeu. 26 janv. 2023 08:43:02 +0100, a ecrit: > On Thu, Jan 26, 2023 at 01:49:12AM +0100, Samuel Thibault wrote: > > blit_x and blit_y are uint32_t, so fbcon currently cannot support fonts > > larger than 32x32. > > "u32" you mean, right? Right :) > > The 32x32 case also needs shifting an unsigned int, to properly set bit > > 31, otherwise we get "UBSAN: shift-out-of-bounds in fbcon_set_font", > > as reported on > > > > http://lore.kernel.org/all/IA1PR07MB98308653E259A6F2CE94A4AFABCE9@IA1PR07MB9830.namprd07.prod.outlook.com > > Odd blank line? Not sure what you mean? I found it easier to read to put a blank line between the text and the references. > > Kernel Branch: 6.2.0-rc5-next-20230124 > > Kernel config: https://drive.google.com/file/d/1F-LszDAizEEH0ZX0HcSR06v5q8FPl2Uv/view?usp=sharing > > Reproducer: https://drive.google.com/file/d/1mP1jcLBY7vWCNM60OMf-ogw-urQRjNrm/view?usp=sharing > > What are all of these lines for? They provide the references that were set in the original report http://lore.kernel.org/all/IA1PR07MB98308653E259A6F2CE94A4AFABCE9@IA1PR07MB9830.namprd07.prod.outlook.com Arguably the "branch" and "config" are not that useful since the bug has been there for more than a dozen years, but notably the "Reproducer" is useful to provide a userland program that triggers the UB. > > Reported-by: Sanan Hasanov <sanan.hasanov@Knights.ucf.edu> > > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> > > What commit id does this fix? I though it was there forever, but it seems the check was added in 2007, so I'll add it in next version. > Should it go to stable kernels? Yes. I added stable in Cc of the mail but missed adding it in the text, I will add it. > > Index: linux-6.0/drivers/video/fbdev/core/fbcon.c > > =================================================================== > > --- linux-6.0.orig/drivers/video/fbdev/core/fbcon.c > > +++ linux-6.0/drivers/video/fbdev/core/fbcon.c > > @@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_data > > h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres)) > > return -EINVAL; > > > > + if (font->width > 32 || font->height > 32) > > + return -EINVAL; > > + > > /* Make sure drawing engine can handle the font */ > > - if (!(info->pixmap.blit_x & (1 << (font->width - 1))) || > > - !(info->pixmap.blit_y & (1 << (font->height - 1)))) > > + if (!(info->pixmap.blit_x & (1U << (font->width - 1))) || > > + !(info->pixmap.blit_y & (1U << (font->height - 1)))) > > Are you sure this is still needed with the above check added? If so, > why? What is the difference in the compiled code? As mentioned by Jiri, yes in the 32 case it's needed otherwise it's UB. Samuel
Index: linux-6.0/drivers/video/fbdev/core/fbcon.c =================================================================== --- linux-6.0.orig/drivers/video/fbdev/core/fbcon.c +++ linux-6.0/drivers/video/fbdev/core/fbcon.c @@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_data h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres)) return -EINVAL; + if (font->width > 32 || font->height > 32) + return -EINVAL; + /* Make sure drawing engine can handle the font */ - if (!(info->pixmap.blit_x & (1 << (font->width - 1))) || - !(info->pixmap.blit_y & (1 << (font->height - 1)))) + if (!(info->pixmap.blit_x & (1U << (font->width - 1))) || + !(info->pixmap.blit_y & (1U << (font->height - 1)))) return -EINVAL; /* Make sure driver can handle the font length */