Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 81874
b: refs/heads/master
c: 23fe186
h: refs/heads/master
v: v3
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Feb 1, 2008
1 parent c6a9016 commit ac39e32
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 533cb5b0a63f28ecab5503cfceb77e641fa7f7c4
refs/heads/master: 23fe18669e7fdaf5b229747858d943a723124e2e
52 changes: 33 additions & 19 deletions trunk/net/netlink/af_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,22 @@ static void netlink_data_ready(struct sock *sk, int len)
* queueing.
*/

static void __netlink_release(struct sock *sk)
{
/*
* Last sock_put should drop referrence to sk->sk_net. It has already
* been dropped in netlink_kernel_create. Taking referrence to stopping
* namespace is not an option.
* Take referrence to a socket to remove it from netlink lookup table
* _alive_ and after that destroy it in the context of init_net.
*/

sock_hold(sk);
sock_release(sk->sk_socket);
sk->sk_net = get_net(&init_net);
sock_put(sk);
}

struct sock *
netlink_kernel_create(struct net *net, int unit, unsigned int groups,
void (*input)(struct sk_buff *skb),
Expand All @@ -1362,8 +1378,18 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
if (sock_create_lite(PF_NETLINK, SOCK_DGRAM, unit, &sock))
return NULL;

if (__netlink_create(net, sock, cb_mutex, unit) < 0)
goto out_sock_release;
/*
* We have to just have a reference on the net from sk, but don't
* get_net it. Besides, we cannot get and then put the net here.
* So we create one inside init_net and the move it to net.
*/

if (__netlink_create(&init_net, sock, cb_mutex, unit) < 0)
goto out_sock_release_nosk;

sk = sock->sk;
put_net(sk->sk_net);
sk->sk_net = net;

if (groups < 32)
groups = 32;
Expand All @@ -1372,7 +1398,6 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
if (!listeners)
goto out_sock_release;

sk = sock->sk;
sk->sk_data_ready = netlink_data_ready;
if (input)
nlk_sk(sk)->netlink_rcv = input;
Expand All @@ -1395,14 +1420,14 @@ netlink_kernel_create(struct net *net, int unit, unsigned int groups,
nl_table[unit].registered++;
}
netlink_table_ungrab();

/* Do not hold an extra referrence to a namespace as this socket is
* internal to a namespace and does not prevent it to stop. */
put_net(net);
return sk;

out_sock_release:
kfree(listeners);
__netlink_release(sk);
return NULL;

out_sock_release_nosk:
sock_release(sock);
return NULL;
}
Expand All @@ -1415,18 +1440,7 @@ netlink_kernel_release(struct sock *sk)
if (sk == NULL || sk->sk_socket == NULL)
return;

/*
* Last sock_put should drop referrence to sk->sk_net. It has already
* been dropped in netlink_kernel_create. Taking referrence to stopping
* namespace is not an option.
* Take referrence to a socket to remove it from netlink lookup table
* _alive_ and after that destroy it in the context of init_net.
*/
sock_hold(sk);
sock_release(sk->sk_socket);

sk->sk_net = get_net(&init_net);
sock_put(sk);
__netlink_release(sk);
}
EXPORT_SYMBOL(netlink_kernel_release);

Expand Down

0 comments on commit ac39e32

Please sign in to comment.