aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2012-11-15 22:02:59 -0500
committerDavid S. Miller <davem@davemloft.net>2012-11-18 20:30:55 -0500
commit464dc801c76aa0db88e16e8f5f47c6879858b9b2 (patch)
treecfaf0f43f4ce50669f07031ec42062b4c9a7f985 /net/ipv4
parent73f7ef435934e952c1d70d83d69921ea5d1f6bd4 (diff)
net: Don't export sysctls to unprivileged users
In preparation for supporting the creation of network namespaces by unprivileged users, modify all of the per net sysctl exports and refuse to allow them to unprivileged users. This makes it safe for unprivileged users in general to access per net sysctls, and allows sysctls to be exported to unprivileged users on an individual basis as they are deemed safe. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/devinet.c8
-rw-r--r--net/ipv4/ip_fragment.c4
-rw-r--r--net/ipv4/route.c4
-rw-r--r--net/ipv4/sysctl_net_ipv4.c3
4 files changed, 19 insertions, 0 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index f6db227c1fd9..6e06e924ed99 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1815,6 +1815,10 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
1815 t->devinet_vars[i].extra2 = net; 1815 t->devinet_vars[i].extra2 = net;
1816 } 1816 }
1817 1817
1818 /* Don't export sysctls to unprivileged users */
1819 if (net->user_ns != &init_user_ns)
1820 t->devinet_vars[0].procname = NULL;
1821
1818 snprintf(path, sizeof(path), "net/ipv4/conf/%s", dev_name); 1822 snprintf(path, sizeof(path), "net/ipv4/conf/%s", dev_name);
1819 1823
1820 t->sysctl_header = register_net_sysctl(net, path, t->devinet_vars); 1824 t->sysctl_header = register_net_sysctl(net, path, t->devinet_vars);
@@ -1900,6 +1904,10 @@ static __net_init int devinet_init_net(struct net *net)
1900 tbl[0].data = &all->data[IPV4_DEVCONF_FORWARDING - 1]; 1904 tbl[0].data = &all->data[IPV4_DEVCONF_FORWARDING - 1];
1901 tbl[0].extra1 = all; 1905 tbl[0].extra1 = all;
1902 tbl[0].extra2 = net; 1906 tbl[0].extra2 = net;
1907
1908 /* Don't export sysctls to unprivileged users */
1909 if (net->user_ns != &init_user_ns)
1910 tbl[0].procname = NULL;
1903#endif 1911#endif
1904 } 1912 }
1905 1913
diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
index 448e68546827..1cf6a768cd53 100644
--- a/net/ipv4/ip_fragment.c
+++ b/net/ipv4/ip_fragment.c
@@ -802,6 +802,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
802 table[0].data = &net->ipv4.frags.high_thresh; 802 table[0].data = &net->ipv4.frags.high_thresh;
803 table[1].data = &net->ipv4.frags.low_thresh; 803 table[1].data = &net->ipv4.frags.low_thresh;
804 table[2].data = &net->ipv4.frags.timeout; 804 table[2].data = &net->ipv4.frags.timeout;
805
806 /* Don't export sysctls to unprivileged users */
807 if (net->user_ns != &init_user_ns)
808 table[0].procname = NULL;
805 } 809 }
806 810
807 hdr = register_net_sysctl(net, "net/ipv4", table); 811 hdr = register_net_sysctl(net, "net/ipv4", table);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index a8c651216fa6..5b58788db863 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2493,6 +2493,10 @@ static __net_init int sysctl_route_net_init(struct net *net)
2493 tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL); 2493 tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
2494 if (tbl == NULL) 2494 if (tbl == NULL)
2495 goto err_dup; 2495 goto err_dup;
2496
2497 /* Don't export sysctls to unprivileged users */
2498 if (net->user_ns != &init_user_ns)
2499 tbl[0].procname = NULL;
2496 } 2500 }
2497 tbl[0].extra1 = net; 2501 tbl[0].extra1 = net;
2498 2502
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 63d4eccc674d..d84400b65049 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -883,6 +883,9 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
883 table[6].data = 883 table[6].data =
884 &net->ipv4.sysctl_ping_group_range; 884 &net->ipv4.sysctl_ping_group_range;
885 885
886 /* Don't export sysctls to unprivileged users */
887 if (net->user_ns != &init_user_ns)
888 table[0].procname = NULL;
886 } 889 }
887 890
888 /* 891 /*