From nobody Sun Sep 14 18:44:25 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B000EC004D4 for ; Thu, 19 Jan 2023 15:20:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbjASPUL (ORCPT ); Thu, 19 Jan 2023 10:20:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230349AbjASPT6 (ORCPT ); Thu, 19 Jan 2023 10:19:58 -0500 Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D960382D7A for ; Thu, 19 Jan 2023 07:19:55 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 1506920105; Thu, 19 Jan 2023 16:19:54 +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 hkaeCxei9PJZ; Thu, 19 Jan 2023 16:19:53 +0100 (CET) Received: from begin (nat-inria-interne-52-gw-01-bso.bordeaux.inria.fr [194.199.1.52]) (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 D4DCE200F4; Thu, 19 Jan 2023 16:19:53 +0100 (CET) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1pIWhl-008cHx-1h; Thu, 19 Jan 2023 16:19:53 +0100 Message-ID: <20230119151935.112415738@ens-lyon.org> User-Agent: quilt/0.66 Date: Thu, 19 Jan 2023 16:19:17 +0100 From: Samuel Thibault To: Greg Kroah-Hartman , Jiri Slaby , kbd@lists.altlinux.org Cc: linux-kernel@vger.kernel.org, "linux-kernel@vger.kernel.org, Samuel Thibault" Subject: [PATCHv3 3/3] VT: Bump font size limitation to 64x128 pixels References: <20230119151914.931619963@ens-lyon.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This moves 32x32 font size limitation checking down to drivers, so that fbcon can allow large fonts. We still keep a limitation to 64x128 pixels so as to have a simple bounded allocation for con_font_get and in the userland kbd tool. That glyph size will however be enough to have 128x36 characters on a "16/9 8K display". Signed-off-by: Samuel Thibault --- V1 -> V2: Switch con_font_get to kvmalloc/kvfree instead of kmalloc/kfree V1 -> V3: Drop sisusb_con.c change, it was phased out Index: linux-6.0/drivers/tty/vt/vt.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-6.0.orig/drivers/tty/vt/vt.c +++ linux-6.0/drivers/tty/vt/vt.c @@ -4575,17 +4575,20 @@ void reset_palette(struct vc_data *vc) /* * Font switching * - * Currently we only support fonts up to 32 pixels wide, at a maximum hei= ght - * of 32 pixels. Userspace fontdata is stored with 32 bytes (shorts/ints,=20 - * depending on width) reserved for each character which is kinda wasty, = but=20 - * this is done in order to maintain compatibility with the EGA/VGA fonts= . It=20 - * is up to the actual low-level console-driver convert data into its fav= orite - * format (maybe we should add a `fontoffset' field to the `display' - * structure so we won't have to convert the fontdata all the time. + * Currently we only support fonts up to 128 pixels wide, at a maximum he= ight + * of 128 pixels. Userspace fontdata may have to be stored with 32 bytes + * (shorts/ints, depending on width) reserved for each character which is + * kinda wasty, but this is done in order to maintain compatibility with = the + * EGA/VGA fonts. It is up to the actual low-level console-driver convert= data + * into its favorite format (maybe we should add a `fontoffset' field to = the + * `display' structure so we won't have to convert the fontdata all the t= ime. * /Jes */ =20 -#define max_font_size 65536 +#define max_font_width 64 +#define max_font_height 128 +#define max_font_glyphs 512 +#define max_font_size (max_font_glyphs*max_font_width*max_font_height) =20 static int con_font_get(struct vc_data *vc, struct console_font_op *op) { @@ -4595,7 +4598,7 @@ static int con_font_get(struct vc_data * unsigned int vpitch =3D op->op =3D=3D KD_FONT_OP_GET_TALL ? op->height : = 32; =20 if (op->data) { - font.data =3D kmalloc(max_font_size, GFP_KERNEL); + font.data =3D kvmalloc(max_font_size, GFP_KERNEL); if (!font.data) return -ENOMEM; } else @@ -4630,7 +4633,7 @@ static int con_font_get(struct vc_data * rc =3D -EFAULT; =20 out: - kfree(font.data); + kvfree(font.data); return rc; } =20 @@ -4645,9 +4648,10 @@ static int con_font_set(struct vc_data * return -EINVAL; if (!op->data) return -EINVAL; - if (op->charcount > 512) + if (op->charcount > max_font_glyphs) return -EINVAL; - if (op->width <=3D 0 || op->width > 32 || !op->height || op->height > 32) + if (op->width <=3D 0 || op->width > max_font_width || !op->height || + op->height > max_font_height) return -EINVAL; if (vpitch < op->height) return -EINVAL; Index: linux-6.0/drivers/video/console/vgacon.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-6.0.orig/drivers/video/console/vgacon.c +++ linux-6.0/drivers/video/console/vgacon.c @@ -1037,7 +1037,7 @@ static int vgacon_font_set(struct vc_dat if (vga_video_type < VIDEO_TYPE_EGAM) return -EINVAL; =20 - if (font->width !=3D VGA_FONTWIDTH || vpitch !=3D 32 || + if (font->width !=3D VGA_FONTWIDTH || font->height > 32 || vpitch !=3D 32= || (charcount !=3D 256 && charcount !=3D 512)) return -EINVAL; =20 Index: linux-6.0/drivers/video/fbdev/core/fbcon.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-6.0.orig/drivers/video/fbdev/core/fbcon.c +++ linux-6.0/drivers/video/fbdev/core/fbcon.c @@ -2279,6 +2279,8 @@ static int fbcon_get_font(struct vc_data =20 font->width =3D vc->vc_font.width; font->height =3D vc->vc_font.height; + if (font->height > vpitch) + return -ENOSPC; font->charcount =3D vc->vc_hi_font_mask ? 512 : 256; if (!font->data) return 0;