Skip to content

Commit a5a9230

Browse files
Shigeru Yoshidahdeller
Shigeru Yoshida
authored andcommitted
fbdev: fbcon: Properly revert changes when vc_resize() failed
fbcon_do_set_font() calls vc_resize() when font size is changed. However, if if vc_resize() failed, current implementation doesn't revert changes for font size, and this causes inconsistent state. syzbot reported unable to handle page fault due to this issue [1]. syzbot's repro uses fault injection which cause failure for memory allocation, so vc_resize() failed. This patch fixes this issue by properly revert changes for font related date when vc_resize() failed. Link: https://syzkaller.appspot.com/bug?id=3443d3a1fa6d964dd7310a0cb1696d165a3e07c4 [1] Reported-by: [email protected] Signed-off-by: Shigeru Yoshida <[email protected]> Signed-off-by: Helge Deller <[email protected]> CC: [email protected] # 5.15+
1 parent 8d02685 commit a5a9230

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

drivers/video/fbdev/core/fbcon.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -2401,15 +2401,21 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
24012401
struct fb_info *info = fbcon_info_from_console(vc->vc_num);
24022402
struct fbcon_ops *ops = info->fbcon_par;
24032403
struct fbcon_display *p = &fb_display[vc->vc_num];
2404-
int resize;
2404+
int resize, ret, old_userfont, old_width, old_height, old_charcount;
24052405
char *old_data = NULL;
24062406

24072407
resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
24082408
if (p->userfont)
24092409
old_data = vc->vc_font.data;
24102410
vc->vc_font.data = (void *)(p->fontdata = data);
2411+
old_userfont = p->userfont;
24112412
if ((p->userfont = userfont))
24122413
REFCOUNT(data)++;
2414+
2415+
old_width = vc->vc_font.width;
2416+
old_height = vc->vc_font.height;
2417+
old_charcount = vc->vc_font.charcount;
2418+
24132419
vc->vc_font.width = w;
24142420
vc->vc_font.height = h;
24152421
vc->vc_font.charcount = charcount;
@@ -2425,7 +2431,9 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
24252431
rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
24262432
cols /= w;
24272433
rows /= h;
2428-
vc_resize(vc, cols, rows);
2434+
ret = vc_resize(vc, cols, rows);
2435+
if (ret)
2436+
goto err_out;
24292437
} else if (con_is_visible(vc)
24302438
&& vc->vc_mode == KD_TEXT) {
24312439
fbcon_clear_margins(vc, 0);
@@ -2435,6 +2443,21 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
24352443
if (old_data && (--REFCOUNT(old_data) == 0))
24362444
kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
24372445
return 0;
2446+
2447+
err_out:
2448+
p->fontdata = old_data;
2449+
vc->vc_font.data = (void *)old_data;
2450+
2451+
if (userfont) {
2452+
p->userfont = old_userfont;
2453+
REFCOUNT(data)--;
2454+
}
2455+
2456+
vc->vc_font.width = old_width;
2457+
vc->vc_font.height = old_height;
2458+
vc->vc_font.charcount = old_charcount;
2459+
2460+
return ret;
24382461
}
24392462

24402463
/*

0 commit comments

Comments
 (0)