@@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_datah>FBCON_SWAP(info->var.rotate,info->var.yres,info->var.xres))return-EINVAL;+if(font->width>32||font->height>32)+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))))+if(!(info->pixmap.blit_x&(1U<<(font->width-1)))||+!(info->pixmap.blit_y&(1U<<(font->height-1))))return-EINVAL;/* Make sure driver can handle the font length */
From: Samuel Thibault <samuel.thibault@ens-lyon.org> Date: 2023-01-26 00:51:36
(FYI, the UB was already a problem before my big-font patch submission,
the checks I add here are already making sense in previous versions
anyway)
Samuel Thibault, le jeu. 26 janv. 2023 01:49:12 +0100, a ecrit:
@@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_datah>FBCON_SWAP(info->var.rotate,info->var.yres,info->var.xres))return-EINVAL;+if(font->width>32||font->height>32)+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))))+if(!(info->pixmap.blit_x&(1U<<(font->width-1)))||+!(info->pixmap.blit_y&(1U<<(font->height-1))))return-EINVAL;/* Make sure driver can handle the font length */
@@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_datah>FBCON_SWAP(info->var.rotate,info->var.yres,info->var.xres))return-EINVAL;+if(font->width>32||font->height>32)+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))))+if(!(info->pixmap.blit_x&(1U<<(font->width-1)))||+!(info->pixmap.blit_y&(1U<<(font->height-1))))
Are you sure this is still needed with the above check added? If so,
why? What is the difference in the compiled code?
thanks,
greg k-h
@@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_datah>FBCON_SWAP(info->var.rotate,info->var.yres,info->var.xres))return-EINVAL;+if(font->width>32||font->height>32)+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))))+if(!(info->pixmap.blit_x&(1U<<(font->width-1)))||+!(info->pixmap.blit_y&(1U<<(font->height-1))))
So use BIT() properly then? That should be used in all these shifts
anyway. Exactly to avoid UB.
thanks,
--
js
suse labs
@@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_datah>FBCON_SWAP(info->var.rotate,info->var.yres,info->var.xres))return-EINVAL;+if(font->width>32||font->height>32)+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))))+if(!(info->pixmap.blit_x&(1U<<(font->width-1)))||+!(info->pixmap.blit_y&(1U<<(font->height-1))))
Are you sure this is still needed with the above check added? If so,
why? What is the difference in the compiled code?
For font->{width,height} == 32, definitely. IMO, 1 << 31 is undefined as
1 << 31 cannot be represented by an (signed) int.
--
js
suse labs
@@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_datah>FBCON_SWAP(info->var.rotate,info->var.yres,info->var.xres))return-EINVAL;+if(font->width>32||font->height>32)+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))))+if(!(info->pixmap.blit_x&(1U<<(font->width-1)))||+!(info->pixmap.blit_y&(1U<<(font->height-1))))
So use BIT() properly then? That should be used in all these shifts anyway.
Exactly to avoid UB.
@@ -2489,9 +2489,12 @@ static int fbcon_set_font(struct vc_datah>FBCON_SWAP(info->var.rotate,info->var.yres,info->var.xres))return-EINVAL;+if(font->width>32||font->height>32)+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))))+if(!(info->pixmap.blit_x&(1U<<(font->width-1)))||+!(info->pixmap.blit_y&(1U<<(font->height-1))))
Are you sure this is still needed with the above check added? If so,
why? What is the difference in the compiled code?
As mentioned by Jiri, yes in the 32 case it's needed otherwise it's UB.
Samuel