Skip to content

Commit de4b59d

Browse files
Waiman-LongIngo Molnar
authored andcommitted
locking/lockdep: Add kasan_check_byte() check in lock_acquire()
KASAN instrumentation of lockdep has been disabled, as we don't need KASAN to check the validity of lockdep internal data structures and incur unnecessary performance overhead. However, the lockdep_map pointer passed in externally may not be valid (e.g. use-after-free) and we run the risk of using garbage data resulting in false lockdep reports. Add kasan_check_byte() call in lock_acquire() for non kernel core data object to catch invalid lockdep_map and print out a KASAN report before any lockdep splat, if any. Suggested-by: Marco Elver <[email protected]> Signed-off-by: Waiman Long <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Marco Elver <[email protected]> Reviewed-by: Andrey Konovalov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected]
1 parent ee57ab5 commit de4b59d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel/locking/lockdep.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/lockdep.h>
5858
#include <linux/context_tracking.h>
5959
#include <linux/console.h>
60+
#include <linux/kasan.h>
6061

6162
#include <asm/sections.h>
6263

@@ -5830,6 +5831,14 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
58305831
if (!debug_locks)
58315832
return;
58325833

5834+
/*
5835+
* As KASAN instrumentation is disabled and lock_acquire() is usually
5836+
* the first lockdep call when a task tries to acquire a lock, add
5837+
* kasan_check_byte() here to check for use-after-free and other
5838+
* memory errors.
5839+
*/
5840+
kasan_check_byte(lock);
5841+
58335842
if (unlikely(!lockdep_enabled())) {
58345843
/* XXX allow trylock from NMI ?!? */
58355844
if (lockdep_nmi() && !trylock) {

0 commit comments

Comments
 (0)