Skip to content

Commit

Permalink
percpu_ref_init(): clean ->percpu_count_ref on failure
Browse files Browse the repository at this point in the history
That way percpu_ref_exit() is safe after failing percpu_ref_init().
At least one user (cgroup_create()) had a double-free that way;
there might be other similar bugs.  Easier to fix in percpu_ref_init(),
rather than playing whack-a-mole in sloppy users...

Usual symptoms look like a messed refcounting in one of subsystems
that use percpu allocations (might be percpu-refcount, might be
something else).  Having refcounts for two different objects share
memory is Not Nice(tm)...

Reported-by: [email protected]
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed May 18, 2022
1 parent feb9c5e commit a917143
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/percpu-refcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release,
data = kzalloc(sizeof(*ref->data), gfp);
if (!data) {
free_percpu((void __percpu *)ref->percpu_count_ptr);
ref->percpu_count_ptr = 0;
return -ENOMEM;
}

Expand Down

0 comments on commit a917143

Please sign in to comment.