Skip to contentSkip to conversation

locking/lockdep: Prevent abuse of lockdep subclass

PATCH Applied Waiman Long 2 participants 2 messages Apr 9, 2025 – May 4, 2025 Locking primitives

lore
Share & tools
lore

Waiman Long

author reviewer
#0 lore raw

PATCH 1/1 locking/lockdep: Prevent abuse of lockdep subclass

As I have seen 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.

---
 kernel/locking/lockdep.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/locking/lockdep.c +3 -0
index 58d78a33ac65..3fb79d8fecdf 100644
@@ -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];
 	/*
Signature · 1 line
2.48.1
Applied
#1 lore raw
Quoted 5 lines · Waiman Long

As I have seen 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.

Queued for 6.16, thanks!

Regards,
Boqun

Quoted 21 lines
---
 kernel/locking/lockdep.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/locking/lockdep.c +3 -0
index 58d78a33ac65..3fb79d8fecdf 100644
@@ -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];
 	/*
Signature · 1 line
2.48.1