Skip to content

Commit c110486

Browse files
dtordavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f8c46cb commit c110486

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

fs/proc/generic.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
390390
atomic_set(&ent->count, 1);
391391
spin_lock_init(&ent->pde_unload_lock);
392392
INIT_LIST_HEAD(&ent->pde_openers);
393+
proc_set_user(ent, (*parent)->uid, (*parent)->gid);
394+
393395
out:
394396
return ent;
395397
}

fs/proc/proc_net.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/bitops.h>
2222
#include <linux/mount.h>
2323
#include <linux/nsproxy.h>
24+
#include <linux/uidgid.h>
2425
#include <net/net_namespace.h>
2526
#include <linux/seq_file.h>
2627

@@ -185,6 +186,8 @@ const struct file_operations proc_net_operations = {
185186
static __net_init int proc_net_ns_init(struct net *net)
186187
{
187188
struct proc_dir_entry *netd, *net_statd;
189+
kuid_t uid;
190+
kgid_t gid;
188191
int err;
189192

190193
err = -ENOMEM;
@@ -199,6 +202,16 @@ static __net_init int proc_net_ns_init(struct net *net)
199202
netd->parent = &proc_root;
200203
memcpy(netd->name, "net", 4);
201204

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+
202215
err = -EEXIST;
203216
net_statd = proc_net_mkdir(net, "stat", netd);
204217
if (!net_statd)

0 commit comments

Comments
 (0)