Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6247338imu; Mon, 21 Jan 2019 05:48:02 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Xji2hMlNG/ZEQ1nTVMbCvJfCcbbmHV6pKK7oVJ9ET+WhHbqz1oxXviR5uvuKsloDyNDnf X-Received: by 2002:a62:425b:: with SMTP id p88mr30242986pfa.137.1548078482786; Mon, 21 Jan 2019 05:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548078482; cv=none; d=google.com; s=arc-20160816; b=m4RLWhe2VlLF360wh/ZA4svGRpPBiAqLPMki/TBSWgrHBTdmDWCbItU+Ko71XF6lFH j5XatkeO7z0Z2pigYKMKClcg48CSG5xQBi1+LJDuOgSpEL44HCZHM8qb6yo8eM4r8CE4 3LRN5qidUcPEeM1pE8khogT9dyzyXqLinb5njrxCu1Hlvz3pYlKV2vw0iRz3tCT35YrF 4WrUVvAwnPwhgnl2HLjX3iX1upkS4s52QQRC6bLECmIkD6uaLGR0EvUkN6Xxnk7rI+L2 dNc3wSyKxkqAD2AbMLur27co/ZTOCIrtaaf6/4uppMoeDIUgfqMd+/D/gJ8HI5XBLKQC 8aQg== 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=Pcs9CXrmuFYKrM3TfLeB3NVdBNbjrl9QndIqc/xgg9c=; b=rYq8RABmDTQC+AaYsCiRDj/ofvOhCeY5W4icA0GeZiYdMj6wVAEIjJBNz9qvpO2z+o 5v0vaAMafgZPSm+ML/q9PyG4ARffiBYrt1C4YDK1FO5kWGMsnSButsxNWF7xjcIdXYo+ NochEx51DI7Js7zLxHh6QmB0qQjkf0GGuwpN3g8TUqkZq132omDjuYxq0ofDEu/zmd6i qRh3LKnc2RW3g2jGtRbxIZkvz3wvumMYZnbGomBr/NzaEZVWao3cPr26/yistA5usEGy YqM1Efw/aWIC5aAYoUqTt+s0Fi2QlJnAPLj6Fa33XAWZVMeMzek+8I8dcFV4DGV5L0Kl N7zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gIElX2re; 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 n8si12546421plk.9.2019.01.21.05.47.47; Mon, 21 Jan 2019 05:48:02 -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=gIElX2re; 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 S1729207AbfAUNq2 (ORCPT + 99 others); Mon, 21 Jan 2019 08:46:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:55188 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729131AbfAUNqX (ORCPT ); Mon, 21 Jan 2019 08:46:23 -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 1F95920861; Mon, 21 Jan 2019 13:46:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548078382; bh=CMBiqU4118vUqUpu2bqZ93TfaSIo5fLwXvjqYJn7qKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gIElX2rezgXk2hflpFyOkI0vGjvx3ECwQu8Ot+u6BZE1vm7fQKWDN5PxKR34iAIyP Ety2vnOgk9R73o9BAPgo7UoZUavXqb+dF2X74ZOs3xCFv1vKBCzqDWPKTAjRiNNWqF X8gjzlkUP/TlWmtRTehd4urI2kmXxJbKt2x5Ouh8= 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.20 004/111] tty: Dont hold ldisc lock in tty_reopen() if ldisc present Date: Mon, 21 Jan 2019 14:41:58 +0100 Message-Id: <20190121122456.262193546@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121122455.819406896@linuxfoundation.org> References: <20190121122455.819406896@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.20-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 @@ -1256,7 +1256,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) @@ -1268,13 +1269,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++;