Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp832336pxb; Tue, 3 Nov 2020 13:50:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwiLRx1FV1R81HxkO03a0FqIA3zzELN5FXOgpETnFysmKzR6EwdfQS98KN1P88vsqVPW1wY X-Received: by 2002:a05:6402:1ad9:: with SMTP id ba25mr1036505edb.120.1604440247275; Tue, 03 Nov 2020 13:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604440247; cv=none; d=google.com; s=arc-20160816; b=wSex41kYXMY0GK1hkUZZXzyXXXmDRhZdPBaf+yFm6XRirAmw8YAnPd0M6vbq5i/7W5 yZnkXU8IAdIwva9YO+Nq0ubrJaDACifgJGik7QV0hqkr3z7GwPR7QV4qq9vpUXvR01dn nIKdXA4yGXM5EITW1JGE6HyzSn8l2V7Jazv7DyMdQBvVbBL/FG9rzmtZI1kz9MIHn5rE k78opFADXvdTuxP1orllm8iyn0f38HRP/jMUi2IX7dJlsWy4urGIkedpNpgdhpkxqf82 cFjmDt/sR3deUptnpRwKtiSyPe/CRM5BraoQVAje9XfRfQU++4VUX8GfTvKGcbcFQpmY +6Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kndzJ4eprB2lJcdiK8KCf8OefsfH/QYyGHvtWJmxN2c=; b=dLaMBwDtVj0Q6T5m4ls9oX5Rc20z6ohgktSN/nKEBL9LUbkURpQU3aNWBAMSSQPdQZ vaXolkpFFIbvGTPEx1Ns21fJjy+B2GIMv/Rv2ywlkfBOqAsaxLsRSfcMz4tiAP4wLXIN vNgdN4lkn7BCNk5j4lx4PHSMCmBCtW5b1FWtBt3N3Xkgmlsh4EUeKKvXHuq0INj58/Zg Qz+ygQe8O3/iAg9glg8xdgM2Md1PcIJo8ip7BCi0fb6JCc0Pv1sgah52wWFn/ntXaHov ZUQYIfPw86lS4KIQbAS0/wlxiEeer/FeiXOXxgr2rCtX2YCuVif44x19jEarmBqS5Yxe wE7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NcWAILUi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a17si6187365eda.321.2020.11.03.13.50.24; Tue, 03 Nov 2020 13:50:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NcWAILUi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732842AbgKCVqw (ORCPT + 99 others); Tue, 3 Nov 2020 16:46:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:46892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731982AbgKCUvf (ORCPT ); Tue, 3 Nov 2020 15:51:35 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4EE0720719; Tue, 3 Nov 2020 20:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436694; bh=1tj8u2Tmffw8pUz/nV4pYbMINdDUfPE18tCYNPuaUcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NcWAILUiX6vZQ0xTYOfA417iwTwxiA90Bw99RerjlkZ4DUcjJmTgRLjuXsByysi5S Iw2HE7SlHH9Y5psv14vDG8UzmyHSrMzlQIy9abDtsMb70dLDzgoLkhjXQW60Ww5AfB jW7rvA+WaGoTuU0pnfbfTaMgWKFjwP4xIIkJMLWE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minh Yuan , Michael Ellerman , Jiri Slaby , Greg KH , Linus Torvalds Subject: [PATCH 5.9 362/391] tty: make FONTX ioctl use the tty pointer they were actually passed Date: Tue, 3 Nov 2020 21:36:53 +0100 Message-Id: <20201103203411.569275318@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds commit 90bfdeef83f1d6c696039b6a917190dcbbad3220 upstream. 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: Minh Yuan Acked-by: Michael Ellerman Acked-by: Jiri Slaby Cc: Greg KH Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/vt_ioctl.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) --- a/drivers/tty/vt/vt_ioctl.c +++ b/drivers/tty/vt/vt_ioctl.c @@ -485,7 +485,7 @@ static int vt_k_ioctl(struct tty_struct return 0; } -static inline int do_fontx_ioctl(int cmd, +static inline int do_fontx_ioctl(struct vc_data *vc, int cmd, struct consolefontdesc __user *user_cfd, struct console_font_op *op) { @@ -503,15 +503,16 @@ static inline int do_fontx_ioctl(int cmd op->height = cfdarg.charheight; op->charcount = cfdarg.charcount; op->data = cfdarg.chardata; - return con_font_op(vc_cons[fg_console].d, op); - case GIO_FONTX: { + return con_font_op(vc, op); + + case GIO_FONTX: op->op = KD_FONT_OP_GET; op->flags = KD_FONT_FLAG_OLD; op->width = 8; op->height = cfdarg.charheight; op->charcount = cfdarg.charcount; op->data = cfdarg.chardata; - i = con_font_op(vc_cons[fg_console].d, op); + i = con_font_op(vc, op); if (i) return i; cfdarg.charheight = op->height; @@ -519,12 +520,11 @@ static inline int do_fontx_ioctl(int cmd if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc))) return -EFAULT; return 0; - } } return -EINVAL; } -static int vt_io_fontreset(struct console_font_op *op) +static int vt_io_fontreset(struct vc_data *vc, struct console_font_op *op) { int ret; @@ -538,12 +538,12 @@ static int vt_io_fontreset(struct consol op->op = KD_FONT_OP_SET_DEFAULT; op->data = NULL; - ret = con_font_op(vc_cons[fg_console].d, op); + ret = con_font_op(vc, op); if (ret) return ret; console_lock(); - con_set_default_unimap(vc_cons[fg_console].d); + con_set_default_unimap(vc); console_unlock(); return 0; @@ -585,7 +585,7 @@ static int vt_io_ioctl(struct vc_data *v op.height = 0; op.charcount = 256; op.data = up; - return con_font_op(vc_cons[fg_console].d, &op); + return con_font_op(vc, &op); case GIO_FONT: op.op = KD_FONT_OP_GET; @@ -594,7 +594,7 @@ static int vt_io_ioctl(struct vc_data *v op.height = 32; op.charcount = 256; op.data = up; - return con_font_op(vc_cons[fg_console].d, &op); + return con_font_op(vc, &op); case PIO_CMAP: if (!perm) @@ -610,13 +610,13 @@ static int vt_io_ioctl(struct vc_data *v fallthrough; case GIO_FONTX: - return do_fontx_ioctl(cmd, up, &op); + return do_fontx_ioctl(vc, cmd, up, &op); case PIO_FONTRESET: if (!perm) return -EPERM; - return vt_io_fontreset(&op); + return vt_io_fontreset(vc, &op); case PIO_SCRNMAP: if (!perm) @@ -1067,8 +1067,9 @@ struct compat_consolefontdesc { }; static inline int -compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd, - int perm, struct console_font_op *op) +compat_fontx_ioctl(struct vc_data *vc, int cmd, + struct compat_consolefontdesc __user *user_cfd, + int perm, struct console_font_op *op) { struct compat_consolefontdesc cfdarg; int i; @@ -1086,7 +1087,8 @@ compat_fontx_ioctl(int cmd, struct compa op->height = cfdarg.charheight; op->charcount = cfdarg.charcount; 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: op->op = KD_FONT_OP_GET; op->flags = KD_FONT_FLAG_OLD; @@ -1094,7 +1096,7 @@ compat_fontx_ioctl(int cmd, struct compa op->height = cfdarg.charheight; op->charcount = cfdarg.charcount; op->data = compat_ptr(cfdarg.chardata); - i = con_font_op(vc_cons[fg_console].d, op); + i = con_font_op(vc, op); if (i) return i; cfdarg.charheight = op->height; @@ -1184,7 +1186,7 @@ long vt_compat_ioctl(struct tty_struct * */ case PIO_FONTX: case GIO_FONTX: - return compat_fontx_ioctl(cmd, up, perm, &op); + return compat_fontx_ioctl(vc, cmd, up, perm, &op); case KDFONTOP: return compat_kdfontop_ioctl(up, perm, &op, vc);