Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6270949imu; Mon, 21 Jan 2019 06:09:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN6O2se0lrIBBepD6OC766AqcPqFdeFfIh+IZwAGmRo1UMZ/fHJ7N4AcX5CRJ1lUQwAbIFwP X-Received: by 2002:a63:b81a:: with SMTP id p26mr28685810pge.433.1548079790556; Mon, 21 Jan 2019 06:09:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079790; cv=none; d=google.com; s=arc-20160816; b=E/z0TLlaEc76hXLfkdg0zWGCZKR+JLH9e4aoeSJiMgo+gKbO7IRbH4BSb8qm62sSca ema0VC7NrQyHVo/WGCW4ZQp9tqiyjF/kdp8chaJWoGW1qsPiiOW5vac6fg+df1IBUdxN 3x5mNxV59E1cw1/Cie0Uoj3y404IE/aJq76IoZB5QoDBOkderYRBCE/XqTl8WFlcmlD6 HKihqoHZ6iTmuzDfnr/8wT/oieaLNW2lQOTtEapfdXVJl8IzfWxSiiHIIlwkVCZS3j8c HGK1lFywQteMhvC6NGEpPNRMPbwRgBT+aE6xyiFk4shGrKNhEEOqA5SNooIuHoQ9n02R /P9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EknwrAnvUOPMvKz6lfBUhalqww8VFBw3SzfHTARskrQ=; b=zHjE2n8U7nihnJWeG5qEDZAEc+V43i3BMDDpjwOL4AlfLr7fRYGTgOMdnwf7K3r5r1 MftUtTPQaMkM+1t+pldD43u7WrVlRdsS2T5TpKo/+NUnA16UIZl4kD5/pw00JrFG/O56 6SFlb0gYd9AKSpzGztJG8HVQhfhivjEm1BAkM7uw6Lo/8MuwW4u8EtxQUy1XXf6PKaYg q9oxoIvJ0wB/mn8ffXnZgVv+btL67/e6o3fk3xptrUt2tCu/lJ+LwwF8NE00LHe/jYCX keXApy4FyI7G/qULgZrlxqet0WtIsfOsms8ce/uF1+esIWKGFKdQ711/EPr4Vh3M9jFQ WIDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zxIW2N5h; 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 b2si12547176pgh.475.2019.01.21.06.09.35; Mon, 21 Jan 2019 06:09:50 -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; dkim=pass header.i=@kernel.org header.s=default header.b=zxIW2N5h; 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 S1732269AbfAUN7w (ORCPT + 99 others); Mon, 21 Jan 2019 08:59:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:45992 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731884AbfAUN7s (ORCPT ); Mon, 21 Jan 2019 08:59:48 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 ED3B42084C; Mon, 21 Jan 2019 13:59:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079187; bh=8ZJ1f6RY4antemTwfBzwo3LtoE+Otds00pXzf4dX8mM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zxIW2N5hNXUCabV7uhB7Kwz6VqhGC97jSSe5gPcx37X7slEpjdPxo+P+TST8XKr4I qAHsf3eKPolCZa604re8ehZF91cHBMMBX9Nh7RyFYbInof0j+kVYNo5DbBuhSKXTIF SKqme0YNhzkgvDcvV59TnJcOqtRvCxMN4UrEGnl0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , "Lukas F. Hartmann" , Dmitry Safonov Subject: [PATCH 4.19 04/99] tty: Dont hold ldisc lock in tty_reopen() if ldisc present Date: Mon, 21 Jan 2019 14:47:56 +0100 Message-Id: <20190121134914.085124687@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Safonov commit d3736d82e8169768218ee0ef68718875918091a0 upstream. Try to get reference for ldisc during tty_reopen(). If ldisc present, we don't need to do tty_ldisc_reinit() and lock the write side for line discipline semaphore. Effectively, it optimizes fast-path for tty_reopen(), but more importantly it won't interrupt ongoing IO on the tty as no ldisc change is needed. Fixes user-visible issue when tty_reopen() interrupted login process for user with a long password, observed and reported by Lukas. Fixes: c96cf923a98d ("tty: Don't block on IO when ldisc change is pending") Fixes: 83d817f41070 ("tty: Hold tty_ldisc_lock() during tty_reopen()") Cc: Jiri Slaby Reported-by: Lukas F. Hartmann Tested-by: Lukas F. Hartmann Cc: stable Signed-off-by: Dmitry Safonov Signed-off-by: Greg Kroah-Hartman --- drivers/tty/tty_io.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1255,7 +1255,8 @@ static void tty_driver_remove_tty(struct static int tty_reopen(struct tty_struct *tty) { struct tty_driver *driver = tty->driver; - int retval; + struct tty_ldisc *ld; + int retval = 0; if (driver->type == TTY_DRIVER_TYPE_PTY && driver->subtype == PTY_TYPE_MASTER) @@ -1267,13 +1268,18 @@ static int tty_reopen(struct tty_struct if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) return -EBUSY; - retval = tty_ldisc_lock(tty, 5 * HZ); - if (retval) - return retval; - - if (!tty->ldisc) - retval = tty_ldisc_reinit(tty, tty->termios.c_line); - tty_ldisc_unlock(tty); + ld = tty_ldisc_ref_wait(tty); + if (ld) { + tty_ldisc_deref(ld); + } else { + retval = tty_ldisc_lock(tty, 5 * HZ); + if (retval) + return retval; + + if (!tty->ldisc) + retval = tty_ldisc_reinit(tty, tty->termios.c_line); + tty_ldisc_unlock(tty); + } if (retval == 0) tty->count++;