netdev
[Top] [All Lists]

[PATCH 2.4 NETLINK]: Unhash sockets correctly

To: "David S. Miller" <davem@xxxxxxxxxxxxx>
Subject: [PATCH 2.4 NETLINK]: Unhash sockets correctly
From: Patrick McHardy <kaber@xxxxxxxxx>
Date: Wed, 16 Feb 2005 19:54:17 +0100
Cc: Maillist netdev <netdev@xxxxxxxxxxx>
Sender: netdev-bounce@xxxxxxxxxxx
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.5) Gecko/20050106 Debian/1.7.5-1
Hi Dave,

this patch fixes a nasty bug introduced by the pid-hash backport.
Sockets are only unhashed if they are contained in the first hash
bucket. This leads to leaking sockets and, over time, to bind
conflicts which confuse iproute and result in sporadic failure.

Regards
Patrick

# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2005/02/16 19:32:38+01:00 kaber@xxxxxxxxxxxx 
#   [NETLINK]: Unhash sockets correctly
#   
#   netlink_remove() only unhashes sockets contained in the
#   first hash bucket. This leads to leaking sockets and,
#   over time, to bind conflicts which confuse iproute.
#   
#   Signed-off-by: Patrick McHardy <kaber@xxxxxxxxx>
# 
# net/netlink/af_netlink.c
#   2005/02/16 19:32:36+01:00 kaber@xxxxxxxxxxxx +2 -1
#   [NETLINK]: Unhash sockets correctly
#   
#   netlink_remove() only unhashes sockets contained in the
#   first hash bucket. This leads to leaking sockets and,
#   over time, to bind conflicts which confuse iproute.
#   
#   Signed-off-by: Patrick McHardy <kaber@xxxxxxxxx>
# 
diff -Nru a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
--- a/net/netlink/af_netlink.c  2005-02-16 19:32:51 +01:00
+++ b/net/netlink/af_netlink.c  2005-02-16 19:32:51 +01:00
@@ -327,10 +327,11 @@
        struct sock **skp;
        struct netlink_table *table = &nl_table[sk->protocol];
        struct nl_pid_hash *hash = &table->hash;
+       u32 pid = nlk_sk(sk)->pid;
 
        netlink_table_grab();
        hash->entries--;
-       for (skp = hash->table; *skp; skp = &((*skp)->next)) {
+       for (skp = nl_pid_hashfn(hash, pid); *skp; skp = &((*skp)->next)) {
                if (*skp == sk) {
                        *skp = sk->next;
                        __sock_put(sk);
<Prev in Thread] Current Thread [Next in Thread>