Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1839147pxb; Fri, 24 Sep 2021 13:12:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWGgDd9ARrr3v7lodtUdHptsCeYW076oIeLd+v8uxJd/cM62kfefrRB2NTllpKLrjNl1Dq X-Received: by 2002:a17:906:4ccf:: with SMTP id q15mr13561257ejt.9.1632514334581; Fri, 24 Sep 2021 13:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632514334; cv=none; d=google.com; s=arc-20160816; b=NKE/h0zsS2/k5vZxGSeca4wWHRsjdMHIUft0qpkpI/dPpIsSJVCCjM1XxJ7FZ61AqB GzLPwzoVv/UVuv2uzMBXFZDBsEVPA/f93UwrtD0ruVfez7wKgRbP1Fnk6Dr9jKKN5d08 qnShR5eJoUQYz5d1+wtt+zBXx4ViRzrpl6k9S873vqi/zR7RaTfkmP+ficRfTPO/z9Rh nJShM7CIZbHlPEeZ89+UjqSvOd+2aJj9D48bVCKA7If37vgubuZLAqPioGuiK9sJwWtb CoJAMTS80NLsP5067Kv7jGHQr+Yy3DiDjG2nWsA9OlZqYVBDMi1igtSJYbpmVEVnlWQq fqJw== 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=ftcviFE702w9qwL4Zrh3Qrflp2rK9Xi8frkyA4mS3xg=; b=ac5uJMHk15vis8hcejODrJ+tjUU+U6DjTBKfFZ4svly/HadaLM0eh0xrc0d/XdxE6d 3jWRycK41SWi9rete+fBudy239cM6o3ydrYW3bYK+ZII1hzxhJNbCOCCkJInmtHyan5I k517iHgDT6bmzJILikfoNh9yYQjUgMmsU7e/INgIi0/5o55ZQFumm6SgvpTC7UdSHoGT PBNFvy2VvYA7XGhKyRPhb29ut0OvlcxJm34X/0j9gEOykJWn/2zsPh+1kJELYYDAgo09 /UmQ9AkyFGPzvtO4xp+98i4hwzT7/ZH1b/P11CvHENDGeF7YSOKMBR9wU5aa4UqmDay7 wBlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mg4gpNzP; 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=pass (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 1si10853915ejb.76.2021.09.24.13.11.49; Fri, 24 Sep 2021 13:12:14 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=mg4gpNzP; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346741AbhIXNLH (ORCPT + 99 others); Fri, 24 Sep 2021 09:11:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:37584 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346794AbhIXNIG (ORCPT ); Fri, 24 Sep 2021 09:08:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 045BF61355; Fri, 24 Sep 2021 12:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632488221; bh=MkrdtIH2tS8XG0eBj1UFlhZwfdyBh43wnnktnB7k6IU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mg4gpNzPEX19rN7Fg/AjEsuudEid15QJyK7qsFxunqQVJyLR4msmEAWNmXvEa6dNT /lmk0s/lkjAsEBUBjfxF5E9tXQu+uaKzfBHdBSBDZrvtTyyYSkUOA19FrZRsH7uXr7 K7RojbTPrzuBu8kBVbIFpY+bk0GktuODQnwXKemg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, nick black , Jiri Slaby , Tetsuo Handa , Daniel Vetter , Linus Torvalds Subject: [PATCH 5.10 03/63] console: consume APC, DM, DCS Date: Fri, 24 Sep 2021 14:44:03 +0200 Message-Id: <20210924124334.341478612@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124334.228235870@linuxfoundation.org> References: <20210924124334.228235870@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: nick black commit 3a2b2eb55681158d3e3ef464fbf47574cf0c517c upstream. The Linux console's VT102 implementation already consumes OSC ("Operating System Command") sequences, probably because that's how palette changes are transmitted. In addition to OSC, there are three other major clases of ANSI control strings: APC ("Application Program Command"), PM ("Privacy Message"), and DCS ("Device Control String"). They are handled similarly to OSC in terms of termination. Source: vt100.net Add three new enumerated states, one for each of these types. All three are handled the same way right now--they simply consume input until terminated. I hope to expand upon this firmament in the future. Add new predicate ansi_control_string(), returning true for any of these states. Replace explicit checks against ESosc with calls to this function. Transition to these states appropriately from the escape initiation (ESesc) state. This was motivated by the following Notcurses bugs: https://github.com/dankamongmen/notcurses/issues/2050 https://github.com/dankamongmen/notcurses/issues/1828 https://github.com/dankamongmen/notcurses/issues/2069 where standard VT sequences are not consumed by the Linux console. It's not necessary that the Linux console *support* these sequences, but it ought *consume* these well-specified classes of sequences. Tested by sending a variety of escape sequences to the console, and verifying that they still worked, or were now properly consumed. Verified that the escapes were properly terminated at a generic level. Verified that the Notcurses tools continued to show expected output on the Linux console, except now without escape bleedthrough. Link: https://lore.kernel.org/lkml/YSydL0q8iaUfkphg@schwarzgerat.orthanc/ Signed-off-by: nick black Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: Tetsuo Handa Cc: Daniel Vetter Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/vt.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -2060,7 +2060,7 @@ static void restore_cur(struct vc_data * enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, EShash, ESsetG0, ESsetG1, ESpercent, EScsiignore, ESnonstd, - ESpalette, ESosc }; + ESpalette, ESosc, ESapc, ESpm, ESdcs }; /* console_lock is held (except via vc_init()) */ static void reset_terminal(struct vc_data *vc, int do_clear) @@ -2134,20 +2134,28 @@ static void vc_setGx(struct vc_data *vc, vc->vc_translate = set_translate(*charset, vc); } +/* is this state an ANSI control string? */ +static bool ansi_control_string(unsigned int state) +{ + if (state == ESosc || state == ESapc || state == ESpm || state == ESdcs) + return true; + return false; +} + /* console_lock is held */ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) { /* * Control characters can be used in the _middle_ - * of an escape sequence. + * of an escape sequence, aside from ANSI control strings. */ - if (vc->vc_state == ESosc && c>=8 && c<=13) /* ... except for OSC */ + if (ansi_control_string(vc->vc_state) && c >= 8 && c <= 13) return; switch (c) { case 0: return; case 7: - if (vc->vc_state == ESosc) + if (ansi_control_string(vc->vc_state)) vc->vc_state = ESnormal; else if (vc->vc_bell_duration) kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration); @@ -2208,6 +2216,12 @@ static void do_con_trol(struct tty_struc case ']': vc->vc_state = ESnonstd; return; + case '_': + vc->vc_state = ESapc; + return; + case '^': + vc->vc_state = ESpm; + return; case '%': vc->vc_state = ESpercent; return; @@ -2225,6 +2239,9 @@ static void do_con_trol(struct tty_struc if (vc->state.x < VC_TABSTOPS_COUNT) set_bit(vc->state.x, vc->vc_tab_stop); return; + case 'P': + vc->vc_state = ESdcs; + return; case 'Z': respond_ID(tty); return; @@ -2521,8 +2538,14 @@ static void do_con_trol(struct tty_struc vc_setGx(vc, 1, c); vc->vc_state = ESnormal; return; + case ESapc: + return; case ESosc: return; + case ESpm: + return; + case ESdcs: + return; default: vc->vc_state = ESnormal; }