From: Jiri Slaby <jslaby@suse.cz>
To: unlisted-recipients:; (no To-header on input)
Cc: Kyle McMartin <kyle@mcmartin.ca>,
gregkh@suse.de, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org, Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: Re: [PATCH 1/1] TTY: don't allow reopen when ldisc is changing
Date: Sat, 27 Nov 2010 16:11:06 +0100 [thread overview]
Message-ID: <4CF11F8A.1050200@suse.cz> (raw)
In-Reply-To: <4CF0D2DA.20105@suse.cz>
[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]
On 11/27/2010 10:43 AM, Jiri Slaby wrote:
> On 11/27/2010 09:50 AM, Jiri Slaby wrote:
>> On 11/27/2010 03:59 AM, Kyle McMartin wrote:
>>> I'm poking around to see, I think maybe something might be dropping
>>> locks in the callchain that gives us a window where this might be
>>> possible...
>>
>> Of course, that's the case:
>> clear_bit(TTY_LDISC, &tty->flags);
>> tty_unlock();
>> cancel_delayed_work_sync(&tty->buf.work);
>> mutex_unlock(&tty->ldisc_mutex);
>>
>> tty_lock();
>> mutex_lock(&tty->ldisc_mutex);
>>
>> in tty_ldisc_hangup. Hence my point 1) from previous posts doesn't hold too:
>> 1) __tty_hangup from tty_ldisc_hangup to tty_ldisc_enable. During this
>> section tty_lock is held.
>>
>> I will check, how to fix this.
>
> Reproducible with 2 running processes from the attachment.
Is it fixed with the attached proof-of-concept patch?
So you need:
THIS ONE
TTY: don't allow reopen when ldisc is changing
TTY: ldisc, fix open flag handling
Char: TTY, restore tty_ldisc_wait_idle
The last one is in 2.6.37-rc2 already.
thanks,
--
js
suse labs
[-- Attachment #2: 0001-TTY-open-hangup-race-fixup.patch --]
[-- Type: text/x-patch, Size: 2328 bytes --]
>From 9e88e8b9915b5e067507a087437d80e6a133d612 Mon Sep 17 00:00:00 2001
From: Jiri Slaby <jslaby@suse.cz>
Date: Sat, 27 Nov 2010 16:06:46 +0100
Subject: [PATCH 1/1] TTY: open/hangup race fixup
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
drivers/tty/tty_io.c | 10 +++++++++-
include/linux/tty.h | 1 +
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 878f6d6..35480dd 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -559,6 +559,9 @@ void __tty_hangup(struct tty_struct *tty)
tty_lock();
+ /* some functions below drop BTM, so we need this bit */
+ set_bit(TTY_HUPPING, &tty->flags);
+
/* inuse_filps is protected by the single tty lock,
this really needs to change if we want to flush the
workqueue with the lock held */
@@ -578,6 +581,10 @@ void __tty_hangup(struct tty_struct *tty)
}
spin_unlock(&tty_files_lock);
+ /*
+ * it drops BTM and thus races with reopen
+ * we protect the race by TTY_HUPPING
+ */
tty_ldisc_hangup(tty);
read_lock(&tasklist_lock);
@@ -615,7 +622,6 @@ void __tty_hangup(struct tty_struct *tty)
tty->session = NULL;
tty->pgrp = NULL;
tty->ctrl_status = 0;
- set_bit(TTY_HUPPED, &tty->flags);
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
/* Account for the p->signal references we killed */
@@ -641,6 +647,7 @@ void __tty_hangup(struct tty_struct *tty)
* can't yet guarantee all that.
*/
set_bit(TTY_HUPPED, &tty->flags);
+ clear_bit(TTY_HUPPING, &tty->flags);
tty_ldisc_enable(tty);
tty_unlock();
@@ -1311,6 +1318,7 @@ static int tty_reopen(struct tty_struct *tty)
struct tty_driver *driver = tty->driver;
if (test_bit(TTY_CLOSING, &tty->flags) ||
+ test_bit(TTY_HUPPING, &tty->flags) ||
test_bit(TTY_LDISC_CHANGING, &tty->flags))
return -EIO;
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 032d79f..54e4eaa 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -366,6 +366,7 @@ struct tty_file_private {
#define TTY_HUPPED 18 /* Post driver->hangup() */
#define TTY_FLUSHING 19 /* Flushing to ldisc in progress */
#define TTY_FLUSHPENDING 20 /* Queued buffer flush pending */
+#define TTY_HUPPING 21 /* ->hangup() in progress */
#define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
--
1.7.3.1
next prev parent reply other threads:[~2010-11-27 15:11 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-24 0:13 mmotm 2010-11-23-16-12 uploaded akpm
2010-11-24 4:52 ` mmotm 2010-11-23 - lockdep whinge in e1000e driver Valdis.Kletnieks
2010-11-24 4:55 ` mmotm 2010-11-23 - WARNING: at drivers/tty/tty_io.c:1331 Valdis.Kletnieks
2010-11-25 15:14 ` Kyle McMartin
2010-11-25 16:44 ` Jiri Slaby
2010-11-25 16:51 ` Jiri Slaby
2010-11-25 17:16 ` [PATCH 1/1] TTY: don't allow reopen when ldisc is changing Jiri Slaby
2010-11-25 17:59 ` Kyle McMartin
2010-11-26 0:28 ` Kyle McMartin
2010-11-26 7:46 ` Jiri Slaby
2010-11-26 13:27 ` Kyle McMartin
2010-11-27 2:59 ` Kyle McMartin
2010-11-27 8:50 ` Jiri Slaby
2010-11-27 9:43 ` Jiri Slaby
2010-11-27 15:11 ` Jiri Slaby [this message]
2010-11-27 23:53 ` Kyle McMartin
2010-11-24 5:01 ` mmotm 2010-11-23 + autogroups -> inconsistent lock state Valdis.Kletnieks
2010-11-24 20:25 ` Mike Galbraith
2010-11-24 20:39 ` Mike Galbraith
2010-11-25 6:09 ` Valdis.Kletnieks
2010-12-02 18:16 ` Paul E. McKenney
2010-12-03 3:58 ` Mike Galbraith
2010-11-24 13:56 ` mmotm 2010-11-23-16-12 uploaded Zimny Lech
2010-11-24 18:51 ` mmotm 2010-11-23-16-12 uploaded (olpc) Randy Dunlap
2010-11-24 19:13 ` Andres Salomon
2010-11-26 16:46 ` Daniel Drake
2010-11-24 19:41 ` [PATCH -mmotm/-next] media: fix timblogiw kconfig & build error Randy Dunlap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CF11F8A.1050200@suse.cz \
--to=jslaby@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=gregkh@suse.de \
--cc=kyle@mcmartin.ca \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox