netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Marshall <tom@cyngn.com>
To: netdev@vger.kernel.org
Subject: [PATCH] net: ip: Do not allow connection to remote port zero
Date: Wed, 11 Feb 2015 16:58:45 -0800	[thread overview]
Message-ID: <20150212005844.GB3829@nwwn.com> (raw)

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

             reply	other threads:[~2015-02-12  0:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-12  0:58 Tom Marshall [this message]
2015-02-12  4:06 ` [PATCH] net: ip: Do not allow connection to remote port zero 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

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=20150212005844.GB3829@nwwn.com \
    --to=tom@cyngn.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).