aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/af_inet.c
diff options
context:
space:
mode:
authorKrister Johansen <kjlx@templeofstupid.com>2017-01-20 20:49:11 -0500
committerDavid S. Miller <davem@davemloft.net>2017-01-24 12:10:51 -0500
commit4548b683b78137f8eadeb312b94e20bb0d4a7141 (patch)
tree8b285d141f533807625336c4524411bf31d48d9f /net/ipv4/af_inet.c
parentd140199af510ad4749dc5e38b7922135258ba5fd (diff)
Introduce a sysctl that modifies the value of PROT_SOCK.
Add net.ipv4.ip_unprivileged_port_start, which is a per namespace sysctl that denotes the first unprivileged inet port in the namespace. To disable all privileged ports set this to zero. It also checks for overlap with the local port range. The privileged and local range may not overlap. The use case for this change is to allow containerized processes to bind to priviliged ports, but prevent them from ever being allowed to modify their container's network configuration. The latter is accomplished by ensuring that the network namespace is not a child of the user namespace. This modification was needed to allow the container manager to disable a namespace's priviliged port restrictions without exposing control of the network namespace to processes in the user namespace. Signed-off-by: Krister Johansen <kjlx@templeofstupid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/af_inet.c')
-rw-r--r--net/ipv4/af_inet.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index aae410bb655a..28fe8da4e1ac 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -479,7 +479,7 @@ int inet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
479 479
480 snum = ntohs(addr->sin_port); 480 snum = ntohs(addr->sin_port);
481 err = -EACCES; 481 err = -EACCES;
482 if (snum && snum < PROT_SOCK && 482 if (snum && snum < inet_prot_sock(net) &&
483 !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE)) 483 !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
484 goto out; 484 goto out;
485 485
@@ -1700,6 +1700,9 @@ static __net_init int inet_init_net(struct net *net)
1700 net->ipv4.sysctl_ip_default_ttl = IPDEFTTL; 1700 net->ipv4.sysctl_ip_default_ttl = IPDEFTTL;
1701 net->ipv4.sysctl_ip_dynaddr = 0; 1701 net->ipv4.sysctl_ip_dynaddr = 0;
1702 net->ipv4.sysctl_ip_early_demux = 1; 1702 net->ipv4.sysctl_ip_early_demux = 1;
1703#ifdef CONFIG_SYSCTL
1704 net->ipv4.sysctl_ip_prot_sock = PROT_SOCK;
1705#endif
1703 1706
1704 return 0; 1707 return 0;
1705} 1708}