net: call cgroup_sk_alloc() earlier in sk_clone_lock()
authorEric Dumazet <edumazet@google.com>
Wed, 11 Oct 2017 02:12:33 +0000 (19:12 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Nov 2017 10:22:21 +0000 (11:22 +0100)
commitcb5880e677a1310be578b6cf4d1093d2bfa2be1a
tree8886b5fb99f75504c1fe1a3ab6685a590d6fbe1f
parent4cd69ad53001ae399b6474113864a4ca190498fd
net: call cgroup_sk_alloc() earlier in sk_clone_lock()

[ Upstream commit c0576e3975084d4699b7bfef578613fb8e1144f6 ]

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: d979a39d7242 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/core/sock.c