netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [SCTP] Bug fixes to the migrate/accept code path.
@ 2007-12-06 17:48 Vlad Yasevich
  2007-12-06 17:48 ` [PATCH] SCTP: Add bind hash locking to the migrate code Vlad Yasevich
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vlad Yasevich @ 2007-12-06 17:48 UTC (permalink / raw)
  To: davem; +Cc: netdev, lksctp-developers

Hi Dave

The following two patches fix some bugs in the SCTP accept code path.
The first one fixes a slab corruption bug that we found during stress
testing.  The second one is just a clean-up and the right way to do things.

You can also pull both from:
  master.kernel.org:/pub/scm/linux/kernel/git/lksctp-dev.git pending

Thanks
-vlad

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] SCTP: Add bind hash locking to the migrate code
  2007-12-06 17:48 [SCTP] Bug fixes to the migrate/accept code path Vlad Yasevich
@ 2007-12-06 17:48 ` Vlad Yasevich
  2007-12-06 17:48 ` [PATCH] SCTP: Fix the bind_addr info during migration Vlad Yasevich
  2007-12-07  6:51 ` [SCTP] Bug fixes to the migrate/accept code path David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Vlad Yasevich @ 2007-12-06 17:48 UTC (permalink / raw)
  To: davem; +Cc: netdev, lksctp-developers, Vlad Yasevich

SCTP accept code tries to add a newliy created socket
to a bind bucket without holding a lock.   On a really
busy system, that can causes slab corruptions.
Add a lock around this code.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
---
 net/sctp/socket.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index ff8bc95..9f5d793 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -6325,6 +6325,7 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
 	struct sctp_endpoint *newep = newsp->ep;
 	struct sk_buff *skb, *tmp;
 	struct sctp_ulpevent *event;
+	struct sctp_bind_hashbucket *head;
 	int flags = 0;
 
 	/* Migrate socket buffer sizes and all the socket level options to the
@@ -6342,10 +6343,15 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
 	newsp->hmac = NULL;
 
 	/* Hook this new socket in to the bind_hash list. */
+	head = &sctp_port_hashtable[sctp_phashfn(inet_sk(oldsk)->num)];
+	sctp_local_bh_disable();
+	sctp_spin_lock(&head->lock);
 	pp = sctp_sk(oldsk)->bind_hash;
 	sk_add_bind_node(newsk, &pp->owner);
 	sctp_sk(newsk)->bind_hash = pp;
 	inet_sk(newsk)->num = inet_sk(oldsk)->num;
+	sctp_spin_unlock(&head->lock);
+	sctp_local_bh_enable();
 
 	/* Copy the bind_addr list from the original endpoint to the new
 	 * endpoint so that we can handle restarts properly
-- 
1.5.3.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] SCTP: Fix the bind_addr info during migration.
  2007-12-06 17:48 [SCTP] Bug fixes to the migrate/accept code path Vlad Yasevich
  2007-12-06 17:48 ` [PATCH] SCTP: Add bind hash locking to the migrate code Vlad Yasevich
@ 2007-12-06 17:48 ` Vlad Yasevich
  2007-12-07  6:51 ` [SCTP] Bug fixes to the migrate/accept code path David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Vlad Yasevich @ 2007-12-06 17:48 UTC (permalink / raw)
  To: davem; +Cc: netdev, lksctp-developers, Vlad Yasevich

During accept/migrate the code attempts to copy the addresses from
the parent endpoint to the new endpoint.   However, if the parent
was bound to a wildcard address, then we end up pointlessly copying
all of the current addresses on the system.

Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
---
 include/net/sctp/structs.h |    3 +++
 net/sctp/bind_addr.c       |   26 ++++++++++++++++++++++++++
 net/sctp/socket.c          |   12 ++----------
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
index eb3113c..002a00a 100644
--- a/include/net/sctp/structs.h
+++ b/include/net/sctp/structs.h
@@ -1184,6 +1184,9 @@ int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
 			const struct sctp_bind_addr *src,
 			sctp_scope_t scope, gfp_t gfp,
 			int flags);
+int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
+			const struct sctp_bind_addr *src,
+			gfp_t gfp);
 int sctp_add_bind_addr(struct sctp_bind_addr *, union sctp_addr *,
 		       __u8 use_as_src, gfp_t gfp);
 int sctp_del_bind_addr(struct sctp_bind_addr *, union sctp_addr *);
diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c
index cae95af..6a7d010 100644
--- a/net/sctp/bind_addr.c
+++ b/net/sctp/bind_addr.c
@@ -105,6 +105,32 @@ out:
 	return error;
 }
 
+/* Exactly duplicate the address lists.  This is necessary when doing
+ * peer-offs and accepts.  We don't want to put all the current system
+ * addresses into the endpoint.  That's useless.  But we do want duplicat
+ * the list of bound addresses that the older endpoint used.
+ */
+int sctp_bind_addr_dup(struct sctp_bind_addr *dest,
+			const struct sctp_bind_addr *src,
+			gfp_t gfp)
+{
+	struct sctp_sockaddr_entry *addr;
+	struct list_head *pos;
+	int error = 0;
+
+	/* All addresses share the same port.  */
+	dest->port = src->port;
+
+	list_for_each(pos, &src->address_list) {
+		addr = list_entry(pos, struct sctp_sockaddr_entry, list);
+		error = sctp_add_bind_addr(dest, &addr->a, 1, gfp);
+		if (error < 0)
+			break;
+	}
+
+	return error;
+}
+
 /* Initialize the SCTP_bind_addr structure for either an endpoint or
  * an association.
  */
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 9f5d793..ea9649c 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -6326,7 +6326,6 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
 	struct sk_buff *skb, *tmp;
 	struct sctp_ulpevent *event;
 	struct sctp_bind_hashbucket *head;
