Skip to content

Commit e400b6e

Browse files
adaplasLinus Torvalds
authored andcommitted
vt/vgacon: Check if screen resize request comes from userspace
Various console drivers are able to resize the screen via the con_resize() hook. This hook is also visible in userspace via the TIOCWINSZ, VT_RESIZE and VT_RESIZEX ioctl's. One particular utility, SVGATextMode, expects that con_resize() of the VGA console will always return success even if the resulting screen is not compatible with the hardware. However, this particular behavior of the VGA console, as reported in Kernel Bugzilla Bug 7513, can cause undefined behavior if the user starts with a console size larger than 80x25. To work around this problem, add an extra parameter to con_resize(). This parameter is ignored by drivers except for vgacon. If this parameter is non-zero, then the resize request came from a VT_RESIZE or VT_RESIZEX ioctl and vgacon will always return success. If this parameter is zero, vgacon will return -EINVAL if the requested size is not compatible with the hardware. The latter is the more correct behavior. With this change, SVGATextMode should still work correctly while in-kernel and stty resize calls can expect correct behavior from vgacon. Signed-off-by: Antonino Daplas <adaplas@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0058f47 commit e400b6e

7 files changed

Lines changed: 32 additions & 12 deletions

File tree

‎drivers/char/vt.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,15 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
750750
return 0;
751751
}
752752

753-
static inline int resize_screen(struct vc_data *vc, int width, int height)
753+
static inline int resize_screen(struct vc_data *vc, int width, int height,
754+
int user)
754755
{
755756
/* Resizes the resolution of the display adapater */
756757
int err = 0;
757758

758759
if (vc->vc_mode != KD_GRAPHICS && vc->vc_sw->con_resize)
759-
err = vc->vc_sw->con_resize(vc, width, height);
760+
err = vc->vc_sw->con_resize(vc, width, height, user);
761+
760762
return err;
761763
}
762764

@@ -772,14 +774,17 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
772774
unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
773775
unsigned int old_cols, old_rows, old_row_size, old_screen_size;
774776
unsigned int new_cols, new_rows, new_row_size, new_screen_size;
775-
unsigned int end;
777+
unsigned int end, user;
776778
unsigned short *newscreen;
777779

778780
WARN_CONSOLE_UNLOCKED();
779781

780782
if (!vc)
781783
return -ENXIO;
782784

785+
user = vc->vc_resize_user;
786+
vc->vc_resize_user = 0;
787+
783788
if (cols > VC_RESIZE_MAXCOL || lines > VC_RESIZE_MAXROW)
784789
return -EINVAL;
785790

@@ -800,7 +805,7 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
800805
old_row_size = vc->vc_size_row;
801806
old_screen_size = vc->vc_screenbuf_size;
802807

803-
err = resize_screen(vc, new_cols, new_rows);
808+
err = resize_screen(vc, new_cols, new_rows, user);
804809
if (err) {
805810
kfree(newscreen);
806811
return err;

‎drivers/char/vt_ioctl.c‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,14 +847,24 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
847847
case VT_RESIZE:
848848
{
849849
struct vt_sizes __user *vtsizes = up;
850+
struct vc_data *vc;
851+
850852
ushort ll,cc;
851853
if (!perm)
852854
return -EPERM;
853855
if (get_user(ll, &vtsizes->v_rows) ||
854856
get_user(cc, &vtsizes->v_cols))
855857
return -EFAULT;
856-
for (i = 0; i < MAX_NR_CONSOLES; i++)
857-
vc_lock_resize(vc_cons[i].d, cc, ll);
858+
859+
for (i = 0; i < MAX_NR_CONSOLES; i++) {
860+
vc = vc_cons[i].d;
861+
862+
if (vc) {
863+
vc->vc_resize_user = 1;
864+
vc_lock_resize(vc_cons[i].d, cc, ll);
865+
}
866+
}
867+
858868
return 0;
859869
}
860870

@@ -900,6 +910,7 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
900910
vc_cons[i].d->vc_scan_lines = vlin;
901911
if (clin)
902912
vc_cons[i].d->vc_font.height = clin;
913+
vc_cons[i].d->vc_resize_user = 1;
903914
vc_resize(vc_cons[i].d, cc, ll);
904915
release_console_sem();
905916
}

‎drivers/usb/misc/sisusbvga/sisusb_con.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,8 @@ sisusbcon_set_origin(struct vc_data *c)
10421042

10431043
/* Interface routine */
10441044
static int
1045-
sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows)
1045+
sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows,
1046+
unsigned int user)
10461047
{
10471048
struct sisusb_usb_data *sisusb;
10481049
int fh;

‎drivers/video/console/fbcon.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,7 @@ static __inline__ void updatescrollmode(struct display *p,
21682168
}
21692169

21702170
static int fbcon_resize(struct vc_data *vc, unsigned int width,
2171-
unsigned int height)
2171+
unsigned int height, unsigned int user)
21722172
{
21732173
struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
21742174
struct fbcon_ops *ops = info->fbcon_par;

‎drivers/video/console/vgacon.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,13 +1278,14 @@ static int vgacon_font_get(struct vc_data *c, struct console_font *font)
12781278
#endif
12791279

12801280
static int vgacon_resize(struct vc_data *c, unsigned int width,
1281-
unsigned int height)
1281+
unsigned int height, unsigned int user)
12821282
{
12831283
if (width % 2 || width > ORIG_VIDEO_COLS ||
12841284
height > (ORIG_VIDEO_LINES * vga_default_font_height)/
12851285
c->vc_font.height)
1286-
/* let svgatextmode tinker with video timings */
1287-
return 0;
1286+
/* let svgatextmode tinker with video timings and
1287+
return success */
1288+
return (user) ? 0 : -EINVAL;
12881289

12891290
if (CON_IS_VISIBLE(c) && !vga_is_gfx) /* who knows */
12901291
vgacon_doresize(c, width, height);

‎include/linux/console.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ struct consw {
4545
int (*con_font_get)(struct vc_data *, struct console_font *);
4646
int (*con_font_default)(struct vc_data *, struct console_font *, char *);
4747
int (*con_font_copy)(struct vc_data *, int);
48-
int (*con_resize)(struct vc_data *, unsigned int, unsigned int);
48+
int (*con_resize)(struct vc_data *, unsigned int, unsigned int,
49+
unsigned int);
4950
int (*con_set_palette)(struct vc_data *, unsigned char *);
5051
int (*con_scrolldelta)(struct vc_data *, int);
5152
int (*con_set_origin)(struct vc_data *);

‎include/linux/console_struct.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct vc_data {
100100
unsigned char vc_G1_charset;
101101
unsigned char vc_saved_G0;
102102
unsigned char vc_saved_G1;
103+
unsigned int vc_resize_user; /* resize request from user */
103104
unsigned int vc_bell_pitch; /* Console bell pitch */
104105
unsigned int vc_bell_duration; /* Console bell duration */
105106
struct vc_data **vc_display_fg; /* [!] Ptr to var holding fg console for this display */

0 commit comments

Comments
 (0)