Skip to content

Commit 28eab3d

Browse files
Peter Zijlstragregkh
authored andcommitted
locking/lockdep: Add nest_lock integrity test
[ Upstream commit 7fb4a2cea6b18dab56d609530d077f168169ed6b ] Boqun reported that hlock->references can overflow. Add a debug test for that to generate a clear error when this happens. Without this, lockdep is likely to report a mysterious failure on unlock. Reported-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Nicolai Hähnle <Nicolai.Haehnle@amd.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d44e463 commit 28eab3d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

kernel/locking/lockdep.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,10 +3128,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
31283128
if (depth) {
31293129
hlock = curr->held_locks + depth - 1;
31303130
if (hlock->class_idx == class_idx && nest_lock) {
3131-
if (hlock->references)
3131+
if (hlock->references) {
3132+
/*
3133+
* Check: unsigned int references:12, overflow.
3134+
*/
3135+
if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1))
3136+
return 0;
3137+
31323138
hlock->references++;
3133-
else
3139+
} else {
31343140
hlock->references = 2;
3141+
}
31353142

31363143
return 1;
31373144
}

0 commit comments

Comments
 (0)