public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] lockdep: check the depth of subclass
@ 2010-10-05  9:01 Hitoshi Mitake
  2010-10-05  9:01 ` [RFC PATCH 2/2] lockdep: caching subclasses Hitoshi Mitake
  2010-10-12 10:27 ` [PATCH 1/2] lockdep: check the depth of subclass Peter Zijlstra
  0 siblings, 2 replies; 14+ messages in thread
From: Hitoshi Mitake @ 2010-10-05  9:01 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, mitake, h.mitake, Dmitry Torokhov, Vojtech Pavlik,
	Peter Zijlstra, Frederic Weisbecker

Current look_up_lock_class() doesn't check the parameter "subclass".
This rarely rises problems because the main caller of this function,
register_lock_class(), checks it.
But register_lock_class() is not the only function which calls
look_up_lock_class(). lock_set_class() and its callees also call it.
And lock_set_class() doesn't check this parameter.

This will rise problems when the the value of subclass is larger
MAX_LOCKDEP_SUBCLASSES. Because the address (used as the key of class)
caliculated with too large subclass has a possibility to point
another key in different lock_class_key.
Of course this problem depends on the memory layout and
occurs with really low possibility.

And mousedev_create() calles lockdep_set_subclass() and
sets class of mousedev->mutex as MOUSEDEV_MIX(== 31).
And if my understanding is correct,
this subclass doesn't have to be MOUSEDEV_MIX,
so I modified this value to SINGLE_DEPTH_NESTING.

Signed-off-by: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Cc: Dmitry Torokhov <dtor@mail.ru>
Cc: Vojtech Pavlik <vojtech@ucw.cz>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
---
 drivers/input/mousedev.c |    2 +-
 kernel/lockdep.c         |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index d528a2d..9897334 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -866,7 +866,7 @@ static struct mousedev *mousedev_create(struct input_dev *dev,
 	spin_lock_init(&mousedev->client_lock);
 	mutex_init(&mousedev->mutex);
 	lockdep_set_subclass(&mousedev->mutex,
-			     minor == MOUSEDEV_MIX ? MOUSEDEV_MIX : 0);
+			     minor == MOUSEDEV_MIX ? SINGLE_DEPTH_NESTING : 0);
 	init_waitqueue_head(&mousedev->wait);
 
 	if (minor == MOUSEDEV_MIX)
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 84baa71..c4c13ae 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -639,6 +639,21 @@ look_up_lock_class(struct lockdep_map *lock, unsigned int subclass)
 	}
 #endif
 
+	if (unlikely(subclass >= MAX_LOCKDEP_SUBCLASSES)) {
+		/*
+		 * This check should be done not only in __lock_acquire()
+		 * but also here. Because register_lock_class() is also called
+		 * by lock_set_class(). Callers of lock_set_class() can
+		 * pass invalid value as subclass.
+		 */
+
+		debug_locks_off();
+		printk(KERN_ERR "BUG: looking up invalid subclass: %u\n", subclass);
+		printk(KERN_ERR "turning off the locking correctness validator.\n");
+		dump_stack();
+		return NULL;
+	}
+
 	/*
 	 * Static locks do not have their class-keys yet - for them the key
 	 * is the lock object itself:
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2010-10-18 19:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-05  9:01 [PATCH 1/2] lockdep: check the depth of subclass Hitoshi Mitake
2010-10-05  9:01 ` [RFC PATCH 2/2] lockdep: caching subclasses Hitoshi Mitake
2010-10-12 10:36   ` Peter Zijlstra
2010-10-18 19:17   ` [tip:core/locking] lockdep: Add improved subclass caching tip-bot for Hitoshi Mitake
2010-10-12 10:27 ` [PATCH 1/2] lockdep: check the depth of subclass Peter Zijlstra
2010-10-12 16:03   ` Dmitry Torokhov
2010-10-13  2:27     ` Hitoshi Mitake
2010-10-13 18:18       ` Dmitry Torokhov
2010-10-13  2:26   ` Hitoshi Mitake
2010-10-13  7:33     ` Peter Zijlstra
2010-10-13  8:13       ` Hitoshi Mitake
2010-10-13  8:30         ` [PATCH v2] " Hitoshi Mitake
2010-10-13  8:48           ` Peter Zijlstra
2010-10-18 19:17           ` [tip:core/locking] lockdep: Check " tip-bot for Hitoshi Mitake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox