@@ -2479,11 +2479,11 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
* So we create one inside init_net and the move it to net.
*/
- if (__netlink_create(&init_net, sock, cb_mutex, unit) < 0)
+ if (__netlink_create(net, sock, cb_mutex, unit) < 0)
goto out_sock_release_nosk;
sk = sock->sk;
- sk_change_net(sk, net);
+ put_net(sock_net(sk));
if (!cfg || cfg->groups < 32)
groups = 32;
@@ -2539,7 +2539,8 @@ EXPORT_SYMBOL(__netlink_kernel_create);
void
netlink_kernel_release(struct sock *sk)
{
- sk_release_kernel(sk);
+ get_net(sock_net(sk));
+ sock_release(sk->sk_socket);
}
EXPORT_SYMBOL(netlink_kernel_release);
As now the race between put_net() and netlink_kernel_create() is resolved, it's unnecessary to switch namespace for a netlink kernel socket from init_net to its desirable one, which means the kernel socket is created and released within one namespace. But as the kernel socket is part of a namespace, we should not hold a reference count to the namespace, otherwise, probably modules relying on it cannot be stopped. Signed-off-by: Ying Xue <ying.xue@windriver.com> --- net/netlink/af_netlink.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)