aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2016-08-10 17:36:01 -0400
committerDavid S. Miller <davem@davemloft.net>2016-08-15 00:07:20 -0400
commitc110486f6cb240f36ec143cad6628d52c071f529 (patch)
treec7b7e3033c55e91744c9271ffd37917ee78f6085
parentf8c46cb39079b7415ada1affc4631ae761d8b621 (diff)
proc: make proc entries inherit ownership from parent
There are certain parameters that belong to net namespace and that are exported in /proc. They should be controllable by the container's owner, but are currently owned by global root and thus not available. Let's change proc code to inherit ownership of parent entry, and when create per-ns "net" proc entry set it up as owned by container's owner. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--fs/proc/generic.c2
-rw-r--r--fs/proc/proc_net.c13
2 files changed, 15 insertions, 0 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index c633476616e0..bca66d83a765 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -390,6 +390,8 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
390 atomic_set(&ent->count, 1); 390 atomic_set(&ent->count, 1);
391 spin_lock_init(&ent->pde_unload_lock); 391 spin_lock_init(&ent->pde_unload_lock);
392 INIT_LIST_HEAD(&ent->pde_openers); 392 INIT_LIST_HEAD(&ent->pde_openers);
393 proc_set_user(ent, (*parent)->uid, (*parent)->gid);
394
393out: 395out:
394 return ent; 396 return ent;
395} 397}
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
index c8bbc68cdb05..7ae6b1da7cab 100644
--- a/fs/proc/proc_net.c
+++ b/fs/proc/proc_net.c
@@ -21,6 +21,7 @@
21#include <linux/bitops.h> 21#include <linux/bitops.h>
22#include <linux/mount.h> 22#include <linux/mount.h>
23#include <linux/nsproxy.h> 23#include <linux/nsproxy.h>
24#include <linux/uidgid.h>
24#include <net/net_namespace.h> 25#include <net/net_namespace.h>
25#include <linux/seq_file.h> 26#include <linux/seq_file.h>
26 27
@@ -185,6 +186,8 @@ const struct file_operations proc_net_operations = {
185static __net_init int proc_net_ns_init(struct net *net) 186static __net_init int proc_net_ns_init(struct net *net)
186{ 187{
187 struct proc_dir_entry *netd, *net_statd; 188 struct proc_dir_entry *netd, *net_statd;
189 kuid_t uid;
190 kgid_t gid;
188 int err; 191 int err;
189 192
190 err = -ENOMEM; 193 err = -ENOMEM;
@@ -199,6 +202,16 @@ static __net_init int proc_net_ns_init(struct net *net)
199 netd->parent = &proc_root; 202 netd->parent = &proc_root;
200 memcpy(netd->name, "net", 4); 203 memcpy(netd->name, "net", 4);
201 204
205 uid = make_kuid(net->user_ns, 0);
206 if (!uid_valid(uid))
207 uid = netd->uid;
208
209 gid = make_kgid(net->user_ns, 0);
210 if (!gid_valid(gid))
211 gid = netd->gid;
212
213 proc_set_user(netd, uid, gid);
214
202 err = -EEXIST; 215 err = -EEXIST;
203 net_statd = proc_net_mkdir(net, "stat", netd); 216 net_statd = proc_net_mkdir(net, "stat", netd);
204 if (!net_statd) 217 if (!net_statd)