* [PATCH v3 1/4] fbcon: Disallow setting font bigger than screen size
2022-07-06 15:02 [PATCH v3 0/4] fbcon: Fixes for screen resolution changes Helge Deller
@ 2022-07-06 15:02 ` Helge Deller
2022-07-06 15:02 ` [PATCH v3 2/4] fbcon: Prevent that screen size is smaller than font size Helge Deller
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Helge Deller @ 2022-07-06 15:02 UTC (permalink / raw)
To: linux-fbdev, daniel.vetter, dri-devel, geert
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 <deller@gmx.de>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: stable@vger.kernel.org # v4.14+
---
drivers/video/fbdev/core/fbcon.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index c4e91715ef00..a33532564393 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 (w > FBCON_SWAP(info->var.rotate, info->var.xres, info->var.yres) ||
+ h > 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))))
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 2/4] fbcon: Prevent that screen size is smaller than font size
2022-07-06 15:02 [PATCH v3 0/4] fbcon: Fixes for screen resolution changes Helge Deller
2022-07-06 15:02 ` [PATCH v3 1/4] fbcon: Disallow setting font bigger than screen size Helge Deller
@ 2022-07-06 15:02 ` Helge Deller
2022-07-07 8:18 ` Geert Uytterhoeven
2022-07-06 15:02 ` [PATCH v3 3/4] fbmem: Check virtual screen sizes in fb_set_var() Helge Deller
2022-07-06 15:02 ` [PATCH v3 4/4] fbcon: Use fbcon_info_from_console() in fbcon_modechange_possible() Helge Deller
3 siblings, 1 reply; 7+ messages in thread
From: Helge Deller @ 2022-07-06 15:02 UTC (permalink / raw)
To: linux-fbdev, daniel.vetter, dri-devel, geert
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 <deller@gmx.de>
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(-)
diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index a33532564393..5632870a9aeb 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;
+ 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 afa2863670f3..160389365a36 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1106,7 +1106,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 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; }
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3 2/4] fbcon: Prevent that screen size is smaller than font size
2022-07-06 15:02 ` [PATCH v3 2/4] fbcon: Prevent that screen size is smaller than font size Helge Deller
@ 2022-07-07 8:18 ` Geert Uytterhoeven
0 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-07-07 8:18 UTC (permalink / raw)
To: Helge Deller; +Cc: Linux Fbdev development list, Daniel Vetter, DRI Development
On Wed, Jul 6, 2022 at 5:02 PM Helge Deller <deller@gmx.de> wrote:
> 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 <deller@gmx.de>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 3/4] fbmem: Check virtual screen sizes in fb_set_var()
2022-07-06 15:02 [PATCH v3 0/4] fbcon: Fixes for screen resolution changes Helge Deller
2022-07-06 15:02 ` [PATCH v3 1/4] fbcon: Disallow setting font bigger than screen size Helge Deller
2022-07-06 15:02 ` [PATCH v3 2/4] fbcon: Prevent that screen size is smaller than font size Helge Deller
@ 2022-07-06 15:02 ` Helge Deller
2022-07-07 8:20 ` Geert Uytterhoeven
2022-07-06 15:02 ` [PATCH v3 4/4] fbcon: Use fbcon_info_from_console() in fbcon_modechange_possible() Helge Deller
3 siblings, 1 reply; 7+ messages in thread
From: Helge Deller @ 2022-07-06 15:02 UTC (permalink / raw)
To: linux-fbdev, daniel.vetter, dri-devel, geert
Verify that the fbdev or drm driver correctly adjusted the virtual
screen sizes. On failure report the failing driver and reject the screen
size change.
Signed-off-by: Helge Deller <deller@gmx.de>
Cc: stable@vger.kernel.org # v5.4+
---
drivers/video/fbdev/core/fbmem.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
index 160389365a36..612b54c23ac7 100644
--- a/drivers/video/fbdev/core/fbmem.c
+++ b/drivers/video/fbdev/core/fbmem.c
@@ -1016,6 +1016,17 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
if (ret)
return ret;
+ /* verify that virtual resolution >= physical resolution */
+ if (var->xres_virtual < var->xres ||
+ var->yres_virtual < var->yres) {
+ pr_warn("WARNING: fbcon: Driver '%s' missed to adjust virtual"
+ " screen size (%dx%d vs. %dx%d)\n",
+ info->fix.id,
+ var->xres_virtual, var->yres_virtual,
+ var->xres, var->yres);
+ return -EINVAL;
+ }
+
if ((var->activate & FB_ACTIVATE_MASK) != FB_ACTIVATE_NOW)
return 0;
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v3 3/4] fbmem: Check virtual screen sizes in fb_set_var()
2022-07-06 15:02 ` [PATCH v3 3/4] fbmem: Check virtual screen sizes in fb_set_var() Helge Deller
@ 2022-07-07 8:20 ` Geert Uytterhoeven
0 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-07-07 8:20 UTC (permalink / raw)
To: Helge Deller; +Cc: Linux Fbdev development list, Daniel Vetter, DRI Development
Hi Helge,
On Wed, Jul 6, 2022 at 5:02 PM Helge Deller <deller@gmx.de> wrote:
> Verify that the fbdev or drm driver correctly adjusted the virtual
> screen sizes. On failure report the failing driver and reject the screen
> size change.
>
> Signed-off-by: Helge Deller <deller@gmx.de>
> --- a/drivers/video/fbdev/core/fbmem.c
> +++ b/drivers/video/fbdev/core/fbmem.c
> @@ -1016,6 +1016,17 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
> if (ret)
> return ret;
>
> + /* verify that virtual resolution >= physical resolution */
> + if (var->xres_virtual < var->xres ||
> + var->yres_virtual < var->yres) {
> + pr_warn("WARNING: fbcon: Driver '%s' missed to adjust virtual"
> + " screen size (%dx%d vs. %dx%d)\n",
%ux%u cs. %ux%u
Please don't split messages, for easier grepping.
> + info->fix.id,
> + var->xres_virtual, var->yres_virtual,
> + var->xres, var->yres);
> + return -EINVAL;
> + }
> +
> if ((var->activate & FB_ACTIVATE_MASK) != FB_ACTIVATE_NOW)
> return 0;
With the above fixed:
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 4/4] fbcon: Use fbcon_info_from_console() in fbcon_modechange_possible()
2022-07-06 15:02 [PATCH v3 0/4] fbcon: Fixes for screen resolution changes Helge Deller
` (2 preceding siblings ...)
2022-07-06 15:02 ` [PATCH v3 3/4] fbmem: Check virtual screen sizes in fb_set_var() Helge Deller
@ 2022-07-06 15:02 ` Helge Deller
3 siblings, 0 replies; 7+ messages in thread
From: Helge Deller @ 2022-07-06 15:02 UTC (permalink / raw)
To: linux-fbdev, daniel.vetter, dri-devel, geert
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 <deller@gmx.de>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
drivers/video/fbdev/core/fbcon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index 5632870a9aeb..1a9aa12cf886 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) ||
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread