All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maciej Żenczykowski" <zenczykowski@gmail.com>
To: "Maciej Żenczykowski" <maze@google.com>,
	"David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, Sean Tranchetti <stranche@codeaurora.org>,
	Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>,
	Eric Dumazet <edumazet@google.com>
Subject: [PATCH 3/3] net: Fail explicit unprivileged bind to local reserved ports
Date: Thu, 21 Nov 2019 23:21:02 -0800	[thread overview]
Message-ID: <20191122072102.248636-3-zenczykowski@gmail.com> (raw)
In-Reply-To: <20191122072102.248636-1-zenczykowski@gmail.com>

From: Maciej Żenczykowski <maze@google.com>

Reserved ports may have some special use cases which are not suitable for
use by general userspace applications. Currently, ports specified in
ip_local_reserved_ports sysctl will not be returned only in case of automatic
port assignment.

It is desirable to prevent the host from assigning the ports even in case
of explicit binds to processes without CAP_NET_BIND_SERVICE (which
hopefully know what they're doing).

Example use cases might be:
 - a port being stolen by the nic for remote serial console,
   or some other sort of debugging functionality (crash collection, gdb,
   direct access to some other microcontroller on the nic or motherboard).
 - a transparent proxy where packets are being redirected: in case a socket
   matches this connection, packets from this application would be incorrectly
   sent to one of the endpoints.

Cc: Sean Tranchetti <stranche@codeaurora.org>
Cc: Subash Abhinov Kasiviswanathan <subashab@codeaurora.org>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
 include/net/ip.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/net/ip.h b/include/net/ip.h
index a92f157bb115..f00e00d15155 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -353,7 +353,8 @@ static inline bool sysctl_dev_name_is_allowed(const char *name)
 
 static inline bool inet_port_requires_bind_service(struct net *net, int port)
 {
-	return port < net->ipv4.sysctl_ip_prot_sock;
+	return port < net->ipv4.sysctl_ip_prot_sock ||
+		inet_is_local_reserved_port(net, port);
 }
 
 #else
-- 
2.24.0.432.g9d3f5f5b63-goog


  parent reply	other threads:[~2019-11-22  7:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22  7:21 [PATCH 1/3] net: inet_is_local_reserved_port() should return bool not int Maciej Żenczykowski
2019-11-22  7:21 ` [PATCH 2/3] net: port < inet_prot_sock(net) --> inet_port_requires_bind_service(net, port) Maciej Żenczykowski
2019-11-22  7:21 ` Maciej Żenczykowski [this message]
2019-11-22 18:06 ` [PATCH 1/3] net: inet_is_local_reserved_port() should return bool not int David Miller
2019-11-22 21:48   ` Maciej Żenczykowski
2019-11-22 21:50     ` [PATCH] " Maciej Żenczykowski
2019-11-23  0:55       ` Jakub Kicinski
2019-11-23  3:31         ` Maciej Żenczykowski
2019-11-24  9:24     ` [PATCH 1/3] " Maciej Żenczykowski
2019-11-24  9:27       ` [PATCH] net: port < inet_prot_sock(net) --> inet_port_requires_bind_service(net, port) Maciej Żenczykowski
2019-11-25 22:45         ` David Miller
2019-11-25 23:32           ` Maciej Żenczykowski
2019-11-25 23:37             ` [PATCH v2] " Maciej Żenczykowski
2019-11-26 21:20               ` David 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=20191122072102.248636-3-zenczykowski@gmail.com \
    --to=zenczykowski@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=maze@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=stranche@codeaurora.org \
    --cc=subashab@codeaurora.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 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.