From: Waiman Long Date: Tue, 6 May 2025 04:20:48 +0000 (-0700) Subject: locking/lockdep: Prevent abuse of lockdep subclass X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=6a1a219f535a437eb12a06d8cef2518e58654beb;p=users%2Fjedix%2Flinux-maple.git locking/lockdep: Prevent abuse of lockdep subclass To catch the code trying to use a subclass value >= MAX_LOCKDEP_SUBCLASSES (8), add a DEBUG_LOCKS_WARN_ON() statement to notify the users that such a large value is not allowed. [ boqun: Reword the commit log with a more objective tone ] Signed-off-by: Waiman Long Signed-off-by: Boqun Feng Signed-off-by: Ingo Molnar Cc: Bill Wendling Cc: Justin Stitt Cc: Nathan Chancellor Cc: Nick Desaulniers Cc: Peter Zijlstra Cc: Will Deacon Cc: llvm@lists.linux.dev Link: https://lore.kernel.org/r/20250506042049.50060-3-boqun.feng@gmail.com --- diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 546e92827de4..050dbe9eec3c 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -5101,6 +5101,9 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, lockevent_inc(lockdep_nocheck); } + if (DEBUG_LOCKS_WARN_ON(subclass >= MAX_LOCKDEP_SUBCLASSES)) + return 0; + if (subclass < NR_LOCKDEP_CACHING_CLASSES) class = lock->class_cache[subclass]; /*