Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp736718rwj; Sat, 17 Dec 2022 17:01:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf46KyCa6cZb+yOIwgdk0VFkW0YBu0QwW7qHUwppfnBF6BcuvfG7Hwk5wd4fZ7DTf/vwPdh9 X-Received: by 2002:a05:6a21:78aa:b0:af:7774:4de4 with SMTP id bf42-20020a056a2178aa00b000af77744de4mr23686000pzc.22.1671325270056; Sat, 17 Dec 2022 17:01:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671325270; cv=none; d=google.com; s=arc-20160816; b=zp8gHhAYBI0OaFqzSbxg+pmVT/zfzoYLQuK2scUkD16BDkze1VIbZV6zzaWeN0QpaZ LIMyrhfUz+ba47imugswaVQn7HJQmN9E2gc2kkmwKcgWZY7BPoi+a3/Law3FMj/y1SoB UlWucTc9tYfipn4aG3p4fazgV7iDmaXVm9hrWS+B9MU4SHGTKJvHJJ3bylh5tDzErEgm fOMK8jD09C9DE1nUQhrXTDnuD25MaujAyvvwSvGts9xG74oc4XTom7MWV9P4cmMQwA7V 0vqA58m6N5oQIp8N76BAq1FX3x6MbI4ccBbDSDD53Lqf3m7Lu0SGiqaWH+wO/sJy5E6q Feow== 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=yt3gzdexpfT74rM3h9AGKyJQn0MvS6lsmM+dtOeqLcc=; b=jXJhyuVdku7PolXJF9G3CBdBkVg4YdTqR6JYu1l4JTC6sQrEPLh/dI0CmdYlsHG4c/ Qlu9+4OsT/WTzsN/exgRr0NO/Sm/RHN4dLxoSYqraxdcZpFwVXafry1kTBEkfS7hED+/ 1DGg1mmU66TFM6iR5+8o+cPaI0SUPoVnG6UT0BXB4WYDQRIG05lsBh5nmj8SZNy6EV1T k0RCcEVqayl1L7D9P8EzeNiBvfMTLZ6Z7O0joWjaaWrDvEw8MxZQmGJL3YrpQ5ldu671 kBECH4xJWUj+qeKUp55aC1s/mksLp0s2CNftc3FFb4Iyqk01km38QZk9hcPFm40aabvV newQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a63df4e000000b0047757a4c275si6721785pgj.808.2022.12.17.17.01.01; Sat, 17 Dec 2022 17:01:10 -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 S230089AbiLRAfT (ORCPT + 69 others); Sat, 17 Dec 2022 19:35:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbiLRAfK (ORCPT ); Sat, 17 Dec 2022 19:35:10 -0500 Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FA8BDFF9 for ; Sat, 17 Dec 2022 16:35:08 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id E3E862016E; Sun, 18 Dec 2022 01:35:06 +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 aMCdHRg6flpU; Sun, 18 Dec 2022 01:35:06 +0100 (CET) Received: from begin (lfbn-bor-1-376-208.w109-215.abo.wanadoo.fr [109.215.91.208]) (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 C34172016C; Sun, 18 Dec 2022 01:35:05 +0100 (CET) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1p6hdx-007m1b-14; Sun, 18 Dec 2022 01:35:05 +0100 Message-ID: <20221218003237.503424466@ens-lyon.org> User-Agent: quilt/0.66 Date: Sun, 18 Dec 2022 01:32:12 +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: [patchv2 3/3] VT: Bump font size limitation to 64x128 pixels References: <20221218003209.503539532@ens-lyon.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Index: linux-6.0/drivers/tty/vt/vt.c =================================================================== --- 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 height - * of 32 pixels. Userspace fontdata is 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 time. + * Currently we only support fonts up to 128 pixels wide, at a maximum height + * 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 time. * /Jes */ -#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) 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 = op->op == KD_FONT_OP_GET_TALL ? op->height : 32; if (op->data) { - font.data = kmalloc(max_font_size, GFP_KERNEL); + font.data = 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 = -EFAULT; out: - kfree(font.data); + kvfree(font.data); return rc; } @@ -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 <= 0 || op->width > 32 || !op->height || op->height > 32) + if (op->width <= 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/usb/misc/sisusbvga/sisusb_con.c =================================================================== --- linux-6.0.orig/drivers/usb/misc/sisusbvga/sisusb_con.c +++ linux-6.0/drivers/usb/misc/sisusbvga/sisusb_con.c @@ -1203,7 +1203,7 @@ sisusbcon_font_set(struct vc_data *c, st struct sisusb_usb_data *sisusb; unsigned charcount = font->charcount; - if (font->width != 8 || vpitch != 32 || + if (font->width != 8 || font->height > 32 || vpitch != 32 || (charcount != 256 && charcount != 512)) return -EINVAL; Index: linux-6.0/drivers/video/console/vgacon.c =================================================================== --- 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; - if (font->width != VGA_FONTWIDTH || vpitch != 32 || + if (font->width != VGA_FONTWIDTH || font->height > 32 || vpitch != 32 || (charcount != 256 && charcount != 512)) return -EINVAL; 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 @@ -2279,6 +2279,8 @@ static int fbcon_get_font(struct vc_data font->width = vc->vc_font.width; font->height = vc->vc_font.height; + if (font->height > vpitch) + return -ENOSPC; font->charcount = vc->vc_hi_font_mask ? 512 : 256; if (!font->data) return 0;