Skip to content

Commit c0576e3

Browse files
Eric Dumazetdavem330
authored andcommitted
net: call cgroup_sk_alloc() earlier in sk_clone_lock()
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 <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Tejun Heo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 75cb070 commit c0576e3

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

net/core/sock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,7 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
16871687
atomic_set(&newsk->sk_zckey, 0);
16881688

16891689
sock_reset_flag(newsk, SOCK_DONE);
1690+
cgroup_sk_alloc(&newsk->sk_cgrp_data);
16901691

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

1721-
cgroup_sk_alloc(&newsk->sk_cgrp_data);
1722-
17231722
/*
17241723
* Before updating sk_refcnt, we must commit prior changes to memory
17251724
* (Documentation/RCU/rculist_nulls.txt for details)

0 commit comments

Comments
 (0)