Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3186027pxb; Mon, 9 Nov 2020 05:07:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLEPQP0dKEQsLBArniD1PFNGW4/b7abkiRE/DDLEpR+8SWSGgvhz/GDBPzq24ah5iuzfMm X-Received: by 2002:a5d:5583:: with SMTP id i3mr14263803wrv.336.1604927248856; Mon, 09 Nov 2020 05:07:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927248; cv=none; d=google.com; s=arc-20160816; b=xp7OJ684++prgNWuyN7caoco4PmqZDAQ8NJrVLj3SlqwsGjubv2Rmlgb18seuMnn+L 8T9m0gpWcUDq0y84nGC3YyMIVg8tsw/h+BlA6bVlApTayD9ZvNrKzwEoZ78ipkytObsb N2j+qlE1WZ7NDCdPJXpZc8Y7xpQsq/ITaC3eeBbnxly850aVj7eusgKmV3r8vaY8CgA1 RixV41N8WtBT2pY6Jf1IijhTFxeNb9C2WZ/B4VVbXBGfwJ9wcO/2DWArKYa6JptoPE8v JCas1vhtSeM5c+XJkO1gvskhulcfSrx9HaaE4aeMQ73+OZYjMqqGW+HHVuHmtLR8rUes 9ObQ== 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=KEsguVRgn7arJJtBHEFNgp/jlYJ6C3HHKoCaQwxgxjo=; b=dquk1+VdjnrwTHNm5NHE4ShFzl17uT9Wji+6i5PTdHJiT4++hUdTGDYNCfyfS5X5Lx TZuSLLw/jWfP78DDDfuN88Xc6SLHOQbkc4BDDXTBtYaO67TTWpcXg5nn9D+Xx11LUj6v Vu5bkLdxC2UstE/dNfOp5PSAwsbxGyM22cSginbkjGMyURBeW/BkAgy2XD6GnAWY10VN pgqvSPEE8EMK4N5/+sjeTOzIuImdVYmyyuSCHYk7FVhT2Pq6gYRsVVczCk+AeINsu7en TNAUn97Ngjf9h7ADHM3YKHzooAnNZSfMcvN/W2wiHFQTsjSH5E6d6pBxIPJbrE1xzkvj APrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hOXYe98v; 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 cq14si3280452edb.207.2020.11.09.05.07.04; Mon, 09 Nov 2020 05:07:28 -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=hOXYe98v; 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 S1730695AbgKINFp (ORCPT + 99 others); Mon, 9 Nov 2020 08:05:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:57432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730743AbgKINEY (ORCPT ); Mon, 9 Nov 2020 08:04:24 -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 19AA120789; Mon, 9 Nov 2020 13:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927061; bh=jP88JYj8Z/AdPCNX+iDECNYYOP9MgaPxV5cN5R2kP8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hOXYe98vhoz8ULs4fl9XRqTPTzGeoQl2I2vrqXc8IC+zHZQUkDsbBgNbLK59afbHD kJbYRmndLeyeaFK77PvPpGSmPmIXNuDpRJq5pLCLxS1KIH+RdwpYoUCej45tZaDpj+ L6IOrqUT2F42b2FAmwv4O5w9C7hexBhUMBSGKx7M= 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 4.9 080/117] tty: make FONTX ioctl use the tty pointer they were actually passed Date: Mon, 9 Nov 2020 13:55:06 +0100 Message-Id: <20201109125029.484537118@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) --- a/drivers/tty/vt/vt_ioctl.c +++ b/drivers/tty/vt/vt_ioctl.c @@ -243,7 +243,7 @@ int vt_waitactive(int n) 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; int i; @@ -261,15 +261,16 @@ do_fontx_ioctl(int cmd, struct consolefo 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; @@ -277,7 +278,6 @@ do_fontx_ioctl(int cmd, struct consolefo if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc))) return -EFAULT; return 0; - } } return -EINVAL; } @@ -927,7 +927,7 @@ int vt_ioctl(struct tty_struct *tty, op.height = 0; op.charcount = 256; op.data = up; - ret = con_font_op(vc_cons[fg_console].d, &op); + ret = con_font_op(vc, &op); break; } @@ -938,7 +938,7 @@ int vt_ioctl(struct tty_struct *tty, op.height = 32; op.charcount = 256; op.data = up; - ret = con_font_op(vc_cons[fg_console].d, &op); + ret = con_font_op(vc, &op); break; } @@ -955,7 +955,7 @@ int vt_ioctl(struct tty_struct *tty, case PIO_FONTX: case GIO_FONTX: - ret = do_fontx_ioctl(cmd, up, perm, &op); + ret = do_fontx_ioctl(vc, cmd, up, perm, &op); break; case PIO_FONTRESET: @@ -972,11 +972,11 @@ int vt_ioctl(struct tty_struct *tty, { 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) break; console_lock(); - con_set_default_unimap(vc_cons[fg_console].d); + con_set_default_unimap(vc); console_unlock(); break; } @@ -1103,8 +1103,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; @@ -1122,7 +1123,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; @@ -1130,7 +1132,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; @@ -1225,7 +1227,7 @@ long vt_compat_ioctl(struct tty_struct * */ case PIO_FONTX: case GIO_FONTX: - ret = compat_fontx_ioctl(cmd, up, perm, &op); + ret = compat_fontx_ioctl(vc, cmd, up, perm, &op); break; case KDFONTOP: