diff mbox series

fbcon: Avoid showing softcursor if font not available

Message ID ZHHLBpGkHBmIpGT9@ls3530
State New
Headers show
Series fbcon: Avoid showing softcursor if font not available | expand

Commit Message

Helge Deller May 27, 2023, 9:19 a.m. UTC
syzbot repored this bug in the softcursor code:

BUG: KASAN: null-ptr-deref in soft_cursor+0x384/0x6b4 drivers/video/fbdev/core/softcursor.c:70
Read of size 16 at addr 0000000000000200 by task kworker/u4:1/12

CPU: 0 PID: 12 Comm: kworker/u4:1 Not tainted 6.4.0-rc3-syzkaller-geb0f1697d729 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/28/2023
Workqueue: events_power_efficient fb_flashcursor
Call trace:
 dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
 show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
 print_report+0xe4/0x514 mm/kasan/report.c:465
 kasan_report+0xd4/0x130 mm/kasan/report.c:572
 kasan_check_range+0x264/0x2a4 mm/kasan/generic.c:187
 __asan_memcpy+0x3c/0x84 mm/kasan/shadow.c:105
 soft_cursor+0x384/0x6b4 drivers/video/fbdev/core/softcursor.c:70
 bit_cursor+0x113c/0x1a64 drivers/video/fbdev/core/bitblit.c:377
 fb_flashcursor+0x35c/0x54c drivers/video/fbdev/core/fbcon.c:380
 process_one_work+0x788/0x12d4 kernel/workqueue.c:2405
 worker_thread+0x8e0/0xfe8 kernel/workqueue.c:2552
 kthread+0x288/0x310 kernel/kthread.c:379
 ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:853

This fix let bit_cursor() bail out early when a font bitmap
isn't available yet.

Signed-off-by: Helge Deller <deller@gmx.de>
Cc: stable@kernel.org
Reported-by: syzbot+d910bd780e6efac35869@syzkaller.appspotmail.com
---
 drivers/video/fbdev/core/bitblit.c | 3 +++
 1 file changed, 3 insertions(+)

--
2.40.1

Comments

Sam Ravnborg May 27, 2023, 10:18 a.m. UTC | #1
Hi Helge,

On Sat, May 27, 2023 at 11:19:02AM +0200, Helge Deller wrote:
> syzbot repored this bug in the softcursor code:
> 
> BUG: KASAN: null-ptr-deref in soft_cursor+0x384/0x6b4 drivers/video/fbdev/core/softcursor.c:70
> Read of size 16 at addr 0000000000000200 by task kworker/u4:1/12
> 
> CPU: 0 PID: 12 Comm: kworker/u4:1 Not tainted 6.4.0-rc3-syzkaller-geb0f1697d729 #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/28/2023
> Workqueue: events_power_efficient fb_flashcursor
> Call trace:
>  dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
>  show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
>  __dump_stack lib/dump_stack.c:88 [inline]
>  dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
>  print_report+0xe4/0x514 mm/kasan/report.c:465
>  kasan_report+0xd4/0x130 mm/kasan/report.c:572
>  kasan_check_range+0x264/0x2a4 mm/kasan/generic.c:187
>  __asan_memcpy+0x3c/0x84 mm/kasan/shadow.c:105
>  soft_cursor+0x384/0x6b4 drivers/video/fbdev/core/softcursor.c:70
>  bit_cursor+0x113c/0x1a64 drivers/video/fbdev/core/bitblit.c:377
>  fb_flashcursor+0x35c/0x54c drivers/video/fbdev/core/fbcon.c:380
>  process_one_work+0x788/0x12d4 kernel/workqueue.c:2405
>  worker_thread+0x8e0/0xfe8 kernel/workqueue.c:2552
>  kthread+0x288/0x310 kernel/kthread.c:379
>  ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:853
> 
> This fix let bit_cursor() bail out early when a font bitmap
> isn't available yet.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> Cc: stable@kernel.org
> Reported-by: syzbot+d910bd780e6efac35869@syzkaller.appspotmail.com
> ---
>  drivers/video/fbdev/core/bitblit.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/video/fbdev/core/bitblit.c b/drivers/video/fbdev/core/bitblit.c
> index f98e8f298bc1..8587c9da0670 100644
> --- a/drivers/video/fbdev/core/bitblit.c
> +++ b/drivers/video/fbdev/core/bitblit.c
> @@ -247,6 +247,9 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
> 
>  	cursor.set = 0;
> 
> +	if (!vc->vc_font.data)
> +		return;
> +
>   	c = scr_readw((u16 *) vc->vc_pos);
>  	attribute = get_attribute(info, c);
>  	src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));

When browsing the code I noticed another use of vc->vc_font.data.

