From: Pavel Emelyanov <xemul@openvz.org>
To: David Miller <davem@davemloft.net>
Cc: Linux Netdev List <netdev@vger.kernel.org>
Subject: [PATCH net-2.6.26 4/5][SYSCTL]: Create the net sysctl root for RO tables.
Date: Tue, 19 Feb 2008 15:02:23 +0300 [thread overview]
Message-ID: <47BAC54F.2030605@openvz.org> (raw)
In-Reply-To: <47BAC38F.10100@openvz.org>
This root keeps ctl tables in one global list, but doesn't allow
for non-init namespaces to write into tables, stored in it.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
include/net/net_namespace.h | 2 ++
net/sysctl_net.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
index 28738b7..2930ae3 100644
--- a/include/net/net_namespace.h
+++ b/include/net/net_namespace.h
@@ -173,6 +173,8 @@ struct ctl_table;
struct ctl_table_header;
extern struct ctl_table_header *register_net_sysctl_table(struct net *net,
const struct ctl_path *path, struct ctl_table *table);
+extern struct ctl_table_header *register_init_net_ctl_table(
+ struct ctl_path *path, struct ctl_table *table);
extern void unregister_net_sysctl_table(struct ctl_table_header *header);
#endif /* __NET_NET_NAMESPACE_H */
diff --git a/net/sysctl_net.c b/net/sysctl_net.c
index 665e856..42c99e6 100644
--- a/net/sysctl_net.c
+++ b/net/sysctl_net.c
@@ -40,6 +40,30 @@ static struct ctl_table_root net_sysctl_root = {
.lookup = net_ctl_header_lookup,
};
+static LIST_HEAD(net_ro_headers);
+
+static struct list_head *net_ctl_ro_header_lookup(struct ctl_table_root *root,
+ struct nsproxy *namespaces)
+{
+ return &net_ro_headers;
+}
+
+static int net_ctl_ro_permissions(struct ctl_table_root *root,
+ struct nsproxy *ns, struct ctl_table *table)
+{
+ int mode;
+
+ mode = table->mode;
+ if (ns->net_ns != &init_net)
+ mode &= ~0222;
+ return mode;
+}
+
+static struct ctl_table_root net_sysctl_ro_root = {
+ .lookup = net_ctl_ro_header_lookup,
+ .permissions = net_ctl_ro_permissions,
+};
+
static int sysctl_net_init(struct net *net)
{
INIT_LIST_HEAD(&net->sysctl_table_headers);
@@ -64,6 +88,7 @@ static __init int sysctl_init(void)
if (ret)
goto out;
register_sysctl_root(&net_sysctl_root);
+ register_sysctl_root(&net_sysctl_ro_root);
out:
return ret;
}
@@ -80,6 +105,14 @@ struct ctl_table_header *register_net_sysctl_table(struct net *net,
}
EXPORT_SYMBOL_GPL(register_net_sysctl_table);
+struct ctl_table_header *register_init_net_ctl_table(struct ctl_path *path,
+ struct ctl_table *table)
+{
+ return __register_sysctl_paths(&net_sysctl_ro_root,
+ &init_nsproxy, path, table);
+}
+EXPORT_SYMBOL_GPL(register_net_ro_ctl_table);
+
void unregister_net_sysctl_table(struct ctl_table_header *header)
{
return unregister_sysctl_table(header);
--
1.5.3.4
next prev parent reply other threads:[~2008-02-19 12:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-19 11:54 [PATCH net-2.6.26 0/5][SYSCTL]: Make some sysctl RO in net namespaces Pavel Emelyanov
2008-02-19 11:56 ` [PATCH net-2.6.26 1/5][SYSCTL]: Merge equal code in sysctl proc handlers Pavel Emelyanov
2008-02-19 11:58 ` [PATCH net-2.6.26 2/5][SYSCTL]: Clean sysctls from unneeded extern and forward declarations Pavel Emelyanov
2008-02-19 12:00 ` [PATCH net-2.6.26 3/5][SYSCTL]: Add the ->permissions callback on the ctl_table_root Pavel Emelyanov
2008-02-19 12:02 ` Pavel Emelyanov [this message]
2008-02-19 12:05 ` [PATCH net-2.6.26 5/5][SYSCTL]: Move some net.core sysctls to RO root Pavel Emelyanov
2008-02-27 7:10 ` [PATCH net-2.6.26 0/5][SYSCTL]: Make some sysctl RO in net namespaces 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=47BAC54F.2030605@openvz.org \
--to=xemul@openvz.org \
--cc=davem@davemloft.net \
--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).