All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Thomas Zimmermann" <tzimmermann@suse.de>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 5/6] fbcon: Look up glyphs using the font interface
Date: Fri, 20 Nov 2026 12:22:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-225136@kernel.org> (raw)
In-Reply-To: <20261120115215.52092-6-tzimmermann@suse.de>

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 <tzimmermann@suse.de>

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/20261120115215.52092-1-tzimmermann@suse.de?part=5

  reply	other threads:[~2026-11-20 12:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 11:49 [PATCH v2 0/6] fbcon: Clean up glyph handling on redraws Thomas Zimmermann
2026-11-20 11:49 ` [PATCH v2 1/6] fbcon: Use unsigned char for glyph data Thomas Zimmermann
2026-11-20 11:49 ` [PATCH v2 2/6] lib/fonts: Provide internal helpers for allocating font_data_t Thomas Zimmermann
2026-11-20 11:49 ` [PATCH v2 3/6] lib/fonts, fbcon: Use font_data_t for rotated fonts Thomas Zimmermann
2026-11-20 12:01   ` sashiko-bot
2026-11-20 11:49 ` [PATCH v2 4/6] fbcon: Refactor size calculation for cursor buffers Thomas Zimmermann
2026-11-20 11:49 ` [PATCH v2 5/6] fbcon: Look up glyphs using the font interface Thomas Zimmermann
2026-11-20 12:22   ` sashiko-bot [this message]
2026-11-20 11:49 ` [PATCH v2 6/6] fbcon: Handle characters with no glyph defined in a consistent way Thomas Zimmermann
2026-11-20 12:28   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-225136@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.