bit_putcs_{un}aligned() access vc->vc_font.data too, so I wonder if
bit_putcs() should also check for vc->vc_font.data?
bit_putcs() is the only user of bit_putcs_{un}aligned.


The actual patch here looks good from a quick browsing around, but I
cannot claim I did a review. But you have my:
Acked-by: Sam Ravnborg <sam@ravnborg.org>

	Sam
Helge Deller May 27, 2023, 5:26 p.m. UTC | #2
On 5/27/23 12:18, Sam Ravnborg wrote:
> Hi Helge,
>
> On Sat, May 27, 2023 at 11:19:02AM +0200, Helge Deller wrote:
>> syzbot repored this bug in the softcursor code:
>>
>> BUG: KASAN: null-ptr-deref in soft_cursor+0x384/0x6b4 drivers/video/fbdev/core/softcursor.c:70
>> Read of size 16 at addr 0000000000000200 by task kworker/u4:1/12
>>
>> CPU: 0 PID: 12 Comm: kworker/u4:1 Not tainted 6.4.0-rc3-syzkaller-geb0f1697d729 #0
>> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/28/2023
>> Workqueue: events_power_efficient fb_flashcursor
>> Call trace:
>>   dump_backtrace+0x1b8/0x1e4 arch/arm64/kernel/stacktrace.c:233
>>   show_stack+0x2c/0x44 arch/arm64/kernel/stacktrace.c:240
>>   __dump_stack lib/dump_stack.c:88 [inline]
>>   dump_stack_lvl+0xd0/0x124 lib/dump_stack.c:106
>>   print_report+0xe4/0x514 mm/kasan/report.c:465
>>   kasan_report+0xd4/0x130 mm/kasan/report.c:572
>>   kasan_check_range+0x264/0x2a4 mm/kasan/generic.c:187
>>   __asan_memcpy+0x3c/0x84 mm/kasan/shadow.c:105
>>   soft_cursor+0x384/0x6b4 drivers/video/fbdev/core/softcursor.c:70
>>   bit_cursor+0x113c/0x1a64 drivers/video/fbdev/core/bitblit.c:377
>>   fb_flashcursor+0x35c/0x54c drivers/video/fbdev/core/fbcon.c:380
>>   process_one_work+0x788/0x12d4 kernel/workqueue.c:2405
>>   worker_thread+0x8e0/0xfe8 kernel/workqueue.c:2552
>>   kthread+0x288/0x310 kernel/kthread.c:379
>>   ret_from_fork+0x10/0x20 arch/arm64/kernel/entry.S:853
>>
>> This fix let bit_cursor() bail out early when a font bitmap
>> isn't available yet.
>>
>> Signed-off-by: Helge Deller <deller@gmx.de>
>> Cc: stable@kernel.org
>> Reported-by: syzbot+d910bd780e6efac35869@syzkaller.appspotmail.com
>> ---
>>   drivers/video/fbdev/core/bitblit.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/video/fbdev/core/bitblit.c b/drivers/video/fbdev/core/bitblit.c
>> index f98e8f298bc1..8587c9da0670 100644
>> --- a/drivers/video/fbdev/core/bitblit.c
>> +++ b/drivers/video/fbdev/core/bitblit.c
>> @@ -247,6 +247,9 @@ static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,
>>
>>   	cursor.set = 0;
>>
>> +	if (!vc->vc_font.data)
>> +		return;
>> +
>>    	c = scr_readw((u16 *) vc->vc_pos);
>>   	attribute = get_attribute(info, c);
>>   	src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));
>
> When browsing the code I noticed another use of vc->vc_font.data.
>
> bit_putcs_{un}aligned() access vc->vc_font.data too, so I wonder if
> bit_putcs() should also check for vc->vc_font.data?
> bit_putcs() is the only user of bit_putcs_{un}aligned.

I think the font is set before any char is printed, so we should
probably be safe there.

> The actual patch here looks good from a quick browsing around, but I
> cannot claim I did a review. But you have my:
> Acked-by: Sam Ravnborg <sam@ravnborg.org>

Thank you!
Helge
diff mbox series

Patch

diff --git a/drivers/video/fbdev/core/bitblit.c b/drivers/video/fbdev/core/bitblit.c
index f98e8f298bc1..8587c9da0670 100644
--- a/drivers/video/fbdev/core/bitblit.c
+++ b/drivers/video/fbdev/core/bitblit.c
@@ -247,6 +247,9 @@  static void bit_cursor(struct vc_data *vc, struct fb_info *info, int mode,

 	cursor.set = 0;

+	if (!vc->vc_font.data)
+		return;
+
  	c = scr_readw((u16 *) vc->vc_pos);
 	attribute = get_attribute(info, c);
 	src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height));