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 3/6] lib/fonts, fbcon: Use font_data_t for rotated fonts
Date: Fri, 20 Nov 2026 12:01:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-225104@kernel.org> (raw)
In-Reply-To: <20261120115215.52092-4-tzimmermann@suse.de>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] fbcon: invalid kfree() of font_data_t pointer in
  fbcon_do_set_font()
- [Low] lib/fonts: contradictory kernel-doc comment for
  font_data_rotate()
--

commit b5f0d07cd7c39fad0c72c3148ca9444f977625ca
Author: Thomas Zimmermann <tzimmermann@suse.de>

lib/fonts, fbcon: Use font_data_t for rotated fonts

This commit converts font_data_rotate() and struct fbcon_rotated.buf to
use font_data_t instead of unsigned char *, releasing rotated font data in
fbcon with font_data_put().

> diff --git a/drivers/video/fbdev/core/fbcon.h b/drivers/video/fbdev/core/fbcon.h
> index 289a3d18f917f..28111c706e348 100644
> --- a/drivers/video/fbdev/core/fbcon.h
> +++ b/drivers/video/fbdev/core/fbcon.h
> @@ -75,8 +75,7 @@ struct fbcon_bitops {
>  #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
>  struct fbcon_rotated {
>  	font_data_t *fontdata;       /* source font */
> -	unsigned char *buf;          /* rotated glyphs */
> -	size_t bufsize;
> +	font_data_t *buf;            /* rotated font */
>  	int buf_rotate;              /* rotation of buf */
>  	unsigned int buf_width;      /* geometry of source font */
>  	unsigned int buf_height;

[Severity: High]
Does fbcon_do_set_font() still pass struct fbcon_rotated.buf directly to
kfree() when changing the font on a visible rotated console?

drivers/video/fbdev/core/fbcon.c:fbcon_do_set_font() {
    ...
#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
	if (rotated_saved)
		kfree(saved_rotated.buf);
#endif
    ...
err_out:
#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
	if (rotated_saved) {
		kfree(par->rotated.buf);
		par->rotated = saved_rotated;
	}
#endif
    ...
}

Because __font_data_alloc() returns &font_data->data[0] (offset 16 bytes
past the start of struct font_data), calling kfree() on saved_rotated.buf
or par->rotated.buf frees an interior pointer and corrupts the slab. Both
paths need to check for a non-NULL buffer and release it with
font_data_put() instead.

[ ... ]

> diff --git a/lib/fonts/font_rotate.c b/lib/fonts/font_rotate.c
> index 275406008823b..ea54bd618ffb0 100644
> --- a/lib/fonts/font_rotate.c
> +++ b/lib/fonts/font_rotate.c
> @@ -181,8 +181,7 @@ EXPORT_SYMBOL_GPL(font_glyph_rotate_270);
>   * @height: The number of scanlines in the glyph
>   * @charcount: The number of glyphs in the font
>   * @steps: Number of rotation steps of 90°
> - * @buf: Preallocated output buffer; can be NULL
> - * @bufsize: The size of @buf in bytes; can be NULL
> + * @buf: Preallocated font data; can be NULL
>   *
>   * The parameters @width and @height refer to the visible number of pixels
>   * and scanlines in a single glyph. The number of glyphs is given in @charcount.
> @@ -194,16 +193,14 @@ EXPORT_SYMBOL_GPL(font_glyph_rotate_270);
>   * as returned by font_data_buf(). Callers are responsible to free the returned
>   * buffer with kfree(). Font rotation typically happens when displays get
>   * re-oriented. To avoid unnecessary re-allocation of the memory buffer, the
> - * caller can pass in an earlier result buffer in @buf for reuse. The old and
> - * new buffer sizes are given and retrieved by the caller in @bufsize. The
> - * allocation semantics are compatible with krealloc().
> + * caller can pass in an earlier result in @buf for reuse. The returned font
> + * data should be released with font_data_put().

[Severity: Low]
This isn't a bug, but the earlier sentences in this kernel-doc comment
still say that the returned buffer is not compatible with font_data_t and
must be freed with kfree(), contradicting the new sentence at the end.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120115215.52092-1-tzimmermann@suse.de?part=3

  reply	other threads:[~2026-11-20 12:01 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 [this message]
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
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-225104@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.