Received: by 10.223.185.116 with SMTP id b49csp6355509wrg; Wed, 28 Feb 2018 08:05:14 -0800 (PST) X-Google-Smtp-Source: AG47ELvQglfJiJ3VafM5E9Nk5kGf4JFSWLXpRKdvDc6epUH/VPEtMhqmo7QLOdUI/UkV3y0xTuYc X-Received: by 2002:a17:902:52ca:: with SMTP id a68-v6mr2243925pli.179.1519833914405; Wed, 28 Feb 2018 08:05:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519833914; cv=none; d=google.com; s=arc-20160816; b=aW7SRCaBk+OQov9WNz39vPqRRot2CWGki0BtUSJotj5/STmujnBj5TEHnVnJqffDKk 7s2EuWkB+FxuitEHawYg3UsFmt13r2Y5NgiGlSCYC+B7fZcd1SuQl7Dbjx5oaYKXXTOR 1TsO76qPo/HzVmfmc6Uv8mhqkPBANH4HcWND61/97jkaXGteUOWozK8F8xscloo6uhhi 7l4RuQpLi0cNsX8ctUn/ikqWzd4Wq4/g1B42QhhD3em4SfPPo0Bf1t6JLYnRWVkU8Fv1 bqwPjSd0cNfz2M8U7/Vxas9va1FcHg/shfO+qArIildyZM+iwPDB8W6pPMxziJs6EkPD ofWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=KITtndeFmBqtKJfT8GyfVKkNTdMyWQItG4uEyRGKnzs=; b=ERovzsq/AMxkDPf0WhzH2QMn6KcAxx72rq9BpUIFlNePf77O0vHiDHKJcrlet1n+yz 8pDhsH1eNZyVjOzBflMmfAE/Mo1g+z5iWXuUznPQjdXXfOADjtjg4J93bYE4D/reoFs9 +uV3VgehzYa+Krmr//GjoPtbeRhRqL20UQRk3plKetvDxtWXeNjJOCMCAVc/sUdNQWl3 I3JySi4FaMzk91lXJupu3FYxULx91Qvyl58cjuNFX2tzWyLm+59PJyIx8Z/LcOzYK13g Y1VbiPA3A/qLbG7TqjQG3y2k9LAHXwIxp4kfX5zqk2qGN9xkTkdornMJAWgj5vhFFsVF oLxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h67si1391236pfj.11.2018.02.28.08.04.57; Wed, 28 Feb 2018 08:05:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753175AbeB1QCl (ORCPT + 99 others); Wed, 28 Feb 2018 11:02:41 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34720 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753147AbeB1QCi (ORCPT ); Wed, 28 Feb 2018 11:02:38 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Ys-0006Xc-HA; Wed, 28 Feb 2018 15:22:30 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yh-000090-HG; Wed, 28 Feb 2018 15:22:19 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Linus Torvalds" , "Jiri Slaby" , "syzkaller" , "Greg Kroah-Hartman" , "Tetsuo Handa" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 137/254] n_tty: fix EXTPROC vs ICANON interaction with TIOCINQ (aka FIONREAD) In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Linus Torvalds commit 966031f340185eddd05affcf72b740549f056348 upstream. We added support for EXTPROC back in 2010 in commit 26df6d13406d ("tty: Add EXTPROC support for LINEMODE") and the intent was to allow it to override some (all?) ICANON behavior. Quoting from that original commit message: There is a new bit in the termios local flag word, EXTPROC. When this bit is set, several aspects of the terminal driver are disabled. Input line editing, character echo, and mapping of signals are all disabled. This allows the telnetd to turn off these functions when in linemode, but still keep track of what state the user wants the terminal to be in. but the problem turns out that "several aspects of the terminal driver are disabled" is a bit ambiguous, and you can really confuse the n_tty layer by setting EXTPROC and then causing some of the ICANON invariants to no longer be maintained. This fixes at least one such case (TIOCINQ) becoming unhappy because of the confusion over whether ICANON really means ICANON when EXTPROC is set. This basically makes TIOCINQ match the case of read: if EXTPROC is set, we ignore ICANON. Also, make sure to reset the ICANON state ie EXTPROC changes, not just if ICANON changes. Fixes: 26df6d13406d ("tty: Add EXTPROC support for LINEMODE") Reported-by: Tetsuo Handa Reported-by: syzkaller Cc: Jiri Slaby Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/tty/n_tty.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/tty/n_tty.c +++ b/drivers/tty/n_tty.c @@ -1809,7 +1809,7 @@ static void n_tty_set_termios(struct tty { struct n_tty_data *ldata = tty->disc_data; - if (!old || (old->c_lflag ^ tty->termios.c_lflag) & ICANON) { + if (!old || (old->c_lflag ^ tty->termios.c_lflag) & (ICANON | EXTPROC)) { bitmap_zero(ldata->read_flags, N_TTY_BUF_SIZE); ldata->line_start = ldata->read_tail; if (!L_ICANON(tty) || !read_cnt(ldata)) { @@ -2520,7 +2520,7 @@ static int n_tty_ioctl(struct tty_struct return put_user(tty_chars_in_buffer(tty), (int __user *) arg); case TIOCINQ: down_write(&tty->termios_rwsem); - if (L_ICANON(tty)) + if (L_ICANON(tty) && !L_EXTPROC(tty)) retval = inq_canon(ldata); else retval = read_cnt(ldata);