All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alan Mackenzie" <acm@muc.de>
Cc: dri-devel@lists.freedesktop.org, linux-serial@vger.kernel.org
Subject: Re: [Patch 9/9]: vt: Misc changes, e.g. to #include directives
Date: Thu, 27 Aug 2026 19:25:34 +0000	[thread overview]
Message-ID: <20260827192534.73AF81F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <apCI6JhoH5D7ss34@MAC.fritz.box>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] A Time-of-Check to Time-of-Use (TOCTOU) race condition in `con_font_get()` can lead to a kernel heap buffer overflow.
- [Critical] Pre-calculating the allocation size `c` based on the per-console `vc->vc_font.charcount` causes a heap buffer overflow in `vgacon_font_get()` due to a per-console versus global state mismatch.
--

commit 501185cf94f089f684db150e409e50e6d10bc832
Author: Alan Mackenzie <acm@muc.de>

vt: Misc changes, e.g. to #include directives

Rearrange some #include directives, add some clarifying comments, and some
code changes which didn't fit elsewhere.

> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index baf7c98429e9c..0c389a5643576 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
[ ... ]
> @@ -4967,14 +4968,16 @@ static int con_font_get(struct vc_data *vc, struct console_font_op *op)
>  {
>  	struct console_font font;
>  	int c;
> -	unsigned int vpitch = op->op == KD_FONT_OP_GET_TALL ? op->height : 32;
> +	unsigned int vpitch =
> +		op->op == KD_FONT_OP_GET_TALL ? vc->vc_font.height : 32;
>  
>  	if (vpitch > max_font_height)
>  		return -EINVAL;
>  
>  	void *font_data __free(kvfree) = NULL;
> +	c = DIV_ROUND_UP(vc->vc_font.width, 8) * vpitch * vc->vc_font.charcount;
>  	if (op->data) {
> -		font.data = font_data = kvzalloc(max_font_size, GFP_KERNEL);
> +		font.data = font_data = kvzalloc(c, GFP_KERNEL);

[Severity: Critical]
Does this introduce a race condition regarding the allocation size?

Since the buffer size c is now calculated using vc->vc_font.width and
vc->vc_font.charcount before acquiring the console_lock, couldn't another
thread concurrently call con_font_set(), update the console font dimensions
to be larger, and cause the newly sized font data to be written into this
undersized heap allocation later when vc_sw->con_font_get() is called inside
the lock?

Additionally, can this cause an issue with the vgacon driver due to a mismatch
between per-console and global state?

The vgacon driver tracks whether a 512-character font is in use globally
via vga_512_chars. However, vc->vc_font.charcount is maintained per-console.

If a 512-character font is set on one terminal (setting vga_512_chars to
true), but con_font_get() is called on a different terminal that still
has a 256-character font, this calculation will size the allocation for 256
characters.

The vgacon_font_get() callback will then observe the global flag and
force a read of 512 characters, writing out of bounds into the smaller
buffer during vgacon_do_font_op().

>  		if (!font.data)
>  			return -ENOMEM;
>  	} else
> @@ -4991,8 +4994,6 @@ static int con_font_get(struct vc_data *vc, struct console_font_op *op)
>  			return ret;
>  	}
>  
> -	c = DIV_ROUND_UP(font.width, 8) * vpitch * font.charcount;
> -
>  	if (op->data && font.charcount > op->charcount)
>  		return -ENOSPC;
>  	if (font.width > op->width || font.height > op->height)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/apCEDM2sWv_M354-@MAC.fritz.box?part=9

  reply	other threads:[~2026-08-27 19:25 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 18:38 vt: Enlarge the framebuffer glyph size from 16 to 32 bits Alan Mackenzie
2026-08-27 18:42 ` [Patch 1/9]: Make consolemap.c handle Unicode planes outside BMP Alan Mackenzie
2026-08-27 19:14   ` sashiko-bot
2026-08-28  4:57   ` Jiri Slaby
2026-08-29 11:51     ` Alan Mackenzie
2026-08-27 18:45 ` [Patch 2/9]: Glyph size: Use GLYPH_SZ/HW rather than hardcoded 2, 1 Alan Mackenzie
2026-08-27 19:22   ` sashiko-bot
2026-08-27 18:47 ` [Patch 3/9]: Replace scr_readw/writew by scr_readg/writeg, etc Alan Mackenzie
2026-08-27 19:18   ` sashiko-bot
2026-08-29 12:11   ` Greg Kroah-Hartman
2026-08-29 13:33     ` Alan Mackenzie
2026-08-27 18:48 ` [Patch 4/9]: Amend internal manipulation of glyph structure Alan Mackenzie
2026-08-27 19:19   ` sashiko-bot
2026-08-27 18:50 ` [Patch 5/9]: vt: Amend three Kconfig files Alan Mackenzie
2026-08-27 19:12   ` sashiko-bot
2026-08-27 18:52 ` [Patch 6/9]: vt: Use u32 and typedef u1632 to handle whole glyphs Alan Mackenzie
2026-08-27 19:22   ` sashiko-bot
2026-08-27 18:54 ` [Patch 7/9]: vt: Handle up to 2^21 glyphs, rather than 256/512 Alan Mackenzie
2026-08-27 19:14   ` sashiko-bot
2026-08-27 18:56 ` [Patch 8/9]: vt: Enhancements to the VT ioctl interface Alan Mackenzie
2026-08-27 19:25   ` sashiko-bot
2026-08-27 18:58 ` [Patch 9/9]: vt: Misc changes, e.g. to #include directives Alan Mackenzie
2026-08-27 19:25   ` sashiko-bot [this message]
2026-08-29 12:06   ` Greg Kroah-Hartman
2026-08-28  6:12 ` vt: Enlarge the framebuffer glyph size from 16 to 32 bits Thomas Zimmermann
2026-08-28 14:36   ` Alan Mackenzie
2026-08-29 12:09     ` Greg Kroah-Hartman
2026-08-29 14:39       ` Alan Mackenzie
2026-08-31  6:20         ` Thomas Zimmermann
2026-08-31 14:45           ` Alan Mackenzie
2026-08-31 17:21             ` Helge Deller
2026-09-01 11:14               ` Alan Mackenzie

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=20260827192534.73AF81F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=acm@muc.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.