Skip to content

Commit

Permalink
kmemleak: Do not return a pointer to an object that kmemleak did not get
Browse files Browse the repository at this point in the history
The kmemleak_seq_next() function tries to get an object (and increment
its use count) before returning it. If it could not get the last object
during list traversal (because it may have been freed), the function
should return NULL rather than a pointer to such object that it did not
get.

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Reported-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Acked-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Cc: <stable@kernel.org>
  • Loading branch information
ctmarinas committed May 19, 2011
1 parent 8e10cd7 commit 52c3ce4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mm/kmemleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -1414,9 +1414,12 @@ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos)
++(*pos);

list_for_each_continue_rcu(n, &object_list) {
next_obj = list_entry(n, struct kmemleak_object, object_list);
if (get_object(next_obj))
struct kmemleak_object *obj =
list_entry(n, struct kmemleak_object, object_list);
if (get_object(obj)) {
next_obj = obj;
break;
}
}

put_object(prev_obj);
Expand Down

0 comments on commit 52c3ce4

Please sign in to comment.