All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
@ 2026-02-27 14:43 Chen Jun
  2026-02-27 14:53 ` chenjun (AM)
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Chen Jun @ 2026-02-27 14:43 UTC (permalink / raw)
  To: simona, deller, tzimmermann, linux-fbdev, linux-kernel
  Cc: chenjun102, linruifeng4

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;
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  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)
  2026-02-27 15:56 ` Thomas Zimmermann
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: chenjun (AM) @ 2026-02-27 14:53 UTC (permalink / raw)
  To: simona@ffwll.ch, deller@gmx.de, tzimmermann@suse.de,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: linruifeng (A)

在 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  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)
@ 2026-02-27 15:56 ` Thomas Zimmermann
  2026-02-28  1:53   ` chenjun (AM)
  2026-02-28  4:08 ` kernel test robot
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 15+ messages in thread
From: Thomas Zimmermann @ 2026-02-27 15:56 UTC (permalink / raw)
  To: Chen Jun, simona, deller, linux-fbdev, linux-kernel; +Cc: linruifeng4

Hi,

thanks for the patch.

Am 27.02.26 um 15:43 schrieb Chen Jun:
> 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.

I looked through vc_resize() but cannot quite find the logic that calls 
fbcon_rotate_font(). Can you please point to correct place?

Best regards
Thomas

>
> 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;

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-02-27 15:56 ` Thomas Zimmermann
@ 2026-02-28  1:53   ` chenjun (AM)
  2026-03-02 10:18     ` Thomas Zimmermann
  0 siblings, 1 reply; 15+ messages in thread
From: chenjun (AM) @ 2026-02-28  1:53 UTC (permalink / raw)
  To: Thomas Zimmermann, simona@ffwll.ch, deller@gmx.de,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: linruifeng (A)

在 2026/2/27 23:56, Thomas Zimmermann 写道:
> Hi,
> 
> thanks for the patch.
> 
> Am 27.02.26 um 15:43 schrieb Chen Jun:
>> 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.
> 
> I looked through vc_resize() but cannot quite find the logic that calls
> fbcon_rotate_font(). Can you please point to correct place?
> 
> Best regards
> Thomas
> 

Hi, fbcon_rouate_font is called in fbcon_switch

[   64.669554] CPU: 3 UID: 0 PID: 978 Comm: a.out Not tainted 
7.0.0-rc1-00021-gd9d32e5bd5a4-dirty #10 PREEMPT(lazy)
[   64.669576] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), 
BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/4
[   64.669584] Call Trace: 

[   64.669589]  <TASK> 

[   64.669595]  dump_stack_lvl+0x53/0x70 

[   64.669615]  fbcon_rotate_font+0x2d6/0xe90 

[   64.669636]  ? kfree+0x159/0x3b0 

[   64.669650]  ? ud_cursor+0x830/0x1d80 

[   64.669661]  ? __kmalloc_noprof+0x198/0x4a0 

[   64.669674]  fbcon_switch+0x67b/0x10f0 

[   64.669689]  ? __pfx_fbcon_switch+0x10/0x10 

[   64.669708]  ? con_is_visible+0xb0/0x130 

[   64.669723]  redraw_screen+0x258/0x690 

[   64.669736]  ? mutex_unlock+0x7d/0xd0 

[   64.669751]  ? __pfx_redraw_screen+0x10/0x10 

[   64.669764]  ? tty_get_pgrp+0x73/0xb0 

[   64.669784]  vc_do_resize+0x9a5/0xec0 

[   64.669803]  ? __pfx_vc_do_resize+0x10/0x10 

[   64.669815]  ? kernel_fpu_begin_mask+0x1c5/0x210 

[   64.669832]  ? __pfx_kernel_fpu_begin_mask+0x10/0x10 

[   64.669843]  ? fbcon_set_font+0x2cb/0x8c0 

[   64.669853]  ? __kasan_kmalloc_large+0x81/0xa0 

[   64.669863]  ? __kmalloc_large_node_noprof+0x18/0xb0 

[   64.669874]  fbcon_do_set_font+0x390/0xa70 

[   64.669890]  ? __pfx_fbcon_set_font+0x10/0x10 

[   64.669900]  con_font_op+0x7d5/0xc30 

[   64.669910]  ? arch_stack_walk+0x9f/0xf0 

