]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
locking/lockdep: Prevent abuse of lockdep subclass
authorWaiman Long <longman@redhat.com>
Tue, 6 May 2025 04:20:48 +0000 (21:20 -0700)
committerIngo Molnar <mingo@kernel.org>
Tue, 6 May 2025 16:34:35 +0000 (18:34 +0200)
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 <longman@redhat.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Bill Wendling <morbo@google.com>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Cc: llvm@lists.linux.dev
Link: https://lore.kernel.org/r/20250506042049.50060-3-boqun.feng@gmail.com
kernel/locking/lockdep.c

index 546e92827de4d5cc90ee0d1b64ba59bc83c6964d..050dbe9eec3c4c2c194c422aa8f4f95ed833b24e 100644 (file)
@@ -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];
        /*