From patchwork Wed Jun 29 20:00:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12900659 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 B1B23CCA480 for ; Wed, 29 Jun 2022 20:00:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230041AbiF2UAg (ORCPT ); Wed, 29 Jun 2022 16:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbiF2UAe (ORCPT ); Wed, 29 Jun 2022 16:00:34 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 561996584 for ; Wed, 29 Jun 2022 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656532825; bh=tRqvkgP3s46IORRaOk1LZP5YQEeJ21rrrTXuUbKXSvE=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=Ento3nZdW0q9/UO4RDKRZiVb6pw6ey9KxVMhLEqP+/L3xK3ng/MbZY/wYgTqWBD8L yJDSqwo2XEb2z0tMF/g23dVI9XVmLM+bLBvd/V7iCIjnVoSRM1NW1y2RywAa1Axm5a +puNJj09fdbmq8+sjyE5UujKloay+fksmkqhfJ2c= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.135.51]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MnJlW-1nNMxZ1hbA-00jJ2Y; Wed, 29 Jun 2022 22:00:25 +0200 From: Helge Deller To: daniel.vetter@ffwll.ch, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, geert@linux-m68k.org Subject: [PATCH 1/5] fbcon: Disallow setting font bigger than screen size Date: Wed, 29 Jun 2022 22:00:20 +0200 Message-Id: <20220629200024.187187-2-deller@gmx.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220629200024.187187-1-deller@gmx.de> References: <20220629200024.187187-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:RLQtPxRX4o/1fkCuxSLZsoyQCtuI9fQ9wby/9dJx0ssJ+Za7mXQ S3Y3icrcrK2wOwaBeJzjLYV1FxNqBFp/iHungp4Noa87uoMr59FJfl5U092DlNInhh/b5M7 2SqENKjjuxO3K7tW9HwRex1hoP83mJYklhCqQCBvIlUQveYj2W5+ktjvQz/1/BpYkwGjlzy dDjg8KogjvPn7yrb2cLVg== X-UI-Out-Filterresults: notjunk:1;V03:K0:z6Ma4WkdjRg=:MOOSdCJ505CPKSqvODfGAj k2GJzF+eW+UnJEm5AaqrDSEhzBV43ArNrMthzXyZAT956cWT386yqIEdBA2AgWlMKIxxw7dsE MqOnsCuQAjlz4Mk7VgTIpzjhB0Exj6ObNnL5B4Mx6f1D+1YNgnzAWjGCfyGcQagMLFVsoePpS a+bflIqP4aHg30DPvD2JqdvGOn5ARul1KoQaLUO5A8gfFgZhSq7U4NcwR9z3EznJUZQOxk5g+ 57lMRIdOnGiHKCkhVyuoyobIEi2XF4XECRCSaVXognd6il6jeY4OdswHndKYhnidqpvoRCIxu OdhM3JpVuj54lMbKN8w28KoPsFLF4hjCxdRjbIzPhp0F1+1U16nGY5ffg5zk4N89APJKxfrup tF/rYy5F01saiMiv4qH53Qh/T4SyEYKsYpN34SIsLZBsRNeEYpl1hkyfHPSKA6BRbsvSwb7Ge wrql9gX8Yla7XPsrdpDQ3kyX+4YFGo0q9pOqiFrzrPr4rGeiaJGRaVX6zJaJb2NSZXdAMMwKf BA03Xf3UA7Clc2zf+0n5Y/qbcIuopCP6Y3AhQwf6KIc3IajdNijjfD000UbJS2/nNkpNpnXbs InPFrp4XEb+fsgsHIdrxjwz22OtFe+kPT0DlRyelHrJJtePczvHQsbAovDyyBzvvhJro4dIGJ JVrQsQcMaN9BOlVxbRoPC8bb1Z4OfbM+gamyToNxyhtDv+Hoh8XDJEC22SD/xV+bu0PcVci1o X3Kcv1StOa5WHbWtCToMtPexzjB8KN4PRqYWfP1z5pNq1vswcLNQVP9+ph4R0Q/1MNX7PXknh rVmRr+UxfX1EprXjS+xKmxktNX2rLKjA9fyck4v30T3vLT0xWwFbiO++eHDp7ZPCPtmF3Wg9K QFSBQH6nw3Oebp9Atn2eC0RkImInfaqtVBbZRW1g1L64LLaiVitbKlmgyXhFtf72VWEwyyhM8 6J89SZNOPgNz1yXuMQmu5X5iFqBty9e4elx2ooFnCUKCHmOaHuavSIwj6ljKJff+BQTTEGF0L UaHqaEzBSItIw6GwSHAuX+ggxhlspAeiNLBAWPjs22X4i/1vKMVX8rYqrw9kIhnsQdrE8lXIP ZrSlV6W3lXfePg8ulX7jDnd/8KUIZ0vU9f1+kqjJFCY6+2Xeaf9lJHGzg== Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Prevent that users set a font size which is bigger than the physical screen. It's unlikely this may happen (because screens are usually much larger than the fonts and each font char is limited to 32x32 pixels), but it may happen on smaller screens/LCD displays. Signed-off-by: Helge Deller Reviewed-by: Daniel Vetter Cc: stable@vger.kernel.org # v4.14+ Reviewed-by: Geert Uytterhoeven --- drivers/video/fbdev/core/fbcon.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.35.3 diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index c4e91715ef00..e162d5e753e5 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2469,6 +2469,11 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font *font, if (charcount != 256 && charcount != 512) return -EINVAL; + /* font bigger than screen resolution ? */ + if (font->width > FBCON_SWAP(info->var.rotate, info->var.xres, info->var.yres) || + font->height > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres)) + 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)))) From patchwork Wed Jun 29 20:00:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12900658 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 D338DCCA47C for ; Wed, 29 Jun 2022 20:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229738AbiF2UAf (ORCPT ); Wed, 29 Jun 2022 16:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229776AbiF2UAd (ORCPT ); Wed, 29 Jun 2022 16:00:33 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6877064DE for ; Wed, 29 Jun 2022 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656532825; bh=eg5Jt30VKi0F1euM/29YUUlIJ1+3/C3w7lH5uaKtqGg=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=PC+DCi88lZZUdYutB+Xvt6QQKg4zbqFGYJXs2KbG3f4bnu1ycWyOhh/eF7nLz0lsU SvvgQ5T3239e5gb0CTOAhIiSNM4f6c3Ujn/ffy6/CtcN+miI/cvQyo2k8Zyewcg2d0 j8o+vMX+FjFpGgcZkl9BVbH6K/ApwYCp8+qzCtBc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.135.51]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MwwZd-1njCmg2FRb-00yQIP; Wed, 29 Jun 2022 22:00:25 +0200 From: Helge Deller To: daniel.vetter@ffwll.ch, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, geert@linux-m68k.org Subject: [PATCH 2/5] fbcon: Fix up user-provided virtual screen size Date: Wed, 29 Jun 2022 22:00:21 +0200 Message-Id: <20220629200024.187187-3-deller@gmx.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220629200024.187187-1-deller@gmx.de> References: <20220629200024.187187-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:q5+c9cZcND93/SaTomtSiwbsb+VbOqovOUpIZS0ava/zByW+J8o rhLxhaYe7F2M/xVMFV7cyEKB/B4UPif+t5076IgmQzpQxyBc7MleMJq0rUey7rDQFWUmy+F DV1ZAkzUMjt2D+7TCoIP6T+QevdfKDNXTWLNpdnLSsGdPfRLacfyIm9KicY5pkdMjCDENKB n02cmy4KigvBG+Jp1bshw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Qfax8JBg+6M=:sLiqfQCREClG2PgYQhj4yh /to3tfh8v8KUXiNNV5gk9g60qQdbTAOOZoPMHnUkupOuTpiB1orf5WtSGPbO9lP2Cu3XCNg6U 05+WNf8NtASvCmoudbEKHT86lIfgAD7fFdHrpBnSGZZuTwVRZ9eQfN6lSlw3d4MArKPsrnNf+ 4AB96BXEvh9NzWd8U9I6Dnht+2r53XjA/OvNuTY15oN70d4WsJsFd6w3OkN3QU5VI61fZfWgX hOxVUZQFS1OihLuTap/8hgTgCmrEQQ0xD7Po5jvtpD1HFNMbwOfQ2jSwZyMs76Srije8Kdb5n tvO5Ir5xd9nSZB7Naw0Cw/dl5PdZ4fvFfr6/DjISeZAZMioXHOMuRhnVoZLVsA3hxJTQE6DXW 1g9MtpgoPgJZHpVM/UZwPbxC7JFsA8BhcEG5dsLP46WuV57cEpQDWs/1he+aAR2qxSAA8C4oi I2n1y3N+GcM1D/S+L2D973TToLx6tihCcRdf/ZSIC0T2BiaMey4jdCOkKHapkH4ScAalt2wx2 m6ddqauHyAWwrH2nhZJgAAdlcsDR41eK1ALow6OGjD47dUcVVBoZ/ZIrhbTYoQJiVVzoa6tPN mXS7TY+N/7Q0j2eOGjd6sIianl4S9ymV/mJle7bCJ07aev61rJAVBQPcKA8/25msRm07ibZCg 40ZMRlbIidl4DCA4v+sDjq7qfx40gagv75TQCeFTqEZmG0/e3aYHk9IdTPguxBEvwtqZW5XEG GwLdHfs+akqHqR24fr0NANSoFe24Kmau4taXFQaHIJ0j54Kbsk9sVHaxrmX8HTxhsP5OAEdLf gd+9uwNUj+gLPeMdU8bHeOYh2h76yWC/EEtw9Ky0087Y2yDsCx56XWmHXSIjfPXTlIBAXSzG3 91EqEb5SgvejcvldBqyyuPRE5EtU2m8Pg+HN5k6oSlp4fuosQANPQjYr6TSSghCEVncH1GkDH ucphMP8OKZM1yIcF9JtuqbxcSmjALweBVk9GKX6+zEo1qtN1sWRGyVRMQv4Y0c9nqy87mevaw DZsgc3THtkFs2WrHwDsv+/0ipScSyNgDY8MBJ9iCgIsrG277dLD+aBG9vr0F1c5pVxnesr26d XpiBajKOSQE2ADPzjDD8J0alQ7ZE1DgG7MdldI6AUp7kYpvGedYBX8S/w== Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org The virtual screen size can't be smaller than the physical screen size. Based on the general rule that we round up user-provided input if neccessary, adjust the virtual screen size as well if needed. Signed-off-by: Helge Deller Cc: stable@vger.kernel.org # v5.4+ --- drivers/video/fbdev/core/fbmem.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.35.3 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index afa2863670f3..e645b96d2700 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1106,6 +1106,11 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, return -EFAULT; console_lock(); lock_fb_info(info); + /* adjust virtual screen size if user missed it */ + if (var.xres_virtual < var.xres) + var.xres_virtual = var.xres; + if (var.yres_virtual < var.yres) + var.yres_virtual = var.yres; ret = fb_set_var(info, &var); if (!ret) fbcon_update_vcs(info, var.activate & FB_ACTIVATE_ALL); From patchwork Wed Jun 29 20:00:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12900656 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 89038C43334 for ; Wed, 29 Jun 2022 20:00:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229654AbiF2UAe (ORCPT ); Wed, 29 Jun 2022 16:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbiF2UAd (ORCPT ); Wed, 29 Jun 2022 16:00:33 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 778AD6545 for ; Wed, 29 Jun 2022 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656532825; bh=Yo9x+xyc6xZ2zGoLj5NjKMYXlhkATJyeZPsLInYBb20=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=dvVp3kNpO/IR/dxokmUrCaQSSzs5XkFka1VF1TUhO39+er1OBASGijOVojlAuwC1i pvWM+nqyDPUWi6mN5AeaDtEjythIONOkDc6aRuC5Bu2PU5oLrvMRqR06/uo354rVCB 8d6iksNDd6Ii5sHimsvAID9wm/OdoJ0JRj64Eg+I= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.135.51]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MfpOd-1nQzRY2lGD-00gLRn; Wed, 29 Jun 2022 22:00:25 +0200 From: Helge Deller To: daniel.vetter@ffwll.ch, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, geert@linux-m68k.org Subject: [PATCH 3/5] fbcon: Prevent that screen size is smaller than font size Date: Wed, 29 Jun 2022 22:00:22 +0200 Message-Id: <20220629200024.187187-4-deller@gmx.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220629200024.187187-1-deller@gmx.de> References: <20220629200024.187187-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Bl3RSVmsYeWfaAlrxG4FeQ7RezTKNvntfDSkQxCjYBRfyztVqM/ yJs0zoZCxjNcnfisFItrY62+xdKDE0/CpFy/UcIjC8qPzsFgBDltaKhwDzSqwa8RUCcKFFU kXG4hFi//Mdr15Q44zVoNH+ndfOyax+he3Gg7ZJwDaUeEETOLFJIaoOmVeUjkXzZMkOTuPH x5G/BzZ0Oqouo01mcCp2g== X-UI-Out-Filterresults: notjunk:1;V03:K0:jttVGFRovNU=:0eCDD+4gxJPzImCSj+edVB P8PInVlsapq/WSkcAsDPqwVZ+1rSl2cgFEg9qh+JA14jILAuwXNhkpu3pDDYYCo4IZxm5Gp2F JX7fUGGXYXQkk7T+Z+Xe6D8LvM2qHz4ke/oi1vzydG/TE2b4R+o+v4r8XrSLCVOh2AjtRjUzb WMMrNfZNReRnZ8anTbOiRCMywW9caMTsh3U21XLqT3aVuar5iqyZEnbVBEAr4Hsn28SY2hRJ+ YqvvyBZFTp2+BABew9hirDcH8v5vVSBTCyOH9kMIBVaRZ3di0xlGs6Azu6fJZHDqOKyAG7PwY Zkhb61GBBZNKo2EQZ2P0ZZdkpE0M4Do68MQBCRSMHY5sUrcZer0lxWmhGzRubyMgg9hfUAJuw K6n0WwuTnwByoc4ItEMbX2mYD7x0v4u2CUkxjOXsltQOO/k7oYJyahFC2ENqkLqEE9rCNudSt PDm/4KEyIUuw7K1iQT//DiA8vjWtr7CpnO+cs9/MTS0avYRdEBMnOs+QvLKpcS+OwLyCjkRra OhuFylRA10EBBqPpmq/i3FXDFxeB0f2MJk53FaqRKMAUz7/pJY5ZaQA6iQqOZMdEjn/mciRdQ Ni2Bjqgc1Rvf1MQ/zA0KPp8KsJrP/6TM242rBx4wztJJxl5TXQCgekMAp1YjPHfOKFPBBxKVO cMfekoDc+r/A+LkqvoP4IhDV1wf1eCHn/YbItzQkp6PuSZn/OEAcuW5o4MYuR7kP80knYAH5w tWVRDGO/MP+NV1Xh1e9PInwhEJy7Wub3vwEM8rkRhoUrer78kubhD0bMVQkFo5O8IRV+5VngM kDjVc19pRP9nt2YW9BNDfCght01Qyo8kjrS7GcA9LHS3JMoeE3BZNbPuhxHrJc7KRBNqtzNm6 mmz4ki2qUhDMIu8vYOyDmgFwujuqlt5IY5wLKBQs8NAGRx8yzaHrU9SyP0fd8BVfXaX897oSc gwAV+ya10bmHpV+hkdGyZEjXt834VxGMqt3iNP0WjjytlFzBZ8NtTEJ0d71F5KLqDIAR2gRS4 vyq1PrRY682RHqR5WXzLHsa2HBZY8IjO+wRH1ykyCGNtA0OYJQtOwcS7ozYCgmHdNDLl1J0Ky 8QGIeNfYAN5U0UMNSv3ogBRDL5r6V3eGJSxgsdkSt52sVnFZ9tCYYVIjg== Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org We need to prevent that users configure a screen size which is smaller than the currently selected font size. Otherwise rendering chars on the screen will access memory outside the graphics memory region. This patch adds a new function fbcon_modechange_possible() which implements this check and which later may be extended with other checks if necessary. The new function is called from the FBIOPUT_VSCREENINFO ioctl handler in fbmem.c, which will return -EINVAL if userspace asked for a too small screen size. Signed-off-by: Helge Deller Cc: stable@vger.kernel.org # v5.4+ --- drivers/video/fbdev/core/fbcon.c | 28 ++++++++++++++++++++++++++++ drivers/video/fbdev/core/fbmem.c | 4 +++- include/linux/fbcon.h | 4 ++++ 3 files changed, 35 insertions(+), 1 deletion(-) -- 2.35.3 diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index e162d5e753e5..278c065722b7 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2736,6 +2736,34 @@ void fbcon_update_vcs(struct fb_info *info, bool all) } EXPORT_SYMBOL(fbcon_update_vcs); +/* let fbcon check if it supports a new screen resolution */ +int fbcon_modechange_possible(struct fb_info *info, struct fb_var_screeninfo *var) +{ + struct fbcon_ops *ops = info->fbcon_par; + struct vc_data *vc; + int i; + + WARN_CONSOLE_UNLOCKED(); + + if (!ops || ops->currcon < 0) + return -EINVAL; + + /* prevent setting a screen size which is smaller than font size */ + for (i = first_fb_vc; i <= last_fb_vc; i++) { + vc = vc_cons[i].d; + if (!vc || vc->vc_mode != KD_TEXT || + registered_fb[con2fb_map[i]] != info) + continue; + + if (vc->vc_font.width > FBCON_SWAP(var->rotate, var->xres, var->yres) || + vc->vc_font.height > FBCON_SWAP(var->rotate, var->yres, var->xres)) + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL(fbcon_modechange_possible); + int fbcon_mode_deleted(struct fb_info *info, struct fb_videomode *mode) { diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index e645b96d2700..324f726739c4 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1111,7 +1111,9 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, var.xres_virtual = var.xres; if (var.yres_virtual < var.yres) var.yres_virtual = var.yres; - ret = fb_set_var(info, &var); + ret = fbcon_modechange_possible(info, &var); + if (!ret) + ret = fb_set_var(info, &var); if (!ret) fbcon_update_vcs(info, var.activate & FB_ACTIVATE_ALL); unlock_fb_info(info); diff --git a/include/linux/fbcon.h b/include/linux/fbcon.h index ff5596dd30f8..2382dec6d6ab 100644 --- a/include/linux/fbcon.h +++ b/include/linux/fbcon.h @@ -15,6 +15,8 @@ void fbcon_new_modelist(struct fb_info *info); void fbcon_get_requirement(struct fb_info *info, struct fb_blit_caps *caps); void fbcon_fb_blanked(struct fb_info *info, int blank); +int fbcon_modechange_possible(struct fb_info *info, + struct fb_var_screeninfo *var); void fbcon_update_vcs(struct fb_info *info, bool all); void fbcon_remap_all(struct fb_info *info); int fbcon_set_con2fb_map_ioctl(void __user *argp); @@ -33,6 +35,8 @@ static inline void fbcon_new_modelist(struct fb_info *info) {} static inline void fbcon_get_requirement(struct fb_info *info, struct fb_blit_caps *caps) {} static inline void fbcon_fb_blanked(struct fb_info *info, int blank) {} +static inline int fbcon_modechange_possible(struct fb_info *info, + struct fb_var_screeninfo *var) { return 0; } static inline void fbcon_update_vcs(struct fb_info *info, bool all) {} static inline void fbcon_remap_all(struct fb_info *info) {} static inline int fbcon_set_con2fb_map_ioctl(void __user *argp) { return 0; } From patchwork Wed Jun 29 20:00:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12900660 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 33D55CCA482 for ; Wed, 29 Jun 2022 20:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230080AbiF2UAg (ORCPT ); Wed, 29 Jun 2022 16:00:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbiF2UAe (ORCPT ); Wed, 29 Jun 2022 16:00:34 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5E506582 for ; Wed, 29 Jun 2022 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656532826; bh=X9zbpRPOh+ldE1nkJcYIH0k5ZFae+4Rxt79Zmb1FBKw=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=gzCJCr+O0d3IlfHCTZCcpw9St22P4VvmLORGZjEkaCaVYJx7KN6c0vsHC2U6NhWYN XmVWASz30uvH/4/kLnOIE7pC4riAIzUXa93CDtuHN+JQWMZjQUXn4PSEcJX5rueYPx Zij1yl2qH3Q2kM1mwp/rAQ4lbahuLmtmmlAtQucU= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.135.51]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N2mFi-1ncpPR3KJQ-0132qo; Wed, 29 Jun 2022 22:00:25 +0200 From: Helge Deller To: daniel.vetter@ffwll.ch, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, geert@linux-m68k.org Subject: [PATCH 4/5] fbmem: Prevent invalid virtual screen sizes in fb_set_var() Date: Wed, 29 Jun 2022 22:00:23 +0200 Message-Id: <20220629200024.187187-5-deller@gmx.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220629200024.187187-1-deller@gmx.de> References: <20220629200024.187187-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xKmtO/00TE159LdMjEf8AoxwSphDIXVRMyd7+AbgNBGf/mNYsg7 BJK3LQnJudJo9b17lqFUIfsuxBjn87oIF7BsMcF38xCJfSNNIDmZJpW1JJTYcai485HnKso 6GZQ7v/xsITxgNjfX8fOQl7MBjpOIShDfJqGvfqANw1H4/QxPQtqGdpJhmBATwQkJIuRn1e QhO2DHiOV43psWk2N9dog== X-UI-Out-Filterresults: notjunk:1;V03:K0:6M8ukoIwx44=:+xv3kOYUuYBStueuar11to NNzzqBZa1bBHnUd1f5Lwchha/9YEyzKkFfcFFxEvfouQ4jB+5z3Myt41hBa3dugnhtUhA4p8c ruRPZRyYxUgZsC+oJsKgw7D+Nr4xDajUEzMjYXeoAjH2odNU544E49TgQTDt8ImjEZ33LXkFa RLp0Ppfn4LAHxksRENc+NFbfk0NuDmj1HBUKaGJC4PdrAXgibIwpysSRUF0HCBlLdxIVUfW22 RxFueQqi0PC0U3vFBzJPSSEx07n//hb91geZoGjcAQnUhpxcsOC7frEKIc1etjQImV+jDK6Ov cJWh/4DXbEX0oY7g1V2GRSrEsk6SDcVeybHglGuBEb837TD6x/rPziEw0jrM2uCQ4nxD7K0nY m4wVdTUipEVwVtPj82HprreFQ9pIMZ1TumDD61IGq3a6E0X+Lh7Y6HiQHxSpnMdTl14MqudbR +7dE6BtMRcb9d9yc/H9YmYEelkljwEWidv/vo+usNSQ+/FoYxgMyrX5Pr3G5GA5THJjYpa3Hm hhSK53aHaaNkJxN+YsamEq6BZlLejEkI4JTIUQwBOxQMtqAcZtJkFZeP04OG9ti5KDD7ls0Ys YlpW0Pxy0eSS3GdX+Bc/o2Yg1atZg2Hckp/7IChI2p66io4LvYrKlXUvf1wAlWp+hxyfwkeED 9d51JSDtOzde+64XTG6DfTznsjMseJJkr/KZjlwU13bJPzX7HxRRmUMPHSzembOZzykt42LKj LbQyv02oeaYoPHw+P4mGw17ujpqSYQdlm8sBKy6QuVKy7WpP2O+s/8WurrTd64tChNMqFQB3y ha8PZIxnBeXvOJr7TEr72r6kTAfTSJR/qEewjB8VjZ3DJToduYAeO4Beym7c99yxQOyU5H0TY +PIZysDyD76ftt9qzSdPFMxGKvkqYn4kg0MrKt8sLaWRbRty3Y7JD5wEDM4XhiCjyI3Mqi+ZC Wyai0p17eMVZWY26o/35gLaYCS5dPlGGYrbFBLirlnNXg+f29VqCuPEidIiWBV0diEUegSCjp 0x+RJPZ7GOb7d/EggB4DLzr/cotU5VDxs+v7hP5s2ZAylzvkJSNj2RYMyk+oJVykneGR2CLrm VbCHNnJGHt6U8YDOLJ4jE302rYuPLILCoZ4jxjXpfctsZrMeD8kBhKSVw== Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Prevent that drivers configure a virtual screen resolution smaller than the physical screen resolution. This is important, because otherwise we may access memory outside of the graphics memory area. Signed-off-by: Helge Deller Cc: stable@vger.kernel.org # v5.4+ --- drivers/video/fbdev/core/fbmem.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.35.3 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 324f726739c4..222d94e2e0a2 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1006,6 +1006,12 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) if (var->xres < 8 || var->yres < 8) return -EINVAL; + /* make sure virtual resolution >= physical resolution */ + if (WARN_ON(var->xres_virtual < var->xres)) + var->xres_virtual = var->xres; + if (WARN_ON(var->yres_virtual < var->yres)) + var->yres_virtual = var->yres; + /* Too huge resolution causes multiplication overflow. */ if (check_mul_overflow(var->xres, var->yres, &unused) || check_mul_overflow(var->xres_virtual, var->yres_virtual, &unused)) From patchwork Wed Jun 29 20:00:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12900657 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 165A4CCA481 for ; Wed, 29 Jun 2022 20:00:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbiF2UAf (ORCPT ); Wed, 29 Jun 2022 16:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbiF2UAe (ORCPT ); Wed, 29 Jun 2022 16:00:34 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96D296546 for ; Wed, 29 Jun 2022 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1656532826; bh=SsyOzrNfen9QSl5eCWj5qx7UuBmcX7tHqF8EIXkCPfU=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=LP7HwpA51b8s2igA9tMKOyKG8KqBnTH0Q7KftF6+TBpjZNmspwqSdJgltRQ0hojSb OSfJHX0e5BMMfSJFDJc0CBS9yHy7ly9mW5l1Zpip7Hruxy+yGpvS8K+rfZWdadeJoU B5yNNP9ME60L3jtVBfDaiBiIAKHUc3JpAezkr3Pk= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.135.51]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M9nxn-1o1Qey3tHp-005tdD; Wed, 29 Jun 2022 22:00:25 +0200 From: Helge Deller To: daniel.vetter@ffwll.ch, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, geert@linux-m68k.org Subject: [PATCH 5/5] fbcon: Use fbcon_info_from_console() in fbcon_modechange_possible() Date: Wed, 29 Jun 2022 22:00:24 +0200 Message-Id: <20220629200024.187187-6-deller@gmx.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220629200024.187187-1-deller@gmx.de> References: <20220629200024.187187-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qgR2YkR2U9Hhrf/Lb7ITElH+EopY19iZaEZNkKj6yg28vpgyZcx ZhYKieMegQ3Hkll49prgqNn1NspvOL5cUPuEPohg8mSjzXc/VrbhOymGhxjzKZMs2rFcc1U Gc3E6usfmCgAArUCYk5N6m5a+HZ3BR8XtZxqhYegY4mxJE5nTpgDcNNnuraDLbdDWf9SeA2 K2b0Om1l8JENDF0XbyliQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:gwVllAQRozg=:O4QIxmyOqHYKduFMAQwiJL fo328kdPr3uZzgORGAMWIqPNE/3yrQwom1yaQ/AkANObRb70Q3+Rhke+H+fPdYKi6gZjSbhcQ GihsOUAmAMPUqf8EStIlXc1q9oHkMDo7PT8XyRjQAou2/zOEgpcU0Y88zWXfd/3aA+G+KpT8M kPGJX6pzP+ADKroB51givNh+XAWtt9QkGO/FyitngqfJNVZ+YVL4cwJrfldLDUIdspJibzMkg oD0hBrWeM0m/rtkyaj46Bic1OrCxdIeaJT0IxqG+v8EZ86BsMz9HsJ0lKbwV4Rfh1j9/fHIU7 hSgFmn1y+a7f0PMYKKgH9+6TlB36ycqKii+xhXOcbk3XNFmQ1keNAXXwPzh8h/lE+h9moNTG8 8im/BVkJYwTd8UFvA6CBAMP8o62uv394wkWEuHNv3A1Air4QSXWNi00JEYYI+PMHv3jPjNoG5 3YuzsOaTqT1NKW77uAzcaxbXO3ML+hbWfiIwNoweLfkGXgSwEnNEMnll9i+XgNSLXeeCuwIqV 2hg5PPT3RRsWHE11x77ReYEqD6WeP+E3ShFajsj9f4muBg14jytaSmmlLe2x8CYJ2sGIB92cS 7d+Syz55gcOW1VdN/6ZAMqv6qC60Na04BavlQEIIbenfWyzsJTiVoo+kO0XfynIkuTvtELsZt Ypjl366A3IZmZH+YEpqESUlalfOn1RK5n4lZRX8P2nrtuOHq5Da6ApskIJKd2QEFEYO6z69Nv +4r+4WkuvcVNdL0F6fEtrl0VqdGlGw/TkCrbPoivrnSaJPQtVPc5CLtuodAlWs6+jGp8gpRTq 4a8Ya5msCHxo4lzKd8MTTxuwHqw4w1GT5VlvSk4eGrQMHAJhE1SWcXusj/OzLXz0VVj0BVc8b S/fJr7acf3rEy54OvXghQxMPWHSVxbdMkOjQapwto7NMxPQSkB5esu39KrgKQY/6dXGvLzJNn KrGkXFNnpWUWWO8yDdkcT1ZBwAG9PxarRodh0rLJRA4cFZ6yBYYzlwLHaiyrcB5S4GUPKB779 E+woaROme9z7Z+X/8UoTHlkJbyM0ZO0QkNZrY05eeBn/onVwQYB3PX/H3ZLoOy1ZjnQqGvyVO JL9j7z/nY2c44ntPRET6Rax5iLuc/mK1N1HpQia3bQTqD+n7sDGlkALAw== Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org Use the fbcon_info_from_console() wrapper which was added to kernel v5.19 with commit 409d6c95f9c6 ("fbcon: Introduce wrapper for console->fb_info lookup"). Signed-off-by: Helge Deller Reviewed-by: Geert Uytterhoeven --- drivers/video/fbdev/core/fbcon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.35.3 diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index 278c065722b7..ec1cfc6c2451 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2752,7 +2752,7 @@ int fbcon_modechange_possible(struct fb_info *info, struct fb_var_screeninfo *va for (i = first_fb_vc; i <= last_fb_vc; i++) { vc = vc_cons[i].d; if (!vc || vc->vc_mode != KD_TEXT || - registered_fb[con2fb_map[i]] != info) + fbcon_info_from_console(i) != info) continue; if (vc->vc_font.width > FBCON_SWAP(var->rotate, var->xres, var->yres) ||