public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Wright <chrisw@osdl.org>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: akpm@osdl.org, "Theodore Ts'o" <tytso@mit.edu>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	Justin Forbes <jmforbes@linuxtx.org>,
	Randy Dunlap <rdunlap@xenotime.net>,
	torvalds@osdl.org, Chuck Wolber <chuckw@quantumlinux.com>,
	alan@lxorguk.ukuu.org.uk, davem@davemloft.net
Subject: [07/07] [NETLINK]: Fix two socket hashing bugs.
Date: Mon, 27 Jun 2005 16:05:12 -0700	[thread overview]
Message-ID: <20050627230512.GP9046@shell0.pdx.osdl.net> (raw)
In-Reply-To: <20050627224651.GI9046@shell0.pdx.osdl.net>

-stable review patch.  If anyone has any objections, please let us know.

------------------


1) netlink_release() should only decrement the hash entry
   count if the socket was actually hashed.

   This was causing hash->entries to underflow, which
   resulting in all kinds of troubles.

   On 64-bit systems, this would cause the following
   conditional to erroneously trigger:

	err = -ENOMEM;
	if (BITS_PER_LONG > 32 && unlikely(hash->entries >= UINT_MAX))
		goto err;

2) netlink_autobind() needs to propagate the error return from
   netlink_insert().  Otherwise, callers will not see the error
   as they should and thus try to operate on a socket with a zero pid,
   which is very bad.

   However, it should not propagate -EBUSY.  If two threads race
   to autobind the socket, that is fine.  This is consistent with the
   autobind behavior in other protocols.

   So bug #1 above, combined with this one, resulted in hangs
   on netlink_sendmsg() calls to the rtnetlink socket.  We'd try
   to do the user sendmsg() with the socket's pid set to zero,
   later we do a socket lookup using that pid (via the value we
   stashed away in NETLINK_CB(skb).pid), but that won't give us the
   user socket, it will give us the rtnetlink socket.  So when we
   try to wake up the receive queue, we dive back into rtnetlink_rcv()
   which tries to recursively take the rtnetlink semaphore.

Thanks to Jakub Jelink for providing backtraces.  Also, thanks to
Herbert Xu for supplying debugging patches to help track this down,
and also finding a mistake in an earlier version of this fix.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chris Wright <chrisw@osdl.org>
---

--- 1/net/netlink/af_netlink.c.~1~	2005-06-26 15:30:20.000000000 -0700
+++ 2/net/netlink/af_netlink.c	2005-06-26 15:30:46.000000000 -0700
@@ -315,8 +315,8 @@
 static void netlink_remove(struct sock *sk)
 {
 	netlink_table_grab();
-	nl_table[sk->sk_protocol].hash.entries--;
-	sk_del_node_init(sk);
+	if (sk_del_node_init(sk))
+		nl_table[sk->sk_protocol].hash.entries--;
 	if (nlk_sk(sk)->groups)
 		__sk_del_bind_node(sk);
 	netlink_table_ungrab();
@@ -429,7 +429,12 @@
 	err = netlink_insert(sk, pid);
 	if (err == -EADDRINUSE)
 		goto retry;
-	return 0;
+
+	/* If 2 threads race to autobind, that is fine.  */
+	if (err == -EBUSY)
+		err = 0;
+
+	return err;
 }
 
 static inline int netlink_capable(struct socket *sock, unsigned int flag) 


  parent reply	other threads:[~2005-06-27 23:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-27 22:46 [00/07] -stable review Chris Wright
2005-06-27 22:50 ` [01/07] Fix typo in drivers/pci/pci-driver.c Chris Wright
2005-06-27 22:53 ` [02/07] [SCSI] qla2xxx: Pull-down scsi-host-addition to follow board initialization Chris Wright
2005-06-28 21:51   ` Jean Delvare
2005-06-28 22:20     ` Andrew Morton
2005-06-28 22:30       ` Chris Wright
2005-06-28 23:09         ` Andrew Morton
2005-06-28 23:16           ` Chris Wright
2005-06-28 22:32       ` [stable] " Greg KH
2005-06-29  8:08       ` Jean Delvare
2005-06-29 16:36         ` James Bottomley
2005-07-01 11:32           ` Jean Delvare
2005-06-27 22:55 ` [03/07] fix remap_pte_range BUG Chris Wright
2005-06-27 22:59 ` [04/07] e1000: fix spinlock bug Chris Wright
2005-06-27 23:01 ` [05/07] Add "memory" clobbers to the x86 inline asm of strncmp and friends Chris Wright
2005-06-28 21:57   ` Jean Delvare
2005-06-27 23:03 ` [06/07] ACPI: Make sure we call acpi_register_gsi() even for default PCI interrupt assignment Chris Wright
2005-06-27 23:05 ` Chris Wright [this message]
2005-06-28 12:10 ` [00/07] -stable review Jim MacBaine
2005-06-28 14:47   ` [stable] " Chris Wright
2005-06-28 17:18     ` Jim MacBaine
2005-06-28 17:20       ` Chris Wright
2005-06-28 20:45   ` David S. Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050627230512.GP9046@shell0.pdx.osdl.net \
    --to=chrisw@osdl.org \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chuckw@quantumlinux.com \
    --cc=davem@davemloft.net \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@xenotime.net \
    --cc=stable@kernel.org \
    --cc=torvalds@osdl.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox