* [PATCH] Don't attach callback to a going-away netlink socket
@ 2007-04-16 11:39 Pavel Emelianov
2007-04-16 11:41 ` Patrick McHardy
2007-04-16 12:37 ` James Morris
0 siblings, 2 replies; 5+ messages in thread
From: Pavel Emelianov @ 2007-04-16 11:39 UTC (permalink / raw)
To: Andrew Morton, Linux Kernel Mailing List, devel
[-- Attachment #1: Type: text/plain, Size: 189 bytes --]
From: Denis Lunev <den@openvz.org>
There is a race between netlink_dump_start() and netlink_release()
that can lead to the situation when a netlink socket with non-zero
callback is freed.
[-- Attachment #2: diff-netlink-dont-dump-in-dead-socket --]
[-- Type: text/plain, Size: 887 bytes --]
--- a/net/netlink/af_netlink.c 2004-10-25 12:12:23.000000000 +0400
+++ b/net/netlink/af_netlink.c 2004-10-28 16:26:12.000000000 +0400
@@ -255,6 +255,7 @@ static int netlink_release(struct socket
return 0;
netlink_remove(sk);
+ sock_orphan(sk);
nlk = nlk_sk(sk);
spin_lock(&nlk->cb_lock);
@@ -269,7 +270,6 @@ static int netlink_release(struct socket
/* OK. Socket is unlinked, and, therefore,
no new packets will arrive */
- sock_orphan(sk);
sock->sk = NULL;
wake_up_interruptible_all(&nlk->wait);
@@ -942,9 +942,9 @@ int netlink_dump_start(struct sock *ssk,
return -ECONNREFUSED;
}
nlk = nlk_sk(sk);
- /* A dump is in progress... */
+ /* A dump or destruction is in progress... */
spin_lock(&nlk->cb_lock);
- if (nlk->cb) {
+ if (nlk->cb || sock_flag(sk, SOCK_DEAD)) {
spin_unlock(&nlk->cb_lock);
netlink_destroy_callback(cb);
sock_put(sk);
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Don't attach callback to a going-away netlink socket
2007-04-16 11:39 [PATCH] Don't attach callback to a going-away netlink socket Pavel Emelianov
@ 2007-04-16 11:41 ` Patrick McHardy
2007-04-16 11:58 ` Pavel Emelianov
2007-04-16 12:37 ` James Morris
1 sibling, 1 reply; 5+ messages in thread
From: Patrick McHardy @ 2007-04-16 11:41 UTC (permalink / raw)
To: Pavel Emelianov
Cc: Andrew Morton, Linux Kernel Mailing List, devel,
Linux Netdev List
Pavel Emelianov wrote:
> From: Denis Lunev <den@openvz.org>
>
> There is a race between netlink_dump_start() and netlink_release()
> that can lead to the situation when a netlink socket with non-zero
> callback is freed.
Can you describe the race in more detail please?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Don't attach callback to a going-away netlink socket
2007-04-16 11:41 ` Patrick McHardy
@ 2007-04-16 11:58 ` Pavel Emelianov
2007-04-16 12:55 ` Patrick McHardy
0 siblings, 1 reply; 5+ messages in thread
From: Pavel Emelianov @ 2007-04-16 11:58 UTC (permalink / raw)
To: Patrick McHardy
Cc: Andrew Morton, Linux Kernel Mailing List, devel,
Linux Netdev List
Patrick McHardy wrote:
> Pavel Emelianov wrote:
>> From: Denis Lunev <den@openvz.org>
>>
>> There is a race between netlink_dump_start() and netlink_release()
>> that can lead to the situation when a netlink socket with non-zero
>> callback is freed.
>
>
> Can you describe the race in more detail please?
>
>
Here it is:
CPU1: CPU2
netlink_release(): netlink_dump_start():
sk = netlink_lookup(); /* OK */
netlink_remove();
spin_lock(&nlk->cb_lock);
if (nlk->cb) { /* false */
...
}
spin_unlock(&nlk->cb_lock);
spin_lock(&nlk->cb_lock);
if (nlk->cb) { /* false */
...
}
nlk->cb = cb;
spin_unlock(&nlk->cb_lock);
...
sock_orphan(sk);
/*
* proceed with releasing
* the socket
*/
The proposal it to make sock_orphan before detaching the callback
in netlink_release() and to check for the sock to be SOCK_DEAD in
netlink_dump_start() before setting a new callback.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Don't attach callback to a going-away netlink socket
2007-04-16 11:58 ` Pavel Emelianov
@ 2007-04-16 12:55 ` Patrick McHardy
0 siblings, 0 replies; 5+ messages in thread
From: Patrick McHardy @ 2007-04-16 12:55 UTC (permalink / raw)
To: Pavel Emelianov
Cc: Andrew Morton, Linux Kernel Mailing List, devel,
Linux Netdev List
Pavel Emelianov wrote:
> Patrick McHardy wrote:
>
>>>There is a race between netlink_dump_start() and netlink_release()
>>>that can lead to the situation when a netlink socket with non-zero
>>>callback is freed.
>>
>>
>>Can you describe the race in more detail please?
>>
>
> Here it is:
>
> [...]
> The proposal it to make sock_orphan before detaching the callback
> in netlink_release() and to check for the sock to be SOCK_DEAD in
> netlink_dump_start() before setting a new callback.
Thanks, good catch. Your patch also looks good.
Acked-by: Patrick McHardy <kaber@trash.net>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Don't attach callback to a going-away netlink socket
2007-04-16 11:39 [PATCH] Don't attach callback to a going-away netlink socket Pavel Emelianov
2007-04-16 11:41 ` Patrick McHardy
@ 2007-04-16 12:37 ` James Morris
1 sibling, 0 replies; 5+ messages in thread
From: James Morris @ 2007-04-16 12:37 UTC (permalink / raw)
To: Pavel Emelianov; +Cc: Andrew Morton, Linux Kernel Mailing List, devel
Please post networking patches to the networking developer list:
http://vger.kernel.org/vger-lists.html#netdev
- James
--
James Morris
<jmorris@namei.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-04-16 12:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-16 11:39 [PATCH] Don't attach callback to a going-away netlink socket Pavel Emelianov
2007-04-16 11:41 ` Patrick McHardy
2007-04-16 11:58 ` Pavel Emelianov
2007-04-16 12:55 ` Patrick McHardy
2007-04-16 12:37 ` James Morris
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.