From patchwork Fri Aug 5 10:09:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1664010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=eALjtPgD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LzhDd6pmfz9s1l for ; Fri, 5 Aug 2022 20:10:25 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oJuHZ-0000M4-L7; Fri, 05 Aug 2022 10:10:17 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oJuHX-0000Je-Ee for kernel-team@lists.ubuntu.com; Fri, 05 Aug 2022 10:10:15 +0000 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 346483F132 for ; Fri, 5 Aug 2022 10:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659694215; bh=t1do7EIXK8qygoDTugzVBfBxBGUrTiSi1xuawARuEIQ=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eALjtPgD2yT3TNLaN+D7wUmVPzK1auNX9UljpLtNy9KcPLOwdQynfaJkdiTsS7tmH pavR6mb6vvaXp7Yiu0gEpTvqZc7ySBpWNcrWcLMnUniPvRBxts4m/Ket6fqKgTxv3v xanBEQxXyERDamxoCAhHiKcIVJ620HIZ2cGHIWiJVcMA5oeNwHfTMMbAPl3uEGP8dD +GayQcp8amPQFF7o+ym+HgLxmoiOqhVpOE5nd3rN8fmYCwxvQZjGcYszGck7SeMziz TsJP5VKQszX5PV4cy2/vwzoru+IiaA0a6yPGNoeA3D0NwbH0YI+f5Fd6nvYRsYmCp5 7f8ogJfXed/DA== Received: by mail-wr1-f72.google.com with SMTP id x5-20020adfbb45000000b0021ee56506dfso364382wrg.11 for ; Fri, 05 Aug 2022 03:10:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc; bh=t1do7EIXK8qygoDTugzVBfBxBGUrTiSi1xuawARuEIQ=; b=nObetC9wqlmrbALW9peSz1h2/npt6kEa2sfb6Hpyrog0d11kICdZ9qoAofvJfCqPP5 AfvOYCYVsl6T2O8xGDUgE+OXsXntIcFw84fNX1VASpwqfttWWWJIb1FWp7e3Z6/fuHt7 WS/d0zln1sBWHossoI6F61mWTqkwd+9vEf6X2jd1aN0aHEuexZ2f64o85u3y2TksboEN MvRq6xYVyFDMqFWzljbwgp0G0d+eYTmBiObDjRm/8jld7CAvuy3yj2JQqRbvMkv3G2fw KYFrqCEGFPw2kEcT68VKJnUKQklQAflQ9IMy9FK3seoGdYgF7+ZsyqY8agpWZI17RwNK maxA== X-Gm-Message-State: ACgBeo0rw4eIeZAPvuH0Fw+7j4dUG9j6yeKLinhCzQIfyh/BE6z+9ysZ +Fk1v61LHoUIT3krbJ8FSLZpA28OAiSibmDbOR+8tcp3MlFPfPbdSWx9lcVRAcMz9K2rLbUhNIf 7a6mD8lyBT72n9cs/mqYuGsR9yniTwWU5tOReWQg/qQ== X-Received: by 2002:a05:600c:4251:b0:3a3:10a0:cc83 with SMTP id r17-20020a05600c425100b003a310a0cc83mr4186033wmm.205.1659694214649; Fri, 05 Aug 2022 03:10:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR5HNFQxGPng+vAJ74yukCRiQOIN2dFZlpO+f+sWT5ju618nuHYiIXBAWo/jm2vMxN9rW4J24g== X-Received: by 2002:a05:600c:4251:b0:3a3:10a0:cc83 with SMTP id r17-20020a05600c425100b003a310a0cc83mr4186022wmm.205.1659694214419; Fri, 05 Aug 2022 03:10:14 -0700 (PDT) Received: from localhost ([2001:67c:1560:8007::aac:c03c]) by smtp.gmail.com with ESMTPSA id r27-20020adfa15b000000b0021d70a871cbsm3506452wrr.32.2022.08.05.03.10.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 03:10:12 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU OEM-5.14 PATCH 2/3] fbcon: Prevent that screen size is smaller than font size Date: Fri, 5 Aug 2022 13:09:45 +0300 Message-Id: <20220805100952.193179-6-cengiz.can@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220805100952.193179-1-cengiz.can@canonical.com> References: <20220805100952.193179-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Helge Deller 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 Reviewed-by: Geert Uytterhoeven Cc: stable@vger.kernel.org # v5.4+ CVE-2021-33655 (cherry picked from commit e64242caef18b4a5840b0e7a9bff37abd4f4f933) Signed-off-by: Cengiz Can --- 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(-) diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index 0710c5ec1014f..bb83e7c53ae0e 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2747,6 +2747,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; + unsigned int i; + + WARN_CONSOLE_UNLOCKED(); + + if (!ops) + return 0; + + /* 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_GPL(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 fad09eafa5624..6e6f68d4fe2af 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1110,7 +1110,9 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, return -EFAULT; console_lock(); lock_fb_info(info); - 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 ff5596dd30f85..2382dec6d6ab8 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; }