All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Phonet: fix race for port number in concurrent bind()
@ 2009-09-23 13:17 Rémi Denis-Courmont
  2009-09-23 13:17 ` [PATCH] Phonet: error on broadcast sending (unimplemented) Rémi Denis-Courmont
  2009-09-24 22:45 ` [PATCH] Phonet: fix race for port number in concurrent bind() David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Rémi Denis-Courmont @ 2009-09-23 13:17 UTC (permalink / raw)
  To: netdev; +Cc: Rémi Denis-Courmont

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Allocating a port number to a socket and hashing that socket shall be
an atomic operation with regards to other port allocation. Otherwise,
we could allocate a port that is already being allocated to another
socket.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/socket.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 7a4ee39..07aa9f0 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -113,6 +113,8 @@ void pn_sock_unhash(struct sock *sk)
 }
 EXPORT_SYMBOL(pn_sock_unhash);
 
+static DEFINE_MUTEX(port_mutex);
+
 static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
 {
 	struct sock *sk = sock->sk;
@@ -140,9 +142,11 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
 		err = -EINVAL; /* attempt to rebind */
 		goto out;
 	}
+	WARN_ON(sk_hashed(sk));
+	mutex_lock(&port_mutex);
 	err = sk->sk_prot->get_port(sk, pn_port(handle));
 	if (err)
-		goto out;
+		goto out_port;
 
 	/* get_port() sets the port, bind() sets the address if applicable */
 	pn->sobject = pn_object(saddr, pn_port(pn->sobject));
@@ -150,6 +154,8 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
 
 	/* Enable RX on the socket */
 	sk->sk_prot->hash(sk);
+out_port:
+	mutex_unlock(&port_mutex);
 out:
 	release_sock(sk);
 	return err;
@@ -357,8 +363,6 @@ const struct proto_ops phonet_stream_ops = {
 };
 EXPORT_SYMBOL(phonet_stream_ops);
 
-static DEFINE_MUTEX(port_mutex);
-
 /* allocate port for a socket */
 int pn_sock_get_port(struct sock *sk, unsigned short sport)
 {
@@ -370,9 +374,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
 
 	memset(&try_sa, 0, sizeof(struct sockaddr_pn));
 	try_sa.spn_family = AF_PHONET;
-
-	mutex_lock(&port_mutex);
-
+	WARN_ON(!mutex_is_locked(&port_mutex));
 	if (!sport) {
 		/* search free port */
 		int port, pmin, pmax;
@@ -401,8 +403,6 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
 		else
 			sock_put(tmpsk);
 	}
-	mutex_unlock(&port_mutex);
-
 	/* the port must be in use already */
 	return -EADDRINUSE;
 
-- 
1.6.0.4


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

* [PATCH] Phonet: error on broadcast sending (unimplemented)
  2009-09-23 13:17 [PATCH] Phonet: fix race for port number in concurrent bind() Rémi Denis-Courmont
@ 2009-09-23 13:17 ` Rémi Denis-Courmont
  2009-09-24 22:45   ` David Miller
  2009-09-24 22:45 ` [PATCH] Phonet: fix race for port number in concurrent bind() David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Rémi Denis-Courmont @ 2009-09-23 13:17 UTC (permalink / raw)
  To: netdev; +Cc: Rémi Denis-Courmont

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

If we ever implement this, then we can stop returning an error.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/linux/phonet.h |    1 +
 net/phonet/af_phonet.c |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/include/linux/phonet.h b/include/linux/phonet.h
index 1ef5a07..e5126cf 100644
--- a/include/linux/phonet.h
+++ b/include/linux/phonet.h
@@ -38,6 +38,7 @@
 #define PNPIPE_IFINDEX		2
 
 #define PNADDR_ANY		0
+#define PNADDR_BROADCAST	0xFC
 #define PNPORT_RESOURCE_ROUTING	0
 
 /* Values for PNPIPE_ENCAP option */
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index a662e62..f60c0c2 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -168,6 +168,12 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev,
 		goto drop;
 	}
 
+	/* Broadcast sending is not implemented */
+	if (pn_addr(dst) == PNADDR_BROADCAST) {
+		err = -EOPNOTSUPP;
+		goto drop;
+	}
+
 	skb_reset_transport_header(skb);
 	WARN_ON(skb_headroom(skb) & 1); /* HW assumes word alignment */
 	skb_push(skb, sizeof(struct phonethdr));
-- 
1.6.0.4


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

* Re: [PATCH] Phonet: error on broadcast sending (unimplemented)
  2009-09-23 13:17 ` [PATCH] Phonet: error on broadcast sending (unimplemented) Rémi Denis-Courmont
@ 2009-09-24 22:45   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2009-09-24 22:45 UTC (permalink / raw)
  To: remi; +Cc: netdev, remi.denis-courmont

From: Rémi Denis-Courmont <remi@remlab.net>
Date: Wed, 23 Sep 2009 16:17:11 +0300

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> If we ever implement this, then we can stop returning an error.
> 
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Applied.

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

* Re: [PATCH] Phonet: fix race for port number in concurrent bind()
  2009-09-23 13:17 [PATCH] Phonet: fix race for port number in concurrent bind() Rémi Denis-Courmont
  2009-09-23 13:17 ` [PATCH] Phonet: error on broadcast sending (unimplemented) Rémi Denis-Courmont
@ 2009-09-24 22:45 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2009-09-24 22:45 UTC (permalink / raw)
  To: remi; +Cc: netdev, remi.denis-courmont

From: Rémi Denis-Courmont <remi@remlab.net>
Date: Wed, 23 Sep 2009 16:17:10 +0300

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> Allocating a port number to a socket and hashing that socket shall be
> an atomic operation with regards to other port allocation. Otherwise,
> we could allocate a port that is already being allocated to another
> socket.
> 
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Applied.

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

end of thread, other threads:[~2009-09-24 22:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-23 13:17 [PATCH] Phonet: fix race for port number in concurrent bind() Rémi Denis-Courmont
2009-09-23 13:17 ` [PATCH] Phonet: error on broadcast sending (unimplemented) Rémi Denis-Courmont
2009-09-24 22:45   ` David Miller
2009-09-24 22:45 ` [PATCH] Phonet: fix race for port number in concurrent bind() David Miller

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.