From: "chenjun (AM)" <chenjun102@huawei.com>
To: "simona@ffwll.ch" <simona@ffwll.ch>,
"deller@gmx.de" <deller@gmx.de>,
"tzimmermann@suse.de" <tzimmermann@suse.de>,
"linux-fbdev@vger.kernel.org" <linux-fbdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "linruifeng (A)" <linruifeng4@huawei.com>
Subject: Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
Date: Fri, 27 Feb 2026 14:53:42 +0000 [thread overview]
Message-ID: <e300c23760df488aaaa0648c4593c802@huawei.com> (raw)
In-Reply-To: 20260227144358.101173-1-chenjun102@huawei.com
在 2026/2/27 22:50, chenjun (AM) 写道:
> When a font is set on an invisible console, the screen will not update.
> However, the fontbuffer is not updated to match the new font dimensions.
>
> This inconsistency leads to out-of-bounds memory access when writing to
> the tty bound to fbcon, as demonstrated by the following KASAN report:
>
> BUG: KASAN: slab-out-of-bounds in fb_pad_aligned_buffer+0xdf/0x140
> Read of size 1 at addr ffff8881195a2280 by task a.out/971
> Call Trace:
> <TASK>
> fb_pad_aligned_buffer+0xdf/0x140
> ud_putcs+0x88a/0xde0
> fbcon_putcs+0x319/0x430
> do_update_region+0x23c/0x3b0
> do_con_write+0x225c/0x67f0
> con_write+0xe/0x30
> n_tty_write+0x4b5/0xff0
> file_tty_write.isra.41+0x46c/0x880
> vfs_write+0x868/0xd60
> ksys_write+0xf2/0x1d0
> do_syscall_64+0xfa/0x570
>
> Fix this by calling fbcon_rotate_font() if vc is invisible in
> fbcon_do_set_font().
>
> Signed-off-by: Chen Jun <chenjun102@huawei.com>
> ---
> drivers/video/fbdev/core/fbcon.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
> index 666261ae59d8..d76100188bee 100644
> --- a/drivers/video/fbdev/core/fbcon.c
> +++ b/drivers/video/fbdev/core/fbcon.c
> @@ -2444,6 +2444,11 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
> rows = FBCON_SWAP(par->rotate, info->var.yres, info->var.xres);
> cols /= w;
> rows /= h;
> + if (!con_is_visible(vc)) {
> + ret = fbcon_rotate_font(info, vc);
> + if (ret)
> + goto err_out;
> + }
> ret = vc_resize(vc, cols, rows);
> if (ret)
> goto err_out;
>
There is a poc:
```
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <linux/capability.h>
char my_font_data[512 * 1 * 32 * 32];
struct console_font_op {
unsigned int op;
unsigned int flags;
unsigned int width, height;
unsigned int charcount;
unsigned char *data;
};
void execute_one(void)
{
int tty = open("/dev/tty2", O_APPEND|O_RDWR, 0);
char buf[100] = {27, '#', '8', 0xa, 0x5, 0x5, 0x5, 0x5};
struct console_font_op op = {
.op = 0,
.width = 32,
.height = 32,
.charcount = 512,
.data = my_font_data,
};
ioctl(tty, 0x4B72, &op);
write(tty, buf, 100);
}
int main(void)
{
execute_one();
return 0;
}
```
echo 2 > /sys/class/graphics/fbcon/rotate_all
./poc
next prev parent reply other threads:[~2026-02-27 14:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-27 14:43 [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs Chen Jun
2026-02-27 14:53 ` chenjun (AM) [this message]
2026-02-27 15:56 ` Thomas Zimmermann
2026-02-28 1:53 ` chenjun (AM)
2026-03-02 10:18 ` Thomas Zimmermann
2026-03-02 10:19 ` Thomas Zimmermann
2026-03-02 11:24 ` chenjun (AM)
2026-03-02 11:33 ` Thomas Zimmermann
2026-03-04 3:47 ` chenjun (AM)
2026-03-04 9:57 ` Thomas Zimmermann
2026-03-04 13:19 ` Helge Deller
2026-03-03 14:15 ` Helge Deller
2026-03-03 19:48 ` Helge Deller
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=e300c23760df488aaaa0648c4593c802@huawei.com \
--to=chenjun102@huawei.com \
--cc=deller@gmx.de \
--cc=linruifeng4@huawei.com \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=simona@ffwll.ch \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox