mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Alan Cox <alan@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Jens Axboe <jaxboe@fusionio.com>
Subject: Re: [PATCH] tty: add lockdep annotations
Date: Sat, 02 Jun 2012 09:17:18 +0200	[thread overview]
Message-ID: <1338621438.2760.1679.camel@edumazet-glaptop> (raw)
In-Reply-To: <1338584389.2760.1653.camel@edumazet-glaptop>

On Fri, 2012-06-01 at 22:59 +0200, Eric Dumazet wrote:
> On Fri, 2012-06-01 at 21:56 +0100, Alan Cox wrote:
> > > Yes, tty->driver deref is ok (tty points to valid memory), but crash is
> > > on tty->driver->ops (driver points to freed/illegal memory)
> > > 
> > > using slub_debug=FZPU, I can indeed see RDI=6b6b6b6b6b6b6b6b
> > 
> > driver and driver->ops is basically const and it's not what you'd expect
> > from a tty refcount bug. The driver side puts shouldn't have changed but
> > I'll take a look over that patch and the error paths closely again just
> > in case.
> 
> right
> 
> The code looks like :
> ...
> 	call mcount
> 	mov  %rdi,%rbx
> 	mov  0x10(%rdi),%rdi   tty->driver
> <>	mov  0xf8(%rdi),%rax   CRASH
> 
> So tty was freed an tty->driver contains 6b6b6b6b6b6b6b6b
> 
> 

Here is the patch I am currently testing (need to boot the machine ~50
times to make sure it is the right fix)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 9e930c0..128a95b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1479,13 +1479,14 @@ static void release_one_tty(struct work_struct *work)
 	struct tty_struct *tty =
 		container_of(work, struct tty_struct, hangup_work);
 	struct tty_driver *driver = tty->driver;
+	struct module *module = driver->owner;
 
 	if (tty->ops->cleanup)
 		tty->ops->cleanup(tty);
 
 	tty->magic = 0;
 	tty_driver_kref_put(driver);
-	module_put(driver->owner);
+	module_put(module);
 
 	spin_lock(&tty_files_lock);
 	list_del_init(&tty->tty_files);
@@ -2005,11 +2006,15 @@ retry_open:
 			filp->f_op = &tty_fops;
 		goto retry_open;
 	}
-	tty_unlock(tty);
-
 
+	/*
+	 * Must acquire both mutexes in right order,
+	 * and keep a reference on tty, so dont call tty_unlock() !
+	 */
+	mutex_unlock(&tty->legacy_mutex);
 	mutex_lock(&tty_mutex);
-	tty_lock(tty);
+	mutex_lock(&tty->legacy_mutex);
+
 	spin_lock_irq(&current->sighand->siglock);
 	if (!noctty &&
 	    current->signal->leader &&



  reply	other threads:[~2012-06-02  7:17 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 12:54 [GIT PULL] Block driver bits for 3.5 Jens Axboe
2012-05-30 18:33 ` Eric Dumazet
2012-05-30 18:55   ` Jens Axboe
2012-05-30 19:08     ` Eric Dumazet
2012-05-30 19:17       ` Jens Axboe
2012-05-30 20:35       ` Eric Dumazet
2012-05-30 20:58         ` Linus Torvalds
2012-05-31  9:35         ` [PATCH] tty: add lockdep annotations Eric Dumazet
2012-05-31 11:45           ` Jiri Kosina
2012-05-31 11:59             ` Eric Dumazet
2012-06-01 18:17           ` Eric Dumazet
2012-06-01 18:51             ` Linus Torvalds
2012-06-01 20:38               ` Alan Cox
2012-06-01 20:46                 ` Eric Dumazet
2012-06-01 20:44               ` Eric Dumazet
2012-06-01 20:56                 ` Alan Cox
2012-06-01 20:59                   ` Eric Dumazet
2012-06-02  7:17                     ` Eric Dumazet [this message]
2012-06-02  7:55                       ` Eric Dumazet
2012-06-02  8:01                         ` Eric Dumazet
2012-06-02 11:57                           ` Alan Cox
2012-06-02 12:30                             ` Eric Dumazet
2012-06-02 18:38                               ` Linus Torvalds
2012-06-02 19:59                                 ` Linus Torvalds
2012-06-02 20:01                                   ` Linus Torvalds
2012-06-02 20:19                                   ` Alan Cox
2012-06-02 22:25                                     ` Linus Torvalds
2012-06-02 23:02                                       ` Alan Cox
2012-06-02 23:14                                         ` Linus Torvalds
2012-06-03  1:37                                       ` Linus Torvalds
2012-06-03 13:06                                         ` Alan Cox
2012-06-03 13:24                                         ` Alan Cox
2012-06-03 19:44                                       ` Eric Dumazet
2012-06-02 20:00                                 ` Alan Cox
2012-05-31 10:38         ` [PATCH] block: avoid infinite loop in get_task_io_context() Eric Dumazet
2012-05-31 10:47           ` Jens Axboe
2012-05-31 10:51             ` Eric Dumazet
2012-05-31 10:56               ` Jens Axboe
2012-06-01  5:06           ` Tejun Heo

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=1338621438.2760.1679.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=alan@linux.intel.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=jaxboe@fusionio.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®