Skip to content

Commit

Permalink
net: call cgroup_sk_alloc() earlier in sk_clone_lock()
Browse files Browse the repository at this point in the history
If for some reason, the newly allocated child need to be freed,
we will call cgroup_put() (via sk_free_unlock_clone()) while the
corresponding cgroup_get() was not yet done, and we will free memory
too soon.

Fixes: d979a39 ("cgroup: duplicate cgroup reference when cloning sockets")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Oct 11, 2017
1 parent 75cb070 commit c0576e3
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
atomic_set(&newsk->sk_zckey, 0);

sock_reset_flag(newsk, SOCK_DONE);
cgroup_sk_alloc(&newsk->sk_cgrp_data);

rcu_read_lock();
filter = rcu_dereference(sk->sk_filter);
Expand Down Expand Up @@ -1718,8 +1719,6 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
newsk->sk_incoming_cpu = raw_smp_processor_id();
atomic64_set(&newsk->sk_cookie, 0);

cgroup_sk_alloc(&newsk->sk_cgrp_data);

/*
* Before updating sk_refcnt, we must commit prior changes to memory
* (Documentation/RCU/rculist_nulls.txt for details)
Expand Down

0 comments on commit c0576e3

Please sign in to comment.