* [PATCH net 1/1] inet: fix sysctl_local_ports init when namespaces are used
@ 2014-05-06 5:53 Francois Romieu
2014-05-06 17:55 ` Cong Wang
0 siblings, 1 reply; 4+ messages in thread
From: Francois Romieu @ 2014-05-06 5:53 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Stefan de Konink, Daniel Borkmann, Stephen Hemminger
Bug: https://bugzilla.kernel.org/show_bug.cgi?id=75221
Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
Reported-by: Stefan de Konink <stefan@konink.de>
Tested-by: Stefan de Konink <stefan@konink.de>
---
net/ipv4/af_inet.c | 36 +++++++++++++++++++++++++++++++-----
net/ipv4/sysctl_net_ipv4.c | 14 --------------
2 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 8c54870..9ee66e2 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1629,7 +1629,33 @@ err_tcp_mib:
return -ENOMEM;
}
-static __net_exit void ipv4_mib_exit_net(struct net *net)
+static __net_init int inet4_net_init(struct net *net)
+{
+ struct netns_ipv4 *nip4 = &net->ipv4;
+ int rc;
+
+ rc = ipv4_mib_init_net(net);
+ if (rc < 0)
+ return rc;
+
+ /*
+ * Sane defaults - nobody may create ping sockets.
+ * Boot scripts should set this to distro-specific group.
+ */
+ nip4->sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
+ nip4->sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
+
+ /*
+ * Set defaults for local port range
+ */
+ seqlock_init(&nip4->sysctl_local_ports.lock);
+ nip4->sysctl_local_ports.range[0] = 32768;
+ nip4->sysctl_local_ports.range[1] = 61000;
+
+ return rc;
+}
+
+static __net_exit void inet4_net_exit(struct net *net)
{
kfree(net->mib.icmpmsg_statistics);
snmp_mib_free((void __percpu **)net->mib.icmp_statistics);
@@ -1640,14 +1666,14 @@ static __net_exit void ipv4_mib_exit_net(struct net *net)
snmp_mib_free((void __percpu **)net->mib.tcp_statistics);
}
-static __net_initdata struct pernet_operations ipv4_mib_ops = {
- .init = ipv4_mib_init_net,
- .exit = ipv4_mib_exit_net,
+static __net_initdata struct pernet_operations inet4_net_ops = {
+ .init = inet4_net_init,
+ .exit = inet4_net_exit,
};
static int __init init_ipv4_mibs(void)
{
- return register_pernet_subsys(&ipv4_mib_ops);
+ return register_pernet_subsys(&inet4_net_ops);
}
static int ipv4_proc_init(void);
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 44eba05..24c0e4e 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -858,20 +858,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
table[i].data += (void *)net - (void *)&init_net;
}
- /*
- * Sane defaults - nobody may create ping sockets.
- * Boot scripts should set this to distro-specific group.
- */
- net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
- net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
-
- /*
- * Set defaults for local port range
- */
- seqlock_init(&net->ipv4.sysctl_local_ports.lock);
- net->ipv4.sysctl_local_ports.range[0] = 32768;
- net->ipv4.sysctl_local_ports.range[1] = 61000;
-
net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
if (net->ipv4.ipv4_hdr == NULL)
goto err_reg;
--
1.9.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/1] inet: fix sysctl_local_ports init when namespaces are used
2014-05-06 5:53 [PATCH net 1/1] inet: fix sysctl_local_ports init when namespaces are used Francois Romieu
@ 2014-05-06 17:55 ` Cong Wang
2014-05-06 22:51 ` Francois Romieu
0 siblings, 1 reply; 4+ messages in thread
From: Cong Wang @ 2014-05-06 17:55 UTC (permalink / raw)
To: Francois Romieu
Cc: David Miller, netdev, Stefan de Konink, Daniel Borkmann,
Stephen Hemminger
[-- Attachment #1: Type: text/plain, Size: 497 bytes --]
On Mon, May 5, 2014 at 10:53 PM, Francois Romieu <romieu@fr.zoreil.com> wrote:
> Bug: https://bugzilla.kernel.org/show_bug.cgi?id=75221
>
Well, $subject sucks, it only fixes !CONFIG_PROC_SYSCTL case actually...
> Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
> Reported-by: Stefan de Konink <stefan@konink.de>
> Tested-by: Stefan de Konink <stefan@konink.de>
I had some better fixes pending (I already tested them, just waiting to submit).
You can try the attached patches if you want.
[-- Attachment #2: 0001-ipv4-move-local_port_range-out-of-CONFIG_SYSCTL.patch --]
[-- Type: text/x-patch, Size: 6814 bytes --]
From 7393f959091fd84b8bbe8a100693eb173db7c784 Mon Sep 17 00:00:00 2001
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Fri, 2 May 2014 14:01:25 -0700
Subject: [PATCH] ipv4: move local_port_range out of CONFIG_SYSCTL
When CONFIG_SYSCTL is not set, ip_local_port_range should still work,
just that no one can change it. Therefore we should move it out of sysctl_inet.c.
Also, rename it to ->ip_local_ports instead.
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
include/net/netns/ipv4.h | 2 +-
net/ipv4/af_inet.c | 28 ++++++++++++++++++++++++++++
net/ipv4/inet_connection_sock.c | 8 ++++----
net/ipv4/ping.c | 4 ++--
net/ipv4/sysctl_net_ipv4.c | 29 +++++++++++------------------
5 files changed, 46 insertions(+), 25 deletions(-)
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 80f500a..3d95cd4 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -66,7 +66,7 @@ struct netns_ipv4 {
int sysctl_icmp_ratemask;
int sysctl_icmp_errors_use_inbound_ifaddr;
- struct local_ports sysctl_local_ports;
+ struct local_ports ip_local_ports;
int sysctl_tcp_ecn;
int sysctl_ip_no_pmtu_disc;
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 8c54870..cccc8e4 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1650,6 +1650,31 @@ static int __init init_ipv4_mibs(void)
return register_pernet_subsys(&ipv4_mib_ops);
}
+static __net_init int inet_init_net(struct net *net)
+{
+ /*
+ * Set defaults for local port range
+ */
+ seqlock_init(&net->ipv4.ip_local_ports.lock);
+ net->ipv4.ip_local_ports.range[0] = 32768;
+ net->ipv4.ip_local_ports.range[1] = 61000;
+ return 0;
+}
+
+static __net_exit void inet_exit_net(struct net *net)
+{
+}
+
+static __net_initdata struct pernet_operations af_inet_ops = {
+ .init = inet_init_net,
+ .exit = inet_exit_net,
+};
+
+static int __init init_inet_pernet_ops(void)
+{
+ return register_pernet_subsys(&af_inet_ops);
+}
+
static int ipv4_proc_init(void);
/*
@@ -1794,6 +1819,9 @@ static int __init inet_init(void)
if (ip_mr_init())
pr_crit("%s: Cannot init ipv4 mroute\n", __func__);
#endif
+
+ if (init_inet_pernet_ops())
+ pr_crit("%s: Cannot init ipv4 inet pernet ops\n", __func__);
/*
* Initialise per-cpu ipv4 mibs
*/
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 0d1e2cb..a56b8e6 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -37,11 +37,11 @@ void inet_get_local_port_range(struct net *net, int *low, int *high)
unsigned int seq;
do {
- seq = read_seqbegin(&net->ipv4.sysctl_local_ports.lock);
+ seq = read_seqbegin(&net->ipv4.ip_local_ports.lock);
- *low = net->ipv4.sysctl_local_ports.range[0];
- *high = net->ipv4.sysctl_local_ports.range[1];
- } while (read_seqretry(&net->ipv4.sysctl_local_ports.lock, seq));
+ *low = net->ipv4.ip_local_ports.range[0];
+ *high = net->ipv4.ip_local_ports.range[1];
+ } while (read_seqretry(&net->ipv4.ip_local_ports.lock, seq));
}
EXPORT_SYMBOL(inet_get_local_port_range);
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 8210964..347bdde 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -240,11 +240,11 @@ static void inet_get_ping_group_range_net(struct net *net, kgid_t *low,
unsigned int seq;
do {
- seq = read_seqbegin(&net->ipv4.sysctl_local_ports.lock);
+ seq = read_seqbegin(&net->ipv4.ip_local_ports.lock);
*low = data[0];
*high = data[1];
- } while (read_seqretry(&net->ipv4.sysctl_local_ports.lock, seq));
+ } while (read_seqretry(&net->ipv4.ip_local_ports.lock, seq));
}
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index 44eba05..a116c41 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -45,10 +45,10 @@ static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
/* Update system visible IP port range */
static void set_local_port_range(struct net *net, int range[2])
{
- write_seqlock(&net->ipv4.sysctl_local_ports.lock);
- net->ipv4.sysctl_local_ports.range[0] = range[0];
- net->ipv4.sysctl_local_ports.range[1] = range[1];
- write_sequnlock(&net->ipv4.sysctl_local_ports.lock);
+ write_seqlock(&net->ipv4.ip_local_ports.lock);
+ net->ipv4.ip_local_ports.range[0] = range[0];
+ net->ipv4.ip_local_ports.range[1] = range[1];
+ write_sequnlock(&net->ipv4.ip_local_ports.lock);
}
/* Validate changes from /proc interface. */
@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
size_t *lenp, loff_t *ppos)
{
struct net *net =
- container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
+ container_of(table->data, struct net, ipv4.ip_local_ports.range);
int ret;
int range[2];
struct ctl_table tmp = {
@@ -90,11 +90,11 @@ static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low
container_of(table->data, struct net, ipv4.sysctl_ping_group_range);
unsigned int seq;
do {
- seq = read_seqbegin(&net->ipv4.sysctl_local_ports.lock);
+ seq = read_seqbegin(&net->ipv4.ip_local_ports.lock);
*low = data[0];
*high = data[1];
- } while (read_seqretry(&net->ipv4.sysctl_local_ports.lock, seq));
+ } while (read_seqretry(&net->ipv4.ip_local_ports.lock, seq));
}
/* Update system visible IP port range */
@@ -103,10 +103,10 @@ static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t hig
kgid_t *data = table->data;
struct net *net =
container_of(table->data, struct net, ipv4.sysctl_ping_group_range);
- write_seqlock(&net->ipv4.sysctl_local_ports.lock);
+ write_seqlock(&net->ipv4.ip_local_ports.lock);
data[0] = low;
data[1] = high;
- write_sequnlock(&net->ipv4.sysctl_local_ports.lock);
+ write_sequnlock(&net->ipv4.ip_local_ports.lock);
}
/* Validate changes from /proc interface. */
@@ -819,8 +819,8 @@ static struct ctl_table ipv4_net_table[] = {
},
{
.procname = "ip_local_port_range",
- .maxlen = sizeof(init_net.ipv4.sysctl_local_ports.range),
- .data = &init_net.ipv4.sysctl_local_ports.range,
+ .maxlen = sizeof(init_net.ipv4.ip_local_ports.range),
+ .data = &init_net.ipv4.ip_local_ports.range,
.mode = 0644,
.proc_handler = ipv4_local_port_range,
},
@@ -865,13 +865,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
- /*
- * Set defaults for local port range
- */
- seqlock_init(&net->ipv4.sysctl_local_ports.lock);
- net->ipv4.sysctl_local_ports.range[0] = 32768;
- net->ipv4.sysctl_local_ports.range[1] = 61000;
-
net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
if (net->ipv4.ipv4_hdr == NULL)
goto err_reg;
--
1.8.3.1
[-- Attachment #3: 0002-ping-move-ping_group_range-out-of-CONFIG_SYSCTL.patch --]
[-- Type: text/x-patch, Size: 4478 bytes --]
From da2166dc426432bd4286ac1401f9a65534e9f88d Mon Sep 17 00:00:00 2001
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Fri, 2 May 2014 14:37:58 -0700
Subject: [PATCH] ping: move ping_group_range out of CONFIG_SYSCTL
Similarly, when CONFIG_SYSCTL is not set, ping_group_range should still
work, just that no one can change it. Therefore we should move it out of
sysctl_net_ipv4.c. And, it should not share the same seqlock with
ip_local_port_range.
BTW, rename it to ->ping_group_range instead.
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
include/net/netns/ipv4.h | 7 ++++++-
net/ipv4/af_inet.c | 8 ++++++++
net/ipv4/ping.c | 6 +++---
net/ipv4/sysctl_net_ipv4.c | 13 +++----------
4 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 3d95cd4..b2704fd0 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -20,6 +20,11 @@ struct local_ports {
int range[2];
};
+struct ping_group_range {
+ seqlock_t lock;
+ kgid_t range[2];
+};
+
struct netns_ipv4 {
#ifdef CONFIG_SYSCTL
struct ctl_table_header *forw_hdr;
@@ -72,7 +77,7 @@ struct netns_ipv4 {
int sysctl_ip_no_pmtu_disc;
int sysctl_ip_fwd_use_pmtu;
- kgid_t sysctl_ping_group_range[2];
+ struct ping_group_range ping_group_range;
atomic_t dev_addr_genid;
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index cccc8e4..6d6dd34 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1658,6 +1658,14 @@ static __net_init int inet_init_net(struct net *net)
seqlock_init(&net->ipv4.ip_local_ports.lock);
net->ipv4.ip_local_ports.range[0] = 32768;
net->ipv4.ip_local_ports.range[1] = 61000;
+
+ seqlock_init(&net->ipv4.ping_group_range.lock);
+ /*
+ * Sane defaults - nobody may create ping sockets.
+ * Boot scripts should set this to distro-specific group.
+ */
+ net->ipv4.ping_group_range.range[0] = make_kgid(&init_user_ns, 1);
+ net->ipv4.ping_group_range.range[1] = make_kgid(&init_user_ns, 0);
return 0;
}
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 347bdde..044a0dd 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -236,15 +236,15 @@ exit:
static void inet_get_ping_group_range_net(struct net *net, kgid_t *low,
kgid_t *high)
{
- kgid_t *data = net->ipv4.sysctl_ping_group_range;
+ kgid_t *data = net->ipv4.ping_group_range.range;
unsigned int seq;
do {
- seq = read_seqbegin(&net->ipv4.ip_local_ports.lock);
+ seq = read_seqbegin(&net->ipv4.ping_group_range.lock);
*low = data[0];
*high = data[1];
- } while (read_seqretry(&net->ipv4.ip_local_ports.lock, seq));
+ } while (read_seqretry(&net->ipv4.ping_group_range.lock, seq));
}
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index a116c41..5cde8f2 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -87,7 +87,7 @@ static void inet_get_ping_group_range_table(struct ctl_table *table, kgid_t *low
{
kgid_t *data = table->data;
struct net *net =
- container_of(table->data, struct net, ipv4.sysctl_ping_group_range);
+ container_of(table->data, struct net, ipv4.ping_group_range.range);
unsigned int seq;
do {
seq = read_seqbegin(&net->ipv4.ip_local_ports.lock);
@@ -102,7 +102,7 @@ static void set_ping_group_range(struct ctl_table *table, kgid_t low, kgid_t hig
{
kgid_t *data = table->data;
struct net *net =
- container_of(table->data, struct net, ipv4.sysctl_ping_group_range);
+ container_of(table->data, struct net, ipv4.ping_group_range.range);
write_seqlock(&net->ipv4.ip_local_ports.lock);
data[0] = low;
data[1] = high;
@@ -805,7 +805,7 @@ static struct ctl_table ipv4_net_table[] = {
},
{
.procname = "ping_group_range",
- .data = &init_net.ipv4.sysctl_ping_group_range,
+ .data = &init_net.ipv4.ping_group_range.range,
.maxlen = sizeof(gid_t)*2,
.mode = 0644,
.proc_handler = ipv4_ping_group_range,
@@ -858,13 +858,6 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
table[i].data += (void *)net - (void *)&init_net;
}
- /*
- * Sane defaults - nobody may create ping sockets.
- * Boot scripts should set this to distro-specific group.
- */
- net->ipv4.sysctl_ping_group_range[0] = make_kgid(&init_user_ns, 1);
- net->ipv4.sysctl_ping_group_range[1] = make_kgid(&init_user_ns, 0);
-
net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
if (net->ipv4.ipv4_hdr == NULL)
goto err_reg;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/1] inet: fix sysctl_local_ports init when namespaces are used
2014-05-06 17:55 ` Cong Wang
@ 2014-05-06 22:51 ` Francois Romieu
0 siblings, 0 replies; 4+ messages in thread
From: Francois Romieu @ 2014-05-06 22:51 UTC (permalink / raw)
To: Cong Wang
Cc: David Miller, netdev, Stefan de Konink, Daniel Borkmann,
Stephen Hemminger
Cong Wang <cwang@twopensource.com> :
> On Mon, May 5, 2014 at 10:53 PM, Francois Romieu <romieu@fr.zoreil.com> wrote:
> > Bug: https://bugzilla.kernel.org/show_bug.cgi?id=75221
> >
>
> Well, $subject sucks, it only fixes !CONFIG_PROC_SYSCTL case actually...
Sure. It says "fix something" though.
> > Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
> > Reported-by: Stefan de Konink <stefan@konink.de>
> > Tested-by: Stefan de Konink <stefan@konink.de>
>
> I had some better fixes pending (I already tested them, just waiting to
> submit).
Before ping patch (!CONFIG_PROC_SYSCTL): the ping group range is zero due
to kzalloc and friends.
After ping patch (!CONFIG_PROC_SYSCTL): the ping group range is disabled
and it can't be set afterwards.
It isn't exactly "still work" but it's a welcome improvement.
Feel free to submit formally so that davem can pick those up.
--
Ueimor
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/1] inet: fix sysctl_local_ports init when namespaces are used
[not found] <20140505222916.GA2299@electric-eye.fr.zoreil.com>
@ 2014-05-07 20:48 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2014-05-07 20:48 UTC (permalink / raw)
To: romieu; +Cc: netdev, stefan, dborkman, stephen
From: Francois Romieu <romieu@fr.zoreil.com>
Date: Tue, 6 May 2014 00:29:16 +0200
> Bug: https://bugzilla.kernel.org/show_bug.cgi?id=75221
Like Cong, I would have wanted a detailed commit log message explaining
the exact bug and why you fixed it the way you did.
It seems like Cong's patch deals with it in a different way but needs
a more formal submission so I'll mark all of this superceded.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-07 20:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-06 5:53 [PATCH net 1/1] inet: fix sysctl_local_ports init when namespaces are used Francois Romieu
2014-05-06 17:55 ` Cong Wang
2014-05-06 22:51 ` Francois Romieu
[not found] <20140505222916.GA2299@electric-eye.fr.zoreil.com>
2014-05-07 20:48 ` David Miller
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.