add fix patches for CVE-2021-33655
v3 cover add fix patches for CVE-2021-33655
v3: modify git message.
v2: add patch d48de54a9dab ("printk: Export is_console_locked") to fix a build error caused by v1 if CONFIG_FB = m.
ERROR: "is_console_locked" [drivers/video/fbdev/core/fb.ko] undefined!
v1: https://lore.kernel.org/stable/[email protected]/
Hans de Goede (1):
printk: Export is_console_locked
Helge Deller (2):
fbcon: Prevent that screen size is smaller than font size
fbmem: Check virtual screen sizes in fb_set_var()
drivers/video/fbdev/core/fbcon.c | 28 ++++++++++++++++++++++++++++ drivers/video/fbdev/core/fbmem.c | 20 +++++++++++++++++--- include/linux/fbcon.h | 4 ++++ kernel/printk/printk.c | 1 + 4 files changed, 50 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/3 printk: Export is_console_locked
From: Hans de Goede <[email protected]>
commit d48de54a9dab5370edd2e991f78cc7996cf5483e upstream
This is a preparation patch for adding a number of WARN_CONSOLE_UNLOCKED() calls to the fbcon code, which may be built as a module (event though usually it is not).
--- kernel/printk/printk.c | 1 + 1 file changed, 1 insertion(+)
kernel/printk/printk.c +1 -0
@@ -2259,6 +2259,7 @@ int is_console_locked(void) {return console_locked; } +EXPORT_SYMBOL (is_console_locked);/* * Check if we have any console that is capable of printing while cpu is
Signature · 1 line
2.17.1
PATCH v3 3/3 fbmem: Check virtual screen sizes in fb_set_var()
In reply to Chen JunFrom: Helge Deller <[email protected]>
commit 6c11df58fd1ac0aefcb3b227f72769272b939e56 upstream
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.
--- drivers/video/fbdev/core/fbmem.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/video/fbdev/core/fbmem.c +10 -0
@@ -1019,6 +1019,16 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)if (ret) goto done; +/* 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 ) {struct fb_var_screeninfo old_var;struct fb_videomode mode;
Signature · 1 line
2.17.1
PATCH v3 2/3 fbcon: Prevent that screen size is smaller than font size
In reply to Chen JunFrom: Helge Deller <[email protected]>
commit e64242caef18b4a5840b0e7a9bff37abd4f4f933 upstream
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.
--- drivers/video/fbdev/core/fbcon.c | 28 ++++++++++++++++++++++++++++ drivers/video/fbdev/core/fbmem.c | 10 +++++++--- include/linux/fbcon.h | 4 ++++ 3 files changed, 39 insertions(+), 3 deletions(-)
drivers/video/fbdev/core/fbcon.c +28 -0
@@ -2706,6 +2706,34 @@ static void fbcon_set_all_vcs(struct fb_info *info)fbcon_modechanged (info); } +/* 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); +static int fbcon_mode_deleted (struct fb_info *info,struct fb_videomode *mode) {
drivers/video/fbdev/core/fbmem.c +7 -3
@@ -1134,9 +1134,13 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,console_unlock ();return -ENODEV ; } - info->flags |=FBINFO_MISC_USEREVENT ; - ret =fb_set_var (info, &var); - info->flags &= ~FBINFO_MISC_USEREVENT ; + ret =fbcon_modechange_possible (info, &var); +if (!ret) { + info->flags |=FBINFO_MISC_USEREVENT ; + ret =fb_set_var (info, &var); + info->flags &= ~FBINFO_MISC_USEREVENT ; + } +lock_fb_info (info);unlock_fb_info (info);console_unlock ();if (!ret &©_to_user (argp, &var,sizeof (var)))
include/linux/fbcon.h +4 -0
@@ -4,9 +4,13 @@#ifdef CONFIG_FRAMEBUFFER_CONSOLE void __init fb_console_init (void ); void __exit fb_console_exit(void); +int fbcon_modechange_possible (struct fb_info *info, +struct fb_var_screeninfo *var);#else static inline void fb_console_init (void ) {}static inline void fb_console_exit (void ) {} +static inline int fbcon_modechange_possible (struct fb_info *info, +struct fb_var_screeninfo *var) {return 0 ; }#endif #endif /* _LINUX_FBCON_H */
Signature · 1 line
2.17.1
Re: [PATCH stable 4.14 v3 2/3] fbcon: Prevent that screen size is smaller than font size
Quoted 72 lines · Chen Jun
From: Helge Deller <[email protected]>
commit
e64242caef18b4a5840b0e7a9bff37abd4f4f933upstreamWe 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 theFBIOPUT_VSCREENINFOioctl handler infbmem.c, which will return-EINVALif userspace asked for a too small screen size.Signed-off-by Helge Deller <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>[Chen Jun: adjust context]Signed-off-by Chen Jun <[email protected]>--- drivers/video/fbdev/core/fbcon.c | 28 ++++++++++++++++++++++++++++ drivers/video/fbdev/core/fbmem.c | 10 +++++++--- include/linux/fbcon.h | 4 ++++ 3 files changed, 39 insertions(+), 3 deletions(-)drivers/video/fbdev/core/fbcon.c +28
-0@@ -2706,6 +2706,34 @@ static void fbcon_set_all_vcs(struct fb_info *info)fbcon_modechanged (info); } +/* 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); +static int fbcon_mode_deleted (struct fb_info *info,struct fb_videomode *mode) {drivers/video/fbdev/core/fbmem.c +0
-1@@ -1134,9 +1134,13 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,console_unlock ();return -ENODEV ; } - info->flags |=FBINFO_MISC_USEREVENT ;
drivers/video/fbdev/core/fbmem.c static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, · line 1144
Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +7
-2- ret =fb_set_var (info, &var); - info->flags &= ~FBINFO_MISC_USEREVENT ; + ret =fbcon_modechange_possible (info, &var); +if (!ret) { + info->flags |=FBINFO_MISC_USEREVENT ; + ret =fb_set_var (info, &var); + info->flags &= ~FBINFO_MISC_USEREVENT ; + } +lock_fb_info (info);unlock_fb_info (info);
Why do we lock and unlock here consecutively?
Can it be a leftover?
Because in upstream commit, lock encapsulates fb_set_var, fbcon_modechange_possible and fbcon_update_vcs calls, which makes sense.
Here, it doesn't.
Quoted 20 lines
drivers/video/fbdev/core/fbmem.c +0
-0console_unlock ();if (!ret &©_to_user (argp, &var,sizeof (var)))include/linux/fbcon.h +4
-0@@ -4,9 +4,13 @@#ifdef CONFIG_FRAMEBUFFER_CONSOLE void __init fb_console_init (void ); void __exit fb_console_exit(void); +int fbcon_modechange_possible (struct fb_info *info, +struct fb_var_screeninfo *var);#else static inline void fb_console_init (void ) {}static inline void fb_console_exit (void ) {} +static inline int fbcon_modechange_possible (struct fb_info *info, +struct fb_var_screeninfo *var) {return 0 ; }#endif #endif /* _LINUX_FBCON_H */
Re: [PATCH stable 4.14 v3 2/3] fbcon: Prevent that screen size is smaller than font size
Quoted 86 lines · Cengiz Can
Quoted 72 lines · Chen Jun
From: Helge Deller <[email protected]>
commit
e64242caef18b4a5840b0e7a9bff37abd4f4f933upstreamWe 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 theFBIOPUT_VSCREENINFOioctl handler infbmem.c, which will return-EINVALif userspace asked for a too small screen size.Signed-off-by Helge Deller <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>[Chen Jun: adjust context]Signed-off-by Chen Jun <[email protected]>--- drivers/video/fbdev/core/fbcon.c | 28 ++++++++++++++++++++++++++++ drivers/video/fbdev/core/fbmem.c | 10 +++++++--- include/linux/fbcon.h | 4 ++++ 3 files changed, 39 insertions(+), 3 deletions(-)drivers/video/fbdev/core/fbcon.c +28
-0@@ -2706,6 +2706,34 @@ static void fbcon_set_all_vcs(struct fb_info *info)fbcon_modechanged (info); } +/* 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); +static int fbcon_mode_deleted (struct fb_info *info,struct fb_videomode *mode) {drivers/video/fbdev/core/fbmem.c +0
-1@@ -1134,9 +1134,13 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,console_unlock ();return -ENODEV ; } - info->flags |=FBINFO_MISC_USEREVENT ;drivers/video/fbdev/core/fbmem.c static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, · line 1144
Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +7
-2- ret =fb_set_var (info, &var); - info->flags &= ~FBINFO_MISC_USEREVENT ; + ret =fbcon_modechange_possible (info, &var); +if (!ret) { + info->flags |=FBINFO_MISC_USEREVENT ; + ret =fb_set_var (info, &var); + info->flags &= ~FBINFO_MISC_USEREVENT ; + } +lock_fb_info (info);unlock_fb_info (info);Why do we lock and unlock here consecutively?
Quoted 8 lines
Can it be a leftover?
Because in upstream commit, lock encapsulates
fb_set_var,fbcon_modechange_possibleandfbcon_update_vcscalls, which makes sense.Here, it doesn't.
Thanks, lock_fb_info(info) is wrong here.
Quoted 22 lines
Quoted 20 lines
drivers/video/fbdev/core/fbmem.c +0
-0console_unlock ();if (!ret &©_to_user (argp, &var,sizeof (var)))include/linux/fbcon.h +4
-0@@ -4,9 +4,13 @@#ifdef CONFIG_FRAMEBUFFER_CONSOLE void __init fb_console_init (void ); void __exit fb_console_exit(void); +int fbcon_modechange_possible (struct fb_info *info, +struct fb_var_screeninfo *var);#else static inline void fb_console_init (void ) {}static inline void fb_console_exit (void ) {} +static inline int fbcon_modechange_possible (struct fb_info *info, +struct fb_var_screeninfo *var) {return 0 ; }#endif #endif /* _LINUX_FBCON_H */
Signature · 2 lines
Regards Chen Jun
[email protected]
maintainerRe: [PATCH stable 4.14 v3 2/3] fbcon: Prevent that screen size is smaller than font size
Quoted 89 lines · chenjun (AM)
Quoted 88 lines · Cengiz Can
Quoted 72 lines · Chen Jun
From: Helge Deller <[email protected]>
commit
e64242caef18b4a5840b0e7a9bff37abd4f4f933upstreamWe 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 theFBIOPUT_VSCREENINFOioctl handler infbmem.c, which will return-EINVALif userspace asked for a too small screen size.Signed-off-by Helge Deller <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>[Chen Jun: adjust context]Signed-off-by Chen Jun <[email protected]>--- drivers/video/fbdev/core/fbcon.c | 28 ++++++++++++++++++++++++++++ drivers/video/fbdev/core/fbmem.c | 10 +++++++--- include/linux/fbcon.h | 4 ++++ 3 files changed, 39 insertions(+), 3 deletions(-)drivers/video/fbdev/core/fbcon.c +28
-0@@ -2706,6 +2706,34 @@ static void fbcon_set_all_vcs(struct fb_info *info)fbcon_modechanged (info); } +/* 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); +static int fbcon_mode_deleted (struct fb_info *info,struct fb_videomode *mode) {drivers/video/fbdev/core/fbmem.c +0
-1@@ -1134,9 +1134,13 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,console_unlock ();return -ENODEV ; } - info->flags |=FBINFO_MISC_USEREVENT ;drivers/video/fbdev/core/fbmem.c static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, · line 1144
Quoted 10 lines
drivers/video/fbdev/core/fbmem.c +7
-2- ret =fb_set_var (info, &var); - info->flags &= ~FBINFO_MISC_USEREVENT ; + ret =fbcon_modechange_possible (info, &var); +if (!ret) { + info->flags |=FBINFO_MISC_USEREVENT ; + ret =fb_set_var (info, &var); + info->flags &= ~FBINFO_MISC_USEREVENT ; + } +lock_fb_info (info);unlock_fb_info (info);Why do we lock and unlock here consecutively?
Can it be a leftover?
Quoted 8 lines
Quoted 6 lines
Because in upstream commit, lock encapsulates
fb_set_var,fbcon_modechange_possibleandfbcon_update_vcscalls, which makes sense.Here, it doesn't.
Thanks,
lock_fb_info(info)is wrong here.
Ok, I'm totally confused now.
I'm dropping all of these series from my queue now. Please fix them up and resend them for all pending stable trees (4.9.y, 4.14.y, and 4.19.y).
thanks,
greg k-h