diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c index 66167830fefd..22446aea4b8c 100644 --- a/drivers/video/fbdev/core/fbcon.c +++ b/drivers/video/fbdev/core/fbcon.c @@ -2203,10 +2203,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width, struct fb_var_screeninfo var = info->var; int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh; - if (ops->p && ops->p->userfont && FNTSIZE(vc->vc_font.data)) { - int size; - int pitch = PITCH(vc->vc_font.width); - + if (p->userfont && FNTSIZE(vc->vc_font.data)) { /* * If user font, ensure that a possible change to user font * height or width will not allow a font data out-of-bounds access. @@ -2214,11 +2211,17 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width, * charcount can change and cannot be used to determine the * font data allocated size. */ - if (pitch <= 0) - return -EINVAL; - size = CALC_FONTSZ(vc->vc_font.height, pitch, FNTCHARCNT(vc->vc_font.data)); - if (size > FNTSIZE(vc->vc_font.data)) + unsigned int size; + unsigned int pitch = PITCH(vc->vc_font.width); + unsigned int height = vc->vc_font.height; + unsigned int len = FNTCHARCNT(vc->vc_font.data); + + if ((int) pitch <= 0 || (int) height <= 0 || (int) len <= 0 || + check_mul_overflow(pitch, height, &size) || + check_mul_overflow(size, len, &size) || size > FNTSIZE(vc->vc_font.data)) return -EINVAL; + printk("%s passed font size check: pitch=%u height=%u len=%u size=%u\n", + __func__, pitch, height, len, (unsigned int) FNTSIZE(vc->vc_font.data)); } virt_w = FBCON_SWAP(ops->rotate, width, height);