Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lockdep: Fix a race between /proc/lock_stat and module unload

The lock_class iteration of /proc/lock_stat is not serialized against
the lockdep_free_key_range() call from module unload.

Therefore it can happen that we find a class of which ->name/->key are
no longer valid.

There is a further bug in zap_class() that left ->name dangling. Cure
this. Use RCU_INIT_POINTER() because NULL.

Since lockdep_free_key_range() is rcu_sched serialized, we can read
both ->name and ->key under rcu_read_lock_sched() (preempt-disable)
and be assured that if we observe a !NULL value it stays safe to use
for as long as we hold that lock.

If we observe both NULL, skip the entry.

Reported-by: Jerome Marchand <jmarchan@redhat.com>
Tested-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20150602105013.GS3644@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Peter Zijlstra and committed by
Ingo Molnar
cee34d88 37ef1647

+19 -6
+2 -1
kernel/locking/lockdep.c
··· 3900 3900 list_del_rcu(&class->hash_entry); 3901 3901 list_del_rcu(&class->lock_entry); 3902 3902 3903 - class->key = NULL; 3903 + RCU_INIT_POINTER(class->key, NULL); 3904 + RCU_INIT_POINTER(class->name, NULL); 3904 3905 } 3905 3906 3906 3907 static inline int within(const void *addr, void *start, unsigned long size)
+17 -5
kernel/locking/lockdep_proc.c
··· 426 426 427 427 static void seq_stats(struct seq_file *m, struct lock_stat_data *data) 428 428 { 429 - char name[39]; 430 - struct lock_class *class; 429 + struct lockdep_subclass_key *ckey; 431 430 struct lock_class_stats *stats; 431 + struct lock_class *class; 432 + const char *cname; 432 433 int i, namelen; 434 + char name[39]; 433 435 434 436 class = data->class; 435 437 stats = &data->stats; ··· 442 440 if (class->subclass) 443 441 namelen -= 2; 444 442 445 - if (!class->name) { 443 + rcu_read_lock_sched(); 444 + cname = rcu_dereference_sched(class->name); 445 + ckey = rcu_dereference_sched(class->key); 446 + 447 + if (!cname && !ckey) { 448 + rcu_read_unlock_sched(); 449 + return; 450 + 451 + } else if (!cname) { 446 452 char str[KSYM_NAME_LEN]; 447 453 const char *key_name; 448 454 449 - key_name = __get_key_name(class->key, str); 455 + key_name = __get_key_name(ckey, str); 450 456 snprintf(name, namelen, "%s", key_name); 451 457 } else { 452 - snprintf(name, namelen, "%s", class->name); 458 + snprintf(name, namelen, "%s", cname); 453 459 } 460 + rcu_read_unlock_sched(); 461 + 454 462 namelen = strlen(name); 455 463 if (class->name_version > 1) { 456 464 snprintf(name+namelen, 3, "#%d", class->name_version);