lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LNX.2.00.1205282042290.15057@pobox.suse.cz>
Date:	Mon, 28 May 2012 20:43:41 +0200 (CEST)
From:	Jiri Kosina <jkosina@...e.cz>
To:	Alan Cox <alan@...ux.intel.com>, Jiri Slaby <jslaby@...e.cz>
Cc:	linux-kernel@...r.kernel.org,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Subject: [PATCH] tty: annotate tty_lock() for lockdep

=============================================
[ INFO: possible recursive locking detected ]
3.4.0-08218-gb48b2c3 #7 Not tainted
---------------------------------------------
blogd/279 is trying to acquire lock:
 (&tty->legacy_mutex){+.+.+.}, at: [<ffffffff8150f51e>] tty_lock+0x3e/0x90

but task is already holding lock:
 (&tty->legacy_mutex){+.+.+.}, at: [<ffffffff8150f51e>] tty_lock+0x3e/0x90

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(&tty->legacy_mutex);
  lock(&tty->legacy_mutex);

 *** DEADLOCK ***

[ .. stacktraces removed .. ]

This is a false positive stemming from the fact that lockdep doesn't
understand that proper lock ordering is already achieved in tty_lock_pair()
by ordering by struct tty address.

Introduce tty_lock_nested() to be able to express this explicit
ordering to lockdep and teach tty_lock_pair() to use it.

Signed-off-by: Jiri Kosina <jkosina@...e.cz>
---
 drivers/tty/tty_mutex.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/tty_mutex.c b/drivers/tty/tty_mutex.c
index 69adc80..90d43ad 100644
--- a/drivers/tty/tty_mutex.c
+++ b/drivers/tty/tty_mutex.c
@@ -10,7 +10,7 @@
  * Getting the big tty mutex.
  */
 
-void __lockfunc tty_lock(struct tty_struct *tty)
+void tty_lock_common(struct tty_struct *tty)
 {
 	if (tty->magic != TTY_MAGIC) {
 		printk(KERN_ERR "L Bad %p\n", tty);
@@ -18,10 +18,22 @@ void __lockfunc tty_lock(struct tty_struct *tty)
 		return;
 	}
 	tty_kref_get(tty);
+}
+
+void __lockfunc tty_lock(struct tty_struct *tty)
+{
+	tty_lock_common(tty);
 	mutex_lock(&tty->legacy_mutex);
 }
 EXPORT_SYMBOL(tty_lock);
 
+void __lockfunc tty_lock_nested(struct tty_struct *tty,
+					unsigned int subclass)
+{
+	tty_lock_common(tty);
+	mutex_lock_nested(&tty->legacy_mutex, subclass);
+}
+
 void __lockfunc tty_unlock(struct tty_struct *tty)
 {
 	if (tty->magic != TTY_MAGIC) {
@@ -42,12 +54,12 @@ void __lockfunc tty_lock_pair(struct tty_struct *tty,
 					struct tty_struct *tty2)
 {
 	if (tty < tty2) {
-		tty_lock(tty);
-		tty_lock(tty2);
+		tty_lock_nested(tty, 1);
+		tty_lock_nested(tty2, 2);
 	} else {
 		if (tty2 && tty2 != tty)
-			tty_lock(tty2);
-		tty_lock(tty);
+			tty_lock_nested(tty2, 2);
+		tty_lock_nested(tty, 1);
 	}
 }
 EXPORT_SYMBOL(tty_lock_pair);

-- 
Jiri Kosina
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