Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] fbcon: mismatched par->p->fontdata lookup and NULL deref in bitblit --
commit 715441bc0ed4d52171baff9d0046bf7f7969ee89 Author: Thomas Zimmermann <[email protected]> fbcon: Look up glyphs using the font interface This commit replaces open-coded glyph lookups and cell-size calculations in the fbcon bitblit and rotation implementations with font_data_glyph_buf() and font_glyph_size(). > diff --git a/drivers/video/fbdev/core/bitblit.c > b/drivers/video/fbdev/core/bitblit.c > index 1cbfbe50bebff..c28329466f051 100644 > --- a/drivers/video/fbdev/core/bitblit.c > +++ b/drivers/video/fbdev/core/bitblit.c > @@ -76,13 +76,15 @@ static void bit_clear(struct vc_data *vc, struct fb_info > *info, int sy, > > static inline void bit_putcs_aligned(struct vc_data *vc, struct fb_info > *info, > const u16 *s, u32 attr, u32 cnt, > - u32 d_pitch, u32 s_pitch, u32 cellsize, > + u32 d_pitch, u32 s_width, u32 s_vpitch, > struct fb_image *image, > unsigned char *buf, u8 *dst) > { > u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; > unsigned int charcnt = vc->vc_font.charcount; > u32 idx = vc->vc_font.width >> 3; > + struct fbcon_par *par = info->fbcon_par; > + u32 s_pitch = font_glyph_pitch(s_width); > const unsigned char *src; > > while (cnt--) { > @@ -90,7 +92,7 @@ static inline void bit_putcs_aligned(struct vc_data *vc, > struct fb_info *info, > > if (ch >= charcnt) > ch = 0; > - src = vc->vc_font.data + (unsigned int)ch * cellsize; > + src = font_data_glyph_buf(par->p->fontdata, s_width, s_vpitch, > ch); > > if (attr) { > update_attr(buf, src, attr, vc); > @@ -113,7 +115,7 @@ static inline void bit_putcs_aligned(struct vc_data *vc, > struct fb_info *info, > static inline void bit_putcs_unaligned(struct vc_data *vc, > struct fb_info *info, const u16 *s, > u32 attr, u32 cnt, u32 d_pitch, > - u32 s_pitch, u32 cellsize, > + u32 s_width, u32 s_vpitch, > struct fb_image *image, > unsigned char *buf, u8 *dst) > { > @@ -122,6 +124,8 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, > u32 shift_low = 0, mod = vc->vc_font.width % 8; > u32 shift_high = 8; > u32 idx = vc->vc_font.width >> 3; > + struct fbcon_par *par = info->fbcon_par; > + u32 s_pitch = font_glyph_pitch(s_width); > const unsigned char *src; > > while (cnt--) { > @@ -129,7 +133,7 @@ static inline void bit_putcs_unaligned(struct vc_data *vc, > > if (ch >= charcnt) > ch = 0; > - src = vc->vc_font.data + (unsigned int)ch * cellsize; > + src = font_data_glyph_buf(par->p->fontdata, s_width, s_vpitch, > ch); > > if (attr) { > update_attr(buf, src, attr, vc); [ ... ] > @@ -289,7 +294,7 @@ static void bit_cursor(struct vc_data *vc, struct fb_info > *info, bool enable, > /* Clamp to font size, same as bit_putcs_aligned() */ > if (c >= vc->vc_font.charcount) > c = 0; > - src = vc->vc_font.data + (c * cellsize); > + src = font_data_glyph_buf(par->p->fontdata, width, vpitch, c); > > if (par->cursor_state.image.data != (const char *)src || > par->cursor_reset) { [Severity: High] Can looking up glyphs in par->p->fontdata instead of vc->vc_font.data cause a NULL pointer dereference in bit_putcs_aligned(), bit_putcs_unaligned(), and bit_cursor()? par is shared across all virtual consoles mapped to info, so par->p does not always point to &fb_display[vc->vc_num]. For example, con_font_set() calls hide_cursor(vc) -> fbcon_cursor(vc, false) -> bit_cursor() on a background console while par->p still points to &fb_display[fg_console], and set_con2fb_map() sets par->p = &fb_display[unit] for a background console before con2fb_init_display() calls update_screen() on fg_console. When par->p->fontdata belongs to a console with a smaller font buffer than vc (such as an 8x16 font on par->p vs a 16x32 font on vc), any character index c >= font_data_num_glyphs(par->p->fontdata, width, vpitch) still passes the c >= vc->vc_font.charcount clamp, causing font_data_glyph_buf() to return NULL. That unchecked NULL src is then dereferenced in soft_cursor(), update_attr(), or the fb_pad_*_buffer() helpers; and if the console referenced by par->p was deallocated via VT_DISALLOCATE so that par->p->fontdata is NULL, font_data_glyph_buf() itself dereferences NULL in FNTSIZE(). The follow-up commit "fbcon: Handle characters with no glyph defined in a consistent way" adds if (!src) checks after font_data_glyph_buf(), but does not fix the par->p->fontdata mismatch in bitblit.c and falls back to dereferencing par->rotated.buf (which is NULL in bitblit) when !src. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=5
