Fix bugs in *_set_par() caused by user input
cover Fix bugs in *_set_par() caused by user input
In the function *_set_par(), the value of 'screen_size' is calculated by the user input. If the user provides the improper value, the value of 'screen_size' may larger than 'info->screen_size', which may cause a bug in the memset_io().
Zheyu Ma (3):
video: fbdev: vt8623fb: Check the size of screen before memset_io()
video: fbdev: arkfb: Check the size of screen before memset_io()
video: fbdev: s3fb: Check the size of screen before memset_io()
drivers/video/fbdev/arkfb.c | 2 ++ drivers/video/fbdev/s3fb.c | 2 ++ drivers/video/fbdev/vt8623fb.c | 2 ++ 3 files changed, 6 insertions(+)
Signature · 1 line
2.25.1
PATCH 1/3 video: fbdev: vt8623fb: Check the size of screen before memset_io()
In the function vt8623fb_set_par(), the value of 'screen_size' is calculated by the user input. If the user provides the improper value, the value of 'screen_size' may larger than 'info->screen_size', which may cause the following bug:
[ 583.339036] BUG: unable to handle page fault for address: ffffc90005000000 [ 583.339049] #PF: supervisor write access in kernel mode [ 583.339052] #PF: error_code(0x0002) - not-present page [ 583.339074] RIP: 0010:memset_orig+0x33/0xb0 [ 583.339110] Call Trace: [ 583.339118] vt8623fb_set_par+0x11cd/0x21e0 [ 583.339146] fb_set_var+0x604/0xeb0 [ 583.339181] do_fb_ioctl+0x234/0x670 [ 583.339209] fb_ioctl+0xdd/0x130
Fix the this by checking the value of 'screen_size' before memset_io().
--- drivers/video/fbdev/vt8623fb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/video/fbdev/vt8623fb.c +2 -0
@@ -507,6 +507,8 @@ static int vt8623fb_set_par(struct fb_info *info) (info->var.vmode &FB_VMODE_DOUBLE ) ?2 :1 ,1 , 1, info->node); +if (screen_size > info->screen_size) + screen_size = info->screen_size;memset_io (info->screen_base,0x00 , screen_size);/* Device and screen back on */
Signature · 1 line
2.25.1
PATCH 2/3 video: fbdev: arkfb: Check the size of screen before memset_io()
In reply to Zheyu MaIn the function arkfb_set_par(), the value of 'screen_size' is calculated by the user input. If the user provides the improper value, the value of 'screen_size' may larger than 'info->screen_size', which may cause the following bug:
[ 659.399066] BUG: unable to handle page fault for address: ffffc90003000000 [ 659.399077] #PF: supervisor write access in kernel mode [ 659.399079] #PF: error_code(0x0002) - not-present page [ 659.399094] RIP: 0010:memset_orig+0x33/0xb0 [ 659.399116] Call Trace: [ 659.399122] arkfb_set_par+0x143f/0x24c0 [ 659.399130] fb_set_var+0x604/0xeb0 [ 659.399161] do_fb_ioctl+0x234/0x670 [ 659.399189] fb_ioctl+0xdd/0x130
Fix the this by checking the value of 'screen_size' before memset_io().
--- drivers/video/fbdev/arkfb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/video/fbdev/arkfb.c +2 -0
@@ -792,6 +792,8 @@ static int arkfb_set_par(struct fb_info *info) value = ((value * hmul / hdiv) /8 ) -5 ;vga_wcrt (par->state.vgabase,0x42 , (value +1 ) /2 ); +if (screen_size > info->screen_size) + screen_size = info->screen_size;memset_io (info->screen_base,0x00 , screen_size);/* Device and screen back on */ svga_wcrt_mask (par->state.vgabase,0x17 ,0x80 ,0x80 );
Signature · 1 line
2.25.1
PATCH 3/3 video: fbdev: s3fb: Check the size of screen before memset_io()
In reply to Zheyu MaIn the function s3fb_set_par(), the value of 'screen_size' is calculated by the user input. If the user provides the improper value, the value of 'screen_size' may larger than 'info->screen_size', which may cause the following bug:
[ 54.083733] BUG: unable to handle page fault for address: ffffc90003000000 [ 54.083742] #PF: supervisor write access in kernel mode [ 54.083744] #PF: error_code(0x0002) - not-present page [ 54.083760] RIP: 0010:memset_orig+0x33/0xb0 [ 54.083782] Call Trace: [ 54.083788] s3fb_set_par+0x1ec6/0x4040 [ 54.083806] fb_set_var+0x604/0xeb0 [ 54.083836] do_fb_ioctl+0x234/0x670
Fix the this by checking the value of 'screen_size' before memset_io().
--- drivers/video/fbdev/s3fb.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/video/fbdev/s3fb.c +2 -0
@@ -905,6 +905,8 @@ static int s3fb_set_par(struct fb_info *info) value =clamp ((htotal + hsstart +1 ) /2 +2 , hsstart +4 , htotal +1 );svga_wcrt_multi (par->state.vgabase, s3_dtpc_regs, value); +if (screen_size > info->screen_size) + screen_size = info->screen_size;memset_io (info->screen_base,0x00 , screen_size);/* Device and screen back on */ svga_wcrt_mask (par->state.vgabase,0x17 ,0x80 ,0x80 );
Signature · 1 line
2.25.1
Quoted 4 lines · Zheyu Ma
In the function
*_set_par(), the value of 'screen_size' is calculated by the user input. If the user provides the improper value, the value of 'screen_size' may larger than 'info->screen_size', which may cause a bug in thememset_io().
Hi
I did not saw fbdev code in years, but should not this be already checked by *_check_var() ?
arkfb_check_var():
... /* Check whether have enough memory */ mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual; if (mem > info->screen_size) ...
Signature · 5 lines
Elen sila lumenn' omentielvo Ondrej 'Santiago' Zajicek (email: [email protected]) OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) "To err is human -- to blame it on a computer is even more so."
Hello,
Quoted 12 lines · Ondrej Zajicek
Quoted 4 lines · Zheyu Ma
In the function
*_set_par(), the value of 'screen_size' is calculated by the user input. If the user provides the improper value, the value of 'screen_size' may larger than 'info->screen_size', which may cause a bug in thememset_io().Hi
I did not saw fbdev code in years, but should not this be already checked by
*_check_var()?
Quoted 7 lines
arkfb_check_var():... /* Check whether have enough memory */ mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual; if (mem > info->screen_size) ...
Thanks for the reminder. But since the user can control all the parameters of the ioctl system call, it is possible to assign 'var->bits_per_pixel' to be 0 and thus 'mem' will be 0, bypassing this check. And in *_set_par(), when 'var->bits_per_pixel' is 0, 'screen_size' will be calculated as follows:
u32 bpp = info->var.bits_per_pixel;
if (bpp != 0) {
...
} else {
...
screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
}resulting in a very large value.
regards,
Zheyu Ma
Quoted 9 lines · Zheyu Ma
In the function
*_set_par(), the value of 'screen_size' is calculated by the user input. If the user provides the improper value, the value of 'screen_size' may larger than 'info->screen_size', which may cause a bug in thememset_io().Zheyu Ma (3):
video: fbdev: vt8623fb: Check the size of screen beforememset_io()
video: fbdev: arkfb: Check the size of screen beforememset_io()
video: fbdev: s3fb: Check the size of screen beforememset_io()
applied all 3 patches to fbdev git tree.
Thanks!
Helge
Quoted 6 lines
drivers/video/fbdev/arkfb.c | 2 ++ drivers/video/fbdev/s3fb.c | 2 ++ drivers/video/fbdev/vt8623fb.c | 2 ++ 3 files changed, 6 insertions(+)