netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ip: Do not allow connection to remote port zero
@ 2015-02-12  0:58 Tom Marshall
  2015-02-12  4:06 ` Eric Dumazet
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Marshall @ 2015-02-12  0:58 UTC (permalink / raw)
  To: netdev

Port zero is reserved according to IANA.

Note UDP sendto is already disallowed if dport is zero.

Signed-off-by: Tom Marshall <tom@cyngn.com>
---
 net/ipv4/datagram.c | 3 +++
 net/ipv4/tcp_ipv4.c | 3 +++
 net/ipv6/datagram.c | 3 +++
 net/ipv6/tcp_ipv6.c | 3 +++
 4 files changed, 12 insertions(+)

diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c
index 90c0e83..e732382 100644
--- a/net/ipv4/datagram.c
+++ b/net/ipv4/datagram.c
@@ -37,6 +37,9 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 	if (usin->sin_family != AF_INET)
 		return -EAFNOSUPPORT;
 
+	if (!usin->sin_port)
+		return -EINVAL;
+
 	sk_dst_reset(sk);
 
 	lock_sock(sk);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index d22f544..fef2f9f 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -156,6 +156,9 @@ int tcp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 	if (usin->sin_family != AF_INET)
 		return -EAFNOSUPPORT;
 
+	if (!usin->sin_port)
+		return -EINVAL;
+
 	nexthop = daddr = usin->sin_addr.s_addr;
 	inet_opt = rcu_dereference_protected(inet->inet_opt,
 					     sock_owned_by_user(sk));
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index 49f5e73..fb6934e 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -66,6 +66,9 @@ int ip6_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
 	if (usin->sin6_family != AF_INET6)
 		return -EAFNOSUPPORT;
 
+	if (!usin->sin6_port)
+		return -EINVAL;
+
 	memset(&fl6, 0, sizeof(fl6));
 	if (np->sndflow) {
 		fl6.flowlabel = usin->sin6_flowinfo&IPV6_FLOWINFO_MASK;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 9c0b54e..1ae8bf1 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -146,6 +146,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
 	if (usin->sin6_family != AF_INET6)
 		return -EAFNOSUPPORT;
 
+	if (!usin->sin6_port)
+		return -EINVAL;
+
 	memset(&fl6, 0, sizeof(fl6));
 
 	if (np->sndflow) {
-- 
2.1.4

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

end of thread, other threads:[~2015-02-12 16:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-12  0:58 [PATCH] net: ip: Do not allow connection to remote port zero Tom Marshall
2015-02-12  4:06 ` Eric Dumazet
2015-02-12  5:24   ` Tom Marshall
2015-02-12  6:23     ` Tom Marshall
2015-02-12 13:54       ` Sergei Shtylyov
2015-02-12 15:34         ` Tom Marshall
2015-02-12 16:21     ` Eric Dumazet

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).