提交 22c770e5 编写于 作者: L Linus Torvalds 提交者: Yang Yingliang

tty: make FONTX ioctl use the tty pointer they were actually passed

mainline inclusion
from mainline-v5.10-rc3
commit 90bfdeef
category: bugfix
bugzilla: NA
CVE: CVE-2020-25668

--------------------------------

Some of the font tty ioctl's always used the current foreground VC for
their operations.  Don't do that then.

This fixes a data race on fg_console.

Side note: both Michael Ellerman and Jiri Slaby point out that all these
ioctls are deprecated, and should probably have been removed long ago,
and everything seems to be using the KDFONTOP ioctl instead.

In fact, Michael points out that it looks like busybox's loadfont
program seems to have switched over to using KDFONTOP exactly _because_
of this bug (ahem.. 12 years ago ;-).
Reported-by: NMinh Yuan <yuanmingbuaa@gmail.com>
Acked-by: NMichael Ellerman <mpe@ellerman.id.au>
Acked-by: NJiri Slaby <jirislaby@kernel.org>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Conflicts:
  drivers/tty/vt/vt_ioctl.c
[yyl: There is no vt_io_fontreset(), change the vc_cons to vc in do_fontx_ioctl()]
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Reviewed-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 3cbadfe3
...@@ -244,7 +244,7 @@ int vt_waitactive(int n) ...@@ -244,7 +244,7 @@ int vt_waitactive(int n)
static inline int static inline int
do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op) do_fontx_ioctl(struct vc_data *vc, int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op)
{ {
struct consolefontdesc cfdarg; struct consolefontdesc cfdarg;
int i; int i;
...@@ -262,15 +262,16 @@ do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struc ...@@ -262,15 +262,16 @@ do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struc
op->height = cfdarg.charheight; op->height = cfdarg.charheight;
op->charcount = cfdarg.charcount; op->charcount = cfdarg.charcount;
op->data = cfdarg.chardata; op->data = cfdarg.chardata;
return con_font_op(vc_cons[fg_console].d, op); return con_font_op(vc, op);
case GIO_FONTX: {
case GIO_FONTX:
op->op = KD_FONT_OP_GET; op->op = KD_FONT_OP_GET;
op->flags = KD_FONT_FLAG_OLD; op->flags = KD_FONT_FLAG_OLD;
op->width = 8; op->width = 8;
op->height = cfdarg.charheight; op->height = cfdarg.charheight;
op->charcount = cfdarg.charcount; op->charcount = cfdarg.charcount;
op->data = cfdarg.chardata; op->data = cfdarg.chardata;
i = con_font_op(vc_cons[fg_console].d, op); i = con_font_op(vc, op);
if (i) if (i)
return i; return i;
cfdarg.charheight = op->height; cfdarg.charheight = op->height;
...@@ -278,7 +279,6 @@ do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struc ...@@ -278,7 +279,6 @@ do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struc
if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc))) if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc)))
return -EFAULT; return -EFAULT;
return 0; return 0;
}
} }
return -EINVAL; return -EINVAL;
} }
...@@ -914,7 +914,7 @@ int vt_ioctl(struct tty_struct *tty, ...@@ -914,7 +914,7 @@ int vt_ioctl(struct tty_struct *tty,
op.height = 0; op.height = 0;
op.charcount = 256; op.charcount = 256;
op.data = up; op.data = up;
ret = con_font_op(vc_cons[fg_console].d, &op); ret = con_font_op(vc, &op);
break; break;
} }
...@@ -925,7 +925,7 @@ int vt_ioctl(struct tty_struct *tty, ...@@ -925,7 +925,7 @@ int vt_ioctl(struct tty_struct *tty,
op.height = 32; op.height = 32;
op.charcount = 256; op.charcount = 256;
op.data = up; op.data = up;
ret = con_font_op(vc_cons[fg_console].d, &op); ret = con_font_op(vc, &op);
break; break;
} }
...@@ -942,7 +942,7 @@ int vt_ioctl(struct tty_struct *tty, ...@@ -942,7 +942,7 @@ int vt_ioctl(struct tty_struct *tty,
case PIO_FONTX: case PIO_FONTX:
case GIO_FONTX: case GIO_FONTX:
ret = do_fontx_ioctl(cmd, up, perm, &op); ret = do_fontx_ioctl(vc, cmd, up, perm, &op);
break; break;
case PIO_FONTRESET: case PIO_FONTRESET:
...@@ -959,11 +959,11 @@ int vt_ioctl(struct tty_struct *tty, ...@@ -959,11 +959,11 @@ int vt_ioctl(struct tty_struct *tty,
{ {
op.op = KD_FONT_OP_SET_DEFAULT; op.op = KD_FONT_OP_SET_DEFAULT;
op.data = NULL; op.data = NULL;
ret = con_font_op(vc_cons[fg_console].d, &op); ret = con_font_op(vc, &op);
if (ret) if (ret)
break; break;
console_lock(); console_lock();
con_set_default_unimap(vc_cons[fg_console].d); con_set_default_unimap(vc);
console_unlock(); console_unlock();
break; break;
} }
...@@ -1090,8 +1090,9 @@ struct compat_consolefontdesc { ...@@ -1090,8 +1090,9 @@ struct compat_consolefontdesc {
}; };
static inline int static inline int
compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd, compat_fontx_ioctl(struct vc_data *vc, int cmd,
int perm, struct console_font_op *op) struct compat_consolefontdesc __user *user_cfd,
int perm, struct console_font_op *op)
{ {
struct compat_consolefontdesc cfdarg; struct compat_consolefontdesc cfdarg;
int i; int i;
...@@ -1109,7 +1110,8 @@ compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd, ...@@ -1109,7 +1110,8 @@ compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd,
op->height = cfdarg.charheight; op->height = cfdarg.charheight;
op->charcount = cfdarg.charcount; op->charcount = cfdarg.charcount;
op->data = compat_ptr(cfdarg.chardata); op->data = compat_ptr(cfdarg.chardata);
return con_font_op(vc_cons[fg_console].d, op); return con_font_op(vc, op);
case GIO_FONTX: case GIO_FONTX:
op->op = KD_FONT_OP_GET; op->op = KD_FONT_OP_GET;
op->flags = KD_FONT_FLAG_OLD; op->flags = KD_FONT_FLAG_OLD;
...@@ -1117,7 +1119,7 @@ compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd, ...@@ -1117,7 +1119,7 @@ compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd,
op->height = cfdarg.charheight; op->height = cfdarg.charheight;
op->charcount = cfdarg.charcount; op->charcount = cfdarg.charcount;
op->data = compat_ptr(cfdarg.chardata); op->data = compat_ptr(cfdarg.chardata);
i = con_font_op(vc_cons[fg_console].d, op); i = con_font_op(vc, op);
if (i) if (i)
return i; return i;
cfdarg.charheight = op->height; cfdarg.charheight = op->height;
...@@ -1208,7 +1210,7 @@ long vt_compat_ioctl(struct tty_struct *tty, ...@@ -1208,7 +1210,7 @@ long vt_compat_ioctl(struct tty_struct *tty,
*/ */
case PIO_FONTX: case PIO_FONTX:
case GIO_FONTX: case GIO_FONTX:
ret = compat_fontx_ioctl(cmd, up, perm, &op); ret = compat_fontx_ioctl(vc, cmd, up, perm, &op);
break; break;
case KDFONTOP: case KDFONTOP:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册