From 6a1a219f535a437eb12a06d8cef2518e58654beb Mon Sep 17 00:00:00 2001 From: Waiman Long Date: Mon, 5 May 2025 21:20:48 -0700 Subject: [PATCH] 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 --- kernel/locking/lockdep.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 546e92827de4d..050dbe9eec3c4 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]; /* -- 2.47.2