-	int flags = 0;
 
 	/* Migrate socket buffer sizes and all the socket level options to the
 	 * new socket.
@@ -6356,15 +6355,8 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
 	/* Copy the bind_addr list from the original endpoint to the new
 	 * endpoint so that we can handle restarts properly
 	 */
-	if (PF_INET6 == assoc->base.sk->sk_family)
-		flags = SCTP_ADDR6_ALLOWED;
-	if (assoc->peer.ipv4_address)
-		flags |= SCTP_ADDR4_PEERSUPP;
-	if (assoc->peer.ipv6_address)
-		flags |= SCTP_ADDR6_PEERSUPP;
-	sctp_bind_addr_copy(&newsp->ep->base.bind_addr,
-			     &oldsp->ep->base.bind_addr,
-			     SCTP_SCOPE_GLOBAL, GFP_KERNEL, flags);
+	sctp_bind_addr_dup(&newsp->ep->base.bind_addr,
+				&oldsp->ep->base.bind_addr, GFP_KERNEL);
 
 	/* Move any messages in the old socket's receive queue that are for the
 	 * peeled off association to the new socket's receive queue.
-- 
1.5.3.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [SCTP] Bug fixes to the migrate/accept code path.
  2007-12-06 17:48 [SCTP] Bug fixes to the migrate/accept code path Vlad Yasevich
  2007-12-06 17:48 ` [PATCH] SCTP: Add bind hash locking to the migrate code Vlad Yasevich
  2007-12-06 17:48 ` [PATCH] SCTP: Fix the bind_addr info during migration Vlad Yasevich
@ 2007-12-07  6:51 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2007-12-07  6:51 UTC (permalink / raw)
  To: vladislav.yasevich; +Cc: netdev, lksctp-developers

From: Vlad Yasevich <vladislav.yasevich@hp.com>
Date: Thu,  6 Dec 2007 12:48:22 -0500

> The following two patches fix some bugs in the SCTP accept code path.
> The first one fixes a slab corruption bug that we found during stress
> testing.  The second one is just a clean-up and the right way to do things.

Both patches applied to net-2.6, thanks Vlad!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-12-07  6:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-06 17:48 [SCTP] Bug fixes to the migrate/accept code path Vlad Yasevich
2007-12-06 17:48 ` [PATCH] SCTP: Add bind hash locking to the migrate code Vlad Yasevich
2007-12-06 17:48 ` [PATCH] SCTP: Fix the bind_addr info during migration Vlad Yasevich
2007-12-07  6:51 ` [SCTP] Bug fixes to the migrate/accept code path David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).