Skip to content

Commit f5886c7

Browse files
ctmarinastorvalds
authored andcommitted
kmemleak: Protect the seq start/next/stop sequence by rcu_read_lock()
Objects passed to kmemleak_seq_next() have an incremented reference count (hence not freed) but they may point via object_list.next to other freed objects. To avoid this, the whole start/next/stop sequence must be protected by rcu_read_lock(). Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 84210ae commit f5886c7

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

‎mm/kmemleak.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,6 @@ static void *kmemleak_seq_start(struct seq_file *seq, loff_t *pos)
12171217
}
12181218
object = NULL;
12191219
out:
1220-
rcu_read_unlock();
12211220
return object;
12221221
}
12231222

@@ -1233,13 +1232,11 @@ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos)
12331232

12341233
++(*pos);
12351234

1236-
rcu_read_lock();
12371235
list_for_each_continue_rcu(n, &object_list) {
12381236
next_obj = list_entry(n, struct kmemleak_object, object_list);
12391237
if (get_object(next_obj))
12401238
break;
12411239
}
1242-
rcu_read_unlock();
12431240

12441241
put_object(prev_obj);
12451242
return next_obj;
@@ -1255,6 +1252,7 @@ static void kmemleak_seq_stop(struct seq_file *seq, void *v)
12551252
* kmemleak_seq_start may return ERR_PTR if the scan_mutex
12561253
* waiting was interrupted, so only release it if !IS_ERR.
12571254
*/
1255+
rcu_read_unlock();
12581256
mutex_unlock(&scan_mutex);
12591257
if (v)
12601258
put_object(v);

0 commit comments

Comments
 (0)