[   64.669924]  ? __pfx_con_font_op+0x10/0x10 

[   64.669940]  vt_ioctl+0x8ee/0x2480 

[   64.669953]  ? __pfx_vt_ioctl+0x10/0x10 

[   64.669964]  ? __x64_sys_open+0x79/0xc0 

[   64.669976]  ? do_syscall_64+0xfa/0x570 

[   64.669986]  ? entry_SYSCALL_64_after_hwframe+0x77/0x7f 

[   64.669996]  ? __pfx_path_openat+0x10/0x10 

[   64.670006]  ? __pfx_avc_has_extended_perms+0x10/0x10 

[   64.670022]  ? _raw_spin_lock+0x7f/0xd0 

[   64.670040]  ? do_file_open+0x22f/0x2b0 

[   64.670048]  ? pte_offset_map_lock+0xe2/0x1e0 

[   64.670070]  ? __pfx_do_file_open+0x10/0x10 

[   64.670082]  tty_ioctl+0x3e7/0x1190 

[   64.670098]  ? __pfx_tty_ioctl+0x10/0x10 

[   64.670109]  ? __pfx_do_vfs_ioctl+0x10/0x10 

[   64.670124]  ? ioctl_has_perm.constprop.74+0x2e1/0x4f0 

[   64.670137]  ? __pfx_ioctl_has_perm.constprop.74+0x10/0x10 

[   64.670148]  ? __pfx_do_sys_openat2+0x10/0x10 

[   64.670191]  __x64_sys_ioctl+0x130/0x1a0 

[   64.670204]  do_syscall_64+0xfa/0x570 

[   64.670214]  entry_SYSCALL_64_after_hwframe+0x77/0x7f 

[   64.670223] RIP: 0033:0x7ff56cb0c577 

[   64.670233] Code: b3 66 90 48 8b 05 11 89 2c 00 64 c7 00 26 00 00 00 
48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 8
[   64.670242] RSP: 002b:00007fff94ab6a48 EFLAGS: 00000206 ORIG_RAX: 
0000000000000010
[   64.670256] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 
00007ff56cb0c577
[   64.670263] RDX: 00007fff94ab6a60 RSI: 0000000000004b72 RDI: 
0000000000000003
[   64.670269] RBP: 00007fff94ab6af0 R08: 000055bf68e008d0 R09: 
00007ff56cdec090
[   64.670275] R10: 0000000000000000 R11: 0000000000000206 R12: 
000055bf68e00630
[   64.670281] R13: 00007fff94ab6be0 R14: 0000000000000000 R15: 
0000000000000000
[   64.670293]  </TASK> 


>>
>> 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;
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  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)
  2026-02-27 15:56 ` Thomas Zimmermann
@ 2026-02-28  4:08 ` kernel test robot
  2026-02-28  5:23 ` kernel test robot
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2026-02-28  4:08 UTC (permalink / raw)
  To: Chen Jun; +Cc: oe-kbuild-all

Hi Chen,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on linus/master v7.0-rc1 next-20260227]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Chen-Jun/fbcon-Fix-out-of-bounds-memory-in-fbcon_putcs/20260227-225307
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260227144358.101173-1-chenjun102%40huawei.com
patch subject: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
config: hexagon-randconfig-r071-20260228 (https://download.01.org/0day-ci/archive/20260228/202602281237.VJhwHzj8-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
smatch version: v0.5.0-8994-gd50c5a4c
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260228/202602281237.VJhwHzj8-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602281237.VJhwHzj8-lkp@intel.com/

All errors (new ones prefixed by >>):

>> ld.lld: error: undefined symbol: fbcon_rotate_font
   >>> referenced by fbcon.c
   >>>               drivers/video/fbdev/core/fbcon.o:(fbcon_do_set_font) in archive vmlinux.a
   >>> referenced by fbcon.c
   >>>               drivers/video/fbdev/core/fbcon.o:(fbcon_do_set_font) in archive vmlinux.a

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-02-27 14:43 [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs Chen Jun
                   ` (2 preceding siblings ...)
  2026-02-28  4:08 ` kernel test robot
@ 2026-02-28  5:23 ` kernel test robot
  2026-03-02 10:19 ` Thomas Zimmermann
  2026-03-03 14:15 ` Helge Deller
  5 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2026-02-28  5:23 UTC (permalink / raw)
  To: Chen Jun; +Cc: oe-kbuild-all

Hi Chen,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on linus/master v7.0-rc1 next-20260227]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Chen-Jun/fbcon-Fix-out-of-bounds-memory-in-fbcon_putcs/20260227-225307
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260227144358.101173-1-chenjun102%40huawei.com
patch subject: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
config: x86_64-buildonly-randconfig-005-20260228 (https://download.01.org/0day-ci/archive/20260228/202602281348.05dMV1Vd-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260228/202602281348.05dMV1Vd-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602281348.05dMV1Vd-lkp@intel.com/

All errors (new ones prefixed by >>):

   ld: drivers/video/fbdev/core/fbcon.o: in function `fbcon_do_set_font':
>> fbcon.c:(.text+0x3655): undefined reference to `fbcon_rotate_font'

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-02-28  1:53   ` chenjun (AM)
@ 2026-03-02 10:18     ` Thomas Zimmermann
  0 siblings, 0 replies; 15+ messages in thread
From: Thomas Zimmermann @ 2026-03-02 10:18 UTC (permalink / raw)
  To: chenjun (AM), simona@ffwll.ch, deller@gmx.de,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: linruifeng (A)

Hi

Am 28.02.26 um 02:53 schrieb chenjun (AM):
> 在 2026/2/27 23:56, Thomas Zimmermann 写道:
>> Hi,
>>
>> thanks for the patch.
>>
>> Am 27.02.26 um 15:43 schrieb Chen Jun:
>>> 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.
>> I looked through vc_resize() but cannot quite find the logic that calls
>> fbcon_rotate_font(). Can you please point to correct place?
>>
>> Best regards
>> Thomas
>>
> Hi, fbcon_rouate_font is called in fbcon_switch
>
> [   64.669554] CPU: 3 UID: 0 PID: 978 Comm: a.out Not tainted
> 7.0.0-rc1-00021-gd9d32e5bd5a4-dirty #10 PREEMPT(lazy)
> [   64.669576] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
> BIOS rel-1.13.0-0-gf21b5a4aeb02-prebuilt.qemu.org 04/4
> [   64.669584] Call Trace:
>
> [   64.669589]  <TASK>
>
> [   64.669595]  dump_stack_lvl+0x53/0x70
>
> [   64.669615]  fbcon_rotate_font+0x2d6/0xe90
>
> [   64.669636]  ? kfree+0x159/0x3b0
>
> [   64.669650]  ? ud_cursor+0x830/0x1d80
>
> [   64.669661]  ? __kmalloc_noprof+0x198/0x4a0
>
> [   64.669674]  fbcon_switch+0x67b/0x10f0
>
> [   64.669689]  ? __pfx_fbcon_switch+0x10/0x10
>
> [   64.669708]  ? con_is_visible+0xb0/0x130
>
> [   64.669723]  redraw_screen+0x258/0x690

Thanks. Somehow I made a wrong turn in redraw_screen()

Best regards
Thomas

>
> [   64.669736]  ? mutex_unlock+0x7d/0xd0
>
> [   64.669751]  ? __pfx_redraw_screen+0x10/0x10
>
> [   64.669764]  ? tty_get_pgrp+0x73/0xb0
>
> [   64.669784]  vc_do_resize+0x9a5/0xec0
>
> [   64.669803]  ? __pfx_vc_do_resize+0x10/0x10
>
> [   64.669815]  ? kernel_fpu_begin_mask+0x1c5/0x210
>
> [   64.669832]  ? __pfx_kernel_fpu_begin_mask+0x10/0x10
>
> [   64.669843]  ? fbcon_set_font+0x2cb/0x8c0
>
> [   64.669853]  ? __kasan_kmalloc_large+0x81/0xa0
>
> [   64.669863]  ? __kmalloc_large_node_noprof+0x18/0xb0
>
> [   64.669874]  fbcon_do_set_font+0x390/0xa70
>
> [   64.669890]  ? __pfx_fbcon_set_font+0x10/0x10
>
> [   64.669900]  con_font_op+0x7d5/0xc30
>
> [   64.669910]  ? arch_stack_walk+0x9f/0xf0
>
> [   64.669924]  ? __pfx_con_font_op+0x10/0x10
>
> [   64.669940]  vt_ioctl+0x8ee/0x2480
>
> [   64.669953]  ? __pfx_vt_ioctl+0x10/0x10
>
> [   64.669964]  ? __x64_sys_open+0x79/0xc0
>
> [   64.669976]  ? do_syscall_64+0xfa/0x570
>
> [   64.669986]  ? entry_SYSCALL_64_after_hwframe+0x77/0x7f
>
> [   64.669996]  ? __pfx_path_openat+0x10/0x10
>
> [   64.670006]  ? __pfx_avc_has_extended_perms+0x10/0x10
>
> [   64.670022]  ? _raw_spin_lock+0x7f/0xd0
>
> [   64.670040]  ? do_file_open+0x22f/0x2b0
>
> [   64.670048]  ? pte_offset_map_lock+0xe2/0x1e0
>
> [   64.670070]  ? __pfx_do_file_open+0x10/0x10
>
> [   64.670082]  tty_ioctl+0x3e7/0x1190
>
> [   64.670098]  ? __pfx_tty_ioctl+0x10/0x10
>
> [   64.670109]  ? __pfx_do_vfs_ioctl+0x10/0x10
>
> [   64.670124]  ? ioctl_has_perm.constprop.74+0x2e1/0x4f0
>
> [   64.670137]  ? __pfx_ioctl_has_perm.constprop.74+0x10/0x10
>
> [   64.670148]  ? __pfx_do_sys_openat2+0x10/0x10
>
> [   64.670191]  __x64_sys_ioctl+0x130/0x1a0
>
> [   64.670204]  do_syscall_64+0xfa/0x570
>
> [   64.670214]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
>
> [   64.670223] RIP: 0033:0x7ff56cb0c577
>
> [   64.670233] Code: b3 66 90 48 8b 05 11 89 2c 00 64 c7 00 26 00 00 00
> 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 8
> [   64.670242] RSP: 002b:00007fff94ab6a48 EFLAGS: 00000206 ORIG_RAX:
> 0000000000000010
> [   64.670256] RAX: ffffffffffffffda RBX: 0000000000000000 RCX:
> 00007ff56cb0c577
> [   64.670263] RDX: 00007fff94ab6a60 RSI: 0000000000004b72 RDI:
> 0000000000000003
> [   64.670269] RBP: 00007fff94ab6af0 R08: 000055bf68e008d0 R09:
> 00007ff56cdec090
> [   64.670275] R10: 0000000000000000 R11: 0000000000000206 R12:
> 000055bf68e00630
> [   64.670281] R13: 00007fff94ab6be0 R14: 0000000000000000 R15:
> 0000000000000000
> [   64.670293]  </TASK>
>
>
>>> 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;
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-02-27 14:43 [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs Chen Jun
                   ` (3 preceding siblings ...)
  2026-02-28  5:23 ` kernel test robot
@ 2026-03-02 10:19 ` Thomas Zimmermann
  2026-03-02 11:24   ` chenjun (AM)
  2026-03-03 14:15 ` Helge Deller
  5 siblings, 1 reply; 15+ messages in thread
From: Thomas Zimmermann @ 2026-03-02 10:19 UTC (permalink / raw)
  To: Chen Jun, simona, deller, linux-fbdev, linux-kernel; +Cc: linruifeng4



Am 27.02.26 um 15:43 schrieb Chen Jun:
> 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>

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
>   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;

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-03-02 10:19 ` Thomas Zimmermann
@ 2026-03-02 11:24   ` chenjun (AM)
  2026-03-02 11:33     ` Thomas Zimmermann
  0 siblings, 1 reply; 15+ messages in thread
From: chenjun (AM) @ 2026-03-02 11:24 UTC (permalink / raw)
  To: Thomas Zimmermann, simona@ffwll.ch, deller@gmx.de,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: linruifeng (A)

在 2026/3/2 18:19, Thomas Zimmermann 写道:
> 
> 
> Am 27.02.26 um 15:43 schrieb Chen Jun:
>> 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>
> 
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

Hi Thomas,

Thanks for your review.

I'm not familiar with the fbcon module. Is there a better way to fix this?

>> ---
>>    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;
> 



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-03-02 11:24   ` chenjun (AM)
@ 2026-03-02 11:33     ` Thomas Zimmermann
  2026-03-04  3:47       ` chenjun (AM)
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Zimmermann @ 2026-03-02 11:33 UTC (permalink / raw)
  To: chenjun (AM), simona@ffwll.ch, deller@gmx.de,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: linruifeng (A)

Hi

Am 02.03.26 um 12:24 schrieb chenjun (AM):
> 在 2026/3/2 18:19, Thomas Zimmermann 写道:
>>
>> Am 27.02.26 um 15:43 schrieb Chen Jun:
>>> 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>
>> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> Hi Thomas,
>
> Thanks for your review.
>
> I'm not familiar with the fbcon module. Is there a better way to fix this?

Not really, I think. The whole module first needs a redesign to be 
easier to understand.

Best regards
Thomas

>
>>> ---
>>>     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;
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-02-27 14:43 [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs Chen Jun
                   ` (4 preceding siblings ...)
  2026-03-02 10:19 ` Thomas Zimmermann
@ 2026-03-03 14:15 ` Helge Deller
  2026-03-03 19:48   ` Helge Deller
  5 siblings, 1 reply; 15+ messages in thread
From: Helge Deller @ 2026-03-03 14:15 UTC (permalink / raw)
  To: Chen Jun, simona, tzimmermann, linux-fbdev, linux-kernel; +Cc: linruifeng4

On 2/27/26 15:43, Chen Jun wrote:
> 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(+)

applied to fbdev git tree.

Thanks!
Helge

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-03-03 14:15 ` Helge Deller
@ 2026-03-03 19:48   ` Helge Deller
  0 siblings, 0 replies; 15+ messages in thread
From: Helge Deller @ 2026-03-03 19:48 UTC (permalink / raw)
  To: Chen Jun, simona, tzimmermann, linux-fbdev, linux-kernel; +Cc: linruifeng4

On 3/3/26 15:15, Helge Deller wrote:
> On 2/27/26 15:43, Chen Jun wrote:
>> 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(+)
> 
> applied to fbdev git tree.

I got a compile error:

hppa-linux-gnu-ld: drivers/video/fbdev/core/fbcon.o: in function `fbcon_do_set_font':
/home/cvs/parisc/git-kernel/linus-linux-2.6/drivers/video/fbdev/core/fbcon.c:2392:(.text+0x1e28): undefined reference to `fbcon_rotate_font'
make[3]: *** [/home/cvs/parisc/git-kernel/linus-linux-2.6/scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 1

I modified your patch like this:

diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
index a58ce1fe320c..1fb28f353168 100644
--- a/drivers/video/fbdev/core/fbcon.c
+++ b/drivers/video/fbdev/core/fbcon.c
@@ -2388,7 +2388,7 @@ 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)) {
+               if (IS_ENABLED(CONFIG_FRAMEBUFFER_CONSOLE_ROTATION) && !con_is_visible(vc)) {
                         ret = fbcon_rotate_font(info, vc);

Helge

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-03-02 11:33     ` Thomas Zimmermann
@ 2026-03-04  3:47       ` chenjun (AM)
  2026-03-04  9:57         ` Thomas Zimmermann
  0 siblings, 1 reply; 15+ messages in thread
From: chenjun (AM) @ 2026-03-04  3:47 UTC (permalink / raw)
  To: Thomas Zimmermann, simona@ffwll.ch, deller@gmx.de,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: linruifeng (A)

在 2026/3/2 19:34, Thomas Zimmermann 写道:
> Hi
> 
> Am 02.03.26 um 12:24 schrieb chenjun (AM):
>> 在 2026/3/2 18:19, Thomas Zimmermann 写道:
>>>
>>> Am 27.02.26 um 15:43 schrieb Chen Jun:
>>>> 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>
>>> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Hi Thomas,
>>
>> Thanks for your review.
>>
>> I'm not familiar with the fbcon module. Is there a better way to fix this?
> 
> Not really, I think. The whole module first needs a redesign to be
> easier to understand.
> 
> Best regards
> Thomas
> 
>>
>>>> ---
>>>>      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;
>>>> +		}

Hi Thomas and Helge,

I apologize, but after reviewing the code, I believe there is a problem.
The issue is that fbcon_do_set_font() updates members of 
info->fbcon_par, and the info are shared with other vc instances.

Best regards
Chen Jun

>>>>      		ret = vc_resize(vc, cols, rows);
>>>>      		if (ret)
>>>>      			goto err_out;
>>
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-03-04  3:47       ` chenjun (AM)
@ 2026-03-04  9:57         ` Thomas Zimmermann
  2026-03-04 13:19           ` Helge Deller
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Zimmermann @ 2026-03-04  9:57 UTC (permalink / raw)
  To: chenjun (AM), simona@ffwll.ch, deller@gmx.de,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: linruifeng (A)

Hi

Am 04.03.26 um 04:47 schrieb chenjun (AM):
> 在 2026/3/2 19:34, Thomas Zimmermann 写道:
>> Hi
>>
>> Am 02.03.26 um 12:24 schrieb chenjun (AM):
>>> 在 2026/3/2 18:19, Thomas Zimmermann 写道:
>>>> Am 27.02.26 um 15:43 schrieb Chen Jun:
>>>>> 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>
>>>> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
>>> Hi Thomas,
>>>
>>> Thanks for your review.
>>>
>>> I'm not familiar with the fbcon module. Is there a better way to fix this?
>> Not really, I think. The whole module first needs a redesign to be
>> easier to understand.
>>
>> Best regards
>> Thomas
>>
>>>>> ---
>>>>>       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;
>>>>> +		}
> Hi Thomas and Helge,
>
> I apologize, but after reviewing the code, I believe there is a problem.
> The issue is that fbcon_do_set_font() updates members of
> info->fbcon_par, and the info are shared with other vc instances.

Than let's drop the patch for now.

My best idea to fix this is to move the rotated font out of fbcon_par. 
The unrotated font data is stored at [1]. The struct fbcon_display 
stores a vc's display settings. It might be possible to move the rotated 
data there as well. Tracked correctly, each vc would have its own 
rotated font. BUT this might also have other side effects.

Best regards
Thomas

[1] 
https://elixir.bootlin.com/linux/v6.19.3/source/drivers/video/fbdev/core/fbcon.h#L28

>
> Best regards
> Chen Jun
>
>>>>>       		ret = vc_resize(vc, cols, rows);
>>>>>       		if (ret)
>>>>>       			goto err_out;
>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC PATCH] fbcon: Fix out-of-bounds memory in fbcon_putcs
  2026-03-04  9:57         ` Thomas Zimmermann
@ 2026-03-04 13:19           ` Helge Deller
  0 siblings, 0 replies; 15+ messages in thread
From: Helge Deller @ 2026-03-04 13:19 UTC (permalink / raw)
  To: Thomas Zimmermann, chenjun (AM), simona@ffwll.ch,
	linux-fbdev@vger.kernel.org
  Cc: linruifeng (A)

On 3/4/26 10:57, Thomas Zimmermann wrote:
> Hi
> 
> Am 04.03.26 um 04:47 schrieb chenjun (AM):
>> 在 2026/3/2 19:34, Thomas Zimmermann 写道:
>>> Hi
>>>
>>> Am 02.03.26 um 12:24 schrieb chenjun (AM):
>>>> 在 2026/3/2 18:19, Thomas Zimmermann 写道:
>>>>> Am 27.02.26 um 15:43 schrieb Chen Jun:
>>>>>> 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>
>>>>> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
>>>> Hi Thomas,
>>>>
>>>> Thanks for your review.
>>>>
>>>> I'm not familiar with the fbcon module. Is there a better way to fix this?
>>> Not really, I think. The whole module first needs a redesign to be
>>> easier to understand.
>>>
>>> Best regards
>>> Thomas
>>>
>>>>>> ---
>>>>>>       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;
>>>>>> +        }
>> Hi Thomas and Helge,
>>
>> I apologize, but after reviewing the code, I believe there is a problem.
>> The issue is that fbcon_do_set_font() updates members of
>> info->fbcon_par, and the info are shared with other vc instances.
> 
> Than let's drop the patch for now.

Patch is now dropped from fbdev git tree.

Helge

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-03-04 13:19 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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)
2026-02-27 15:56 ` Thomas Zimmermann
2026-02-28  1:53   ` chenjun (AM)
2026-03-02 10:18     ` Thomas Zimmermann
2026-02-28  4:08 ` kernel test robot
2026-02-28  5:23 ` kernel test robot
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

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.