Skip to content

Commit

Permalink
Merge tag 'for-5.19/fbdev-3' of git://git.kernel.org/pub/scm/linux/ke…
Browse files Browse the repository at this point in the history
…rnel/git/deller/linux-fbdev

Pull fbdev fixes from Helge Deller:

 - fbcon now prevents switching to screen resolutions which are smaller
   than the font size, and prevents enabling a font which is bigger than
   the current screen resolution. This fixes vmalloc-out-of-bounds
   accesses found by KASAN.

 - Guiling Deng fixed a bug where the centered fbdev logo wasn't
   displayed correctly if the screen size matched the logo size.

 - Hsin-Yi Wang provided a patch to include errno.h to fix build when
   CONFIG_OF isn't enabled.

* tag 'for-5.19/fbdev-3' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/linux-fbdev:
  fbcon: Use fbcon_info_from_console() in fbcon_modechange_possible()
  fbmem: Check virtual screen sizes in fb_set_var()
  fbcon: Prevent that screen size is smaller than font size
  fbcon: Disallow setting font bigger than screen size
  video: of_display_timing.h: include errno.h
  fbdev: fbmem: Fix logo center image dx issue
  • Loading branch information
torvalds committed Jul 8, 2022
2 parents e8a4e1c + 53a6e66 commit 086ff84
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
33 changes: 33 additions & 0 deletions drivers/video/fbdev/core/fbcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -2731,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 ||
fbcon_info_from_console(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)
{
Expand Down
16 changes: 14 additions & 2 deletions drivers/video/fbdev/core/fbmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ static int fb_show_logo_line(struct fb_info *info, int rotate,

while (n && (n * (logo->width + 8) - 8 > xres))
--n;
image.dx = (xres - n * (logo->width + 8) - 8) / 2;
image.dx = (xres - (n * (logo->width + 8) - 8)) / 2;
image.dy = y ?: (yres - logo->height) / 2;
} else {
image.dx = 0;
Expand Down Expand Up @@ -1017,6 +1017,16 @@ 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 (%ux%u vs. %ux%u)\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;

Expand Down Expand Up @@ -1107,7 +1117,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);
Expand Down
4 changes: 4 additions & 0 deletions include/linux/fbcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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; }
Expand Down
2 changes: 2 additions & 0 deletions include/video/of_display_timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef __LINUX_OF_DISPLAY_TIMING_H
#define __LINUX_OF_DISPLAY_TIMING_H

#include <linux/errno.h>

struct device_node;
struct display_timing;
struct display_timings;
Expand Down

0 comments on commit 086ff84

Please sign in to comment.