public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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 10:43:54 +0100	[thread overview]
Message-ID: <4CF0D2DA.20105@suse.cz> (raw)
In-Reply-To: <4CF0C65E.2010104@suse.cz>

[-- Attachment #1: Type: text/plain, Size: 813 bytes --]

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.

regards,
-- 
js
suse labs

[-- Attachment #2: tty_reopen.c --]
[-- Type: text/x-csrc, Size: 1227 bytes --]

#include <err.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>

static void do_work(const char *tty)
{
	char buf[256];
	unsigned int cnt = 0;
	unsigned int errc = 0;
	int fd, con;

	if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
		err(1, "signal(SIGHUP)");

	setsid();

	con = open("/tmp/aaa", O_WRONLY|O_NOCTTY|O_CREAT);
	if (con < 0)
		err(2, "open cons");

	while (1) {
		if (!(cnt++ % 10000)) {
			int len = sprintf(buf, "err=%x\n", errc);
			write(con, buf, len);
			errc = 0;
		}
		fd = open(tty, O_RDWR|O_NOCTTY);
		if (fd < 0) {
			errc |= 1;
			continue;
		}
		if (ioctl(fd, TIOCSCTTY)) {
			errc |= 2;
			continue;
		}

		if (vhangup()) {
			errc |= 4;
			continue;
		}
		close(fd);
	}
	close(con);
	exit(errc);
}

int main(int argc, char **argv)
{
	pid_t pid;

	switch (pid = fork()) {
	case 0:
		do_work(argv[1]);
		break;
	case -1:
		err(1, "fork");
		break;
	default:
	{
		int stat;
		waitpid(pid, &stat, 0);
		if (stat) {
			fprintf(stderr, "exited with: %d sig=%d signr=%u\n",
					WEXITSTATUS(stat), WIFSIGNALED(stat),
					WTERMSIG(stat));
		}
		break;
	}
	}

	return 0;
}

  reply	other threads:[~2010-11-27  9:44 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 [this message]
2010-11-27 15:11                     ` Jiri Slaby
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=4CF0D2DA.20105@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