add fix patches for CVE-2021-33655
v2 cover add fix patches for CVE-2021-33655
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 v2 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 v2 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
Greg KH
maintainerRe: [PATCH stable 4.14 v2 2/3] fbcon: Prevent that screen size is smaller than font size
Quoted 14 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.
Quoted 4 lines
Signed-off-by Helge Deller <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>[sudip: adjust context]
Who is "sudip" here?
And the Link: line wasn't in the original commit, where did that come from?
thanks,
greg k-h
Re: [PATCH stable 4.14 v2 2/3] fbcon: Prevent that screen size is smaller than font size
Quoted 15 lines · Greg KH
Quoted 14 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.
Quoted 6 lines
Quoted 4 lines
Signed-off-by Helge Deller <[email protected]>Reviewed-by Geert Uytterhoeven <[email protected]>[sudip: adjust context]Who is "sudip" here?
Em..I misunderstood the meaning "sudip". I just mean I made some contextual adjustments.
Quoted 3 lines
And the Link: line wasn't in the original commit, where did that come from?
The mainline commit appears to be from this link. Should I remove the link?
Quoted 4 lines
thanks,
greg k-h
Signature · 2 lines
Regards Chen Jun
Greg KH
maintainerRe: [PATCH stable 4.14 v2 2/3] fbcon: Prevent that screen size is smaller than font size
Quoted 21 lines · chenjun (AM)
Quoted 20 lines · Greg KH
Quoted 18 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]>[sudip: adjust context]
Quoted 4 lines
Quoted 1 line
Who is "sudip" here?
Em..I misunderstood the meaning "sudip". I just mean I made some contextual adjustments.
Then please use your name here when you resend them.
Quoted 5 lines
Quoted 3 lines
And the Link: line wasn't in the original commit, where did that come from?
The mainline commit appears to be from this link. Should I remove the link?
It is odd to see fields that are not in the upstream commit be added without any explaination (i.e. it's not an obvious signed-off-by addition), which is why I asked where it came from.
We can add these, but for some reason the upstream maintainer did not when applying it to their trees, so it's up to you if you want to dig up the information like this or not, it's not a trivial task at times.
thanks,
greg k-h
Re: [PATCH stable 4.14 v2 2/3] fbcon: Prevent that screen size is smaller than font size
Quoted 38 lines · Greg KH
Quoted 21 lines · chenjun (AM)
Quoted 20 lines · Greg KH
Quoted 18 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]>[sudip: adjust context]Quoted 4 lines
Quoted 1 line
Who is "sudip" here?
Em..I misunderstood the meaning "sudip". I just mean I made some contextual adjustments.
Then please use your name here when you resend them >
Quoted 5 lines
Quoted 3 lines
And the Link: line wasn't in the original commit, where did that come from?
The mainline commit appears to be from this link. Should I remove the link?
It is odd to see fields that are not in the upstream commit be added without any explaination (i.e. it's not an obvious signed-off-by addition), which is why I asked where it came from.
Quoted 8 lines
We can add these, but for some reason the upstream maintainer did not when applying it to their trees, so it's up to you if you want to dig up the information like this or not, it's not a trivial task at times.
thanks,
greg k-h
Very thanks for your opinion.
I will sent v3.
Signature · 2 lines
Regards Chen Jun
PATCH v2 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