Skip to contentSkip to conversation

Fix /proc/net in presence of net namespaces

PATCH In review Pavel Emelyanov 3 participants 20 messages Feb 28, 2008 – Mar 5, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Fix /proc/net in presence of net namespaces

Current /proc/net is done with so called "shadows", but current implementation is broken and has little chances to get fixed.

The problem is that dentries subtree of /proc/net directory has fancy revalidation rules to make processes living in different net namespaces see different entries in /proc/net subtree, but currently, tasks see in the /proc/net subdir the contents of any other namespace, depending on who opened the file first.

The proposed fix is to turn /proc/net into a symlink, which behaves similar to /proc/self link - it points to .netns/<id> directory where the <id> is the id of net namespace, current task lives in.

# ls -l /proc/net
lrwxrwxrwx  1 root root 8 Feb 28 18:38 /proc/net -> .netns/0

The /proc/.netns dir contains subtrees for all the namespaces in the system:

# ls -l /proc/.netns/
total 0
dr-xr-xr-x  5 root root 0 Feb 28 18:39 0
dr-xr-xr-x  3 root root 0 Feb 28 18:39 1

To provide some security each /proc/.netns/<id> directory allows access to tasks that live in the owning namespace only (with the exception, that init_net tasks can see everything).

#1 lore raw

PATCH 1/2 Add an id to struct net

This is required to implement the /proc/net symlink, but can later be used to enhance networking hash functions - objects like sockets, fragments, twbuckets, etc should better be stored in different hash chains when they live in different namespaces.

Id generation is done via ida to handle the id overflowing.

---

include/net/net_namespace.h +1 -0
index 28738b7..8aedfd6 100644
@@ -26,6 +26,7 @@ struct net {
 	atomic_t		use_count;	/* To track references we
 						 * destroy on demand
 						 */
+	int			id;
 	struct list_head	list;		/* list of network namespaces */
 	struct work_struct	work;		/* work struct for freeing */
 
net/core/net_namespace.c +18 -1
index 7b66083..31b018a 100644
@@ -6,6 +6,7 @@
 #include <linux/delay.h>
 #include <linux/sched.h>
 #include <net/net_namespace.h>
+#include <linux/idr.h>
 
 /*
  *	Our network namespace constructor/destructor lists
@@ -20,6 +21,8 @@ LIST_HEAD(net_namespace_list);
 struct net init_net;
 EXPORT_SYMBOL(init_net);
 
+static struct ida net_ns_ids;
+
 /*
  * setup_net runs the initializers for the network namespace object.
  */
@@ -31,8 +34,17 @@ static __net_init int setup_net(struct net *net)
 
 	atomic_set(&net->count, 1);
 	atomic_set(&net->use_count, 0);
+retry:
+	error = ida_get_new(&net_ns_ids, &net->id);
+	if (error) {
+		if (error == -EAGAIN) {
+			ida_pre_get(&net_ns_ids, GFP_KERNEL);
+			goto retry;
+		}
+
+		goto out;
+	}
 
-	error = 0;
 	list_for_each_entry(ops, &pernet_list, list) {
 		if (ops->init) {
 			error = ops->init(net);
@@ -53,6 +65,8 @@ out_undo:
 	}
 
 	rcu_barrier();
+
+	ida_remove(&net_ns_ids, net->id);
 	goto out;
 }
 
@@ -142,6 +156,7 @@ static void cleanup_net(struct work_struct *work)
 	 */
 	rcu_barrier();
 
+	ida_remove(&net_ns_ids, net->id);
 	/* Finally it is safe to free my network namespace structure */
 	net_free(net);
 }
@@ -179,6 +194,8 @@ static int __init net_ns_init(void)
 		panic("Could not create netns workq");
 #endif
 
+	ida_init(&net_ns_ids);
+
 	mutex_lock(&net_mutex);
 	err = setup_net(&init_net);
 
#2 lore raw

PATCH 2/2 Make /proc/net a symlink and drop proc shadows

In reply to Pavel Emelyanov

Turn /proc/net into a symlink, which behaves similar to /proc/self link - it points to .netns/<id> directory where the <id> is the id of net namespace, current task lives in.

# ls -l /proc/net
lrwxrwxrwx  1 root root 8 Feb 28 18:38 /proc/net -> .netns/0

The /proc/.netns dir contains subtrees for all the namespaces in the system:

# ls -l /proc/.netns/
total 0
dr-xr-xr-x  5 root root 0 Feb 28 18:39 0
dr-xr-xr-x  3 root root 0 Feb 28 18:39 1

To provide some security each /proc/.netns/<id> directory allows access to tasks that live in the owning namespace only (with the exception, that init_net tasks can see everything).

---

fs/proc/generic.c +2 -4
index 68971e6..d4103e5 100644
@@ -227,7 +227,7 @@ static const struct file_operations proc_file_operations = {
 	.write		= proc_file_write,
 };
 
-static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)
+int proc_notify_change(struct dentry *dentry, struct iattr *iattr)
 {
 	struct inode *inode = dentry->d_inode;
 	struct proc_dir_entry *de = PDE(inode);
@@ -248,7 +248,7 @@ out:
 	return error;
 }
 
-static int proc_getattr(struct vfsmount *mnt, struct dentry *dentry,
+int proc_getattr(struct vfsmount *mnt, struct dentry *dentry,
 			struct kstat *stat)
 {
 	struct inode *inode = dentry->d_inode;
@@ -393,8 +393,6 @@ struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry, struct nam
 			if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
 				unsigned int ino;
 
-				if (de->shadow_proc)
-					de = de->shadow_proc(current, de);
 				ino = de->low_ino;
 				de_get(de);
 				spin_unlock(&proc_subdir_lock);
fs/proc/proc_net.c +64 -32

135 lines not on this page · raw message

include/linux/proc_fs.h +3 -1
index d9a9e71..be0c9b7 100644
@@ -82,7 +82,6 @@ struct proc_dir_entry {
 	int pde_users;	/* number of callers into module in progress */
 	spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
 	struct completion *pde_unload_completion;
-	shadow_proc_t *shadow_proc;
 };
 
 struct kcore_list {
@@ -145,6 +144,9 @@ extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct p
  */
 extern int proc_readdir(struct file *, void *, filldir_t);
 extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);
+extern int proc_getattr(struct vfsmount *mnt, struct dentry *dentry,
+			struct kstat *stat);
+extern int proc_notify_change(struct dentry *dentry, struct iattr *iattr);
 
 extern const struct file_operations proc_kcore_operations;
 extern const struct file_operations proc_kmsg_operations;
include/net/net_namespace.h +0 -1
index 28738b7..8aedfd6 100644
@@ -32,7 +32,6 @@ struct net {
 
 	struct proc_dir_entry 	*proc_net;
 	struct proc_dir_entry 	*proc_net_stat;
-	struct proc_dir_entry 	*proc_net_root;
 
 	struct list_head	sysctl_table_headers;
 
#3 lore raw
In reply to Pavel Emelyanov
Quoted 19 lines · Pavel Emelyanov

Current /proc/net is done with so called "shadows", but current implementation is broken and has little chances to get fixed.

The problem is that dentries subtree of /proc/net directory has fancy revalidation rules to make processes living in different net namespaces see different entries in /proc/net subtree, but currently, tasks see in the /proc/net subdir the contents of any other namespace, depending on who opened the file first.

The proposed fix is to turn /proc/net into a symlink, which behaves similar to /proc/self link - it points to .netns/<id> directory where the <id> is the id of net namespace, current task lives in.

# ls -l /proc/net
lrwxrwxrwx  1 root root 8 Feb 28 18:38 /proc/net -> .netns/0

The /proc/.netns dir contains subtrees for all the namespaces in the system:

Quoted 8 lines
# ls -l /proc/.netns/
total 0
dr-xr-xr-x  5 root root 0 Feb 28 18:39 0
dr-xr-xr-x  3 root root 0 Feb 28 18:39 1

To provide some security each /proc/.netns/<id> directory allows access to tasks that live in the owning namespace only (with the exception, that init_net tasks can see everything).

Nack. Yet another global set of ids that require us to implement another namespace looks like the wrong way to go.

Can you try this approach by capturing a struct pid instead of an id in a new global namespace?

In particular the pid of the process that creates the pid namespace. Like we do with setsid.

I think the implementation difficulty should be about the same, but it will allow us something that works cleanly in the cases of migration and nested namespaces. As well as not adding an unnecessary special case with init_net and visibility.

Eric

#4 lore raw
Quoted 26 lines · Eric W. Biederman
Quoted 24 lines · Pavel Emelyanov

Current /proc/net is done with so called "shadows", but current implementation is broken and has little chances to get fixed.

The problem is that dentries subtree of /proc/net directory has fancy revalidation rules to make processes living in different net namespaces see different entries in /proc/net subtree, but currently, tasks see in the /proc/net subdir the contents of any other namespace, depending on who opened the file first.

The proposed fix is to turn /proc/net into a symlink, which behaves similar to /proc/self link - it points to .netns/<id> directory where the <id> is the id of net namespace, current task lives in.

# ls -l /proc/net
lrwxrwxrwx  1 root root 8 Feb 28 18:38 /proc/net -> .netns/0

The /proc/.netns dir contains subtrees for all the namespaces in the system:

# ls -l /proc/.netns/
total 0
dr-xr-xr-x  5 root root 0 Feb 28 18:39 0
dr-xr-xr-x  3 root root 0 Feb 28 18:39 1
Quoted 7 lines
Quoted 3 lines

To provide some security each /proc/.netns/<id> directory allows access to tasks that live in the owning namespace only (with the exception, that init_net tasks can see everything).

Nack. Yet another global set of ids that require us to implement another namespace looks like the wrong way to go.

Sentiment granted, but I'm not sure it can be an issue. It *could* be in issue if we moved to a more flexible access control here here any netns could access the .netns/N directories for all it's child namespaces.

But it can't, and /proc/net is set by the kernel. So the <id> can't be an issue for any checkpoint/restart except htat of the whole system, and of course on whole-system resume we have no <id> collision worries.

So userspace can't do anything with <id>, so there is no reason to worry about it becoming another namespace?

Right?

thanks,
-serge

Quoted 17 lines

Can you try this approach by capturing a struct pid instead of an id in a new global namespace?

In particular the pid of the process that creates the pid namespace. Like we do with setsid.

I think the implementation difficulty should be about the same, but it will allow us something that works cleanly in the cases of migration and nested namespaces. As well as not adding an unnecessary special case with init_net and visibility.

Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw
Quoted 32 lines · [email protected] writes:
Quoted 31 lines · Eric W. Biederman
Quoted 27 lines · Pavel Emelyanov

Current /proc/net is done with so called "shadows", but current implementation is broken and has little chances to get fixed.

The problem is that dentries subtree of /proc/net directory has fancy revalidation rules to make processes living in different net namespaces see different entries in /proc/net subtree, but currently, tasks see in the /proc/net subdir the contents of any other namespace, depending on who opened the file first.

The proposed fix is to turn /proc/net into a symlink, which behaves similar to /proc/self link - it points to .netns/<id> directory where the <id> is the id of net namespace, current task lives in.

# ls -l /proc/net
lrwxrwxrwx  1 root root 8 Feb 28 18:38 /proc/net -> .netns/0

The /proc/.netns dir contains subtrees for all the namespaces in the system:

# ls -l /proc/.netns/
total 0
dr-xr-xr-x  5 root root 0 Feb 28 18:39 0
dr-xr-xr-x  3 root root 0 Feb 28 18:39 1

To provide some security each /proc/.netns/<id> directory allows access to tasks that live in the owning namespace only (with the exception, that init_net tasks can see everything).

Quoted 7 lines
Quoted 2 lines

Nack. Yet another global set of ids that require us to implement another namespace looks like the wrong way to go.

Sentiment granted, but I'm not sure it can be an issue. It *could* be in issue if we moved to a more flexible access control here here any netns could access the .netns/N directories for all it's child namespaces.

However at least for visibility and inspection we want that. We want to inspect what is happening to other processes. If we didn't care then all of the pid namespaces could just be disjoint.

Providing interfaces where people can inspect what is going on through the filesystem is very natural, and a lot easier to support long term then adding a whole new set of interfaces for debuggers and the like.

Quoted 6 lines

But it can't, and /proc/net is set by the kernel. So the <id> can't be an issue for any checkpoint/restart except htat of the whole system, and of course on whole-system resume we have no <id> collision worries.

So userspace can't do anything with <id>, so there is no reason to worry about it becoming another namespace?

I was thinking we might be able to hide the existence of /proc/.netns/NNN/ however we can read the current working directory. So even if we only allow explicit access through /proc/net and all others paths don't work we have something that is visible.

So we really need something that we are not afraid to air in public. That we are not afraid to use and have it's use expanded upon.

Quoted 1 line

Right?

Think of user space processes inspecting /proc etc. Having directory names change out form under you for no apparent reason is pretty nasty.

Plus we have the consequence that a user space visible id is likely to get used for reporting in user space programs. Reporting that will go haywire on a migration event.

And if the id is used in reporting people are likely to want to use the id for control (so this may be the edge of a slippery slope).

Things like inode numbers that are a secondary effect are enough of a problem when looking at how things interact. A directly visible user space visible id is a problem.

All we need to do if we use a pid as an id is:
- Have one directory .netns with all of the net directories listed by pid.
- Have readdir and lookup filter the directory entries by the pid namespace of the proc mount.

It looks like we have to tweak things just a bit so that free_pid would not be called until the pid namespace goes away. Something similar to how we do the hash chains.

If we make namespaces show up anywhere besides under "/proc/<pid>/task/<tid>/" we have to do something like this, and pids are largely designed for this kind of use.

It looks like the way /proc is currently structured we don't need a reverse map from pid to net namespace. But I would not have a problem with that.

Our limitations are:
- We need an inviolate dentry tree of the VFS dcache goes nuts.
- We need an id that is in a namespace, or else we get pushed into the yet another namespace problem.
- We want to aim for minimal dentry duplication, to keep resource consumption under control. Which makes /proc/<pid>/task/<tid>/net an unfortunate choice.

So I think /proc/.netns/ or simply /proc/netns/ is a good choice. We just need a non-global id for our directory entries so we don't paint ourselves into a corner.

And honestly pid visibility is a very natural choice for which network namespaces you can see. You can see the namespace of any process you can see. Which especially means your children. It is an arbitrary rule, it is a simple rule to explain, and it works recursively unlike any init_net is special rule.

Eric

#6 lore raw
Quoted 37 lines · Eric W. Biederman
Quoted 35 lines · [email protected] writes:
Quoted 33 lines · Eric W. Biederman
Quoted 19 lines · Pavel Emelyanov

Current /proc/net is done with so called "shadows", but current implementation is broken and has little chances to get fixed.

The problem is that dentries subtree of /proc/net directory has fancy revalidation rules to make processes living in different net namespaces see different entries in /proc/net subtree, but currently, tasks see in the /proc/net subdir the contents of any other namespace, depending on who opened the file first.

The proposed fix is to turn /proc/net into a symlink, which behaves similar to /proc/self link - it points to .netns/<id> directory where the <id> is the id of net namespace, current task lives in.

# ls -l /proc/net
lrwxrwxrwx  1 root root 8 Feb 28 18:38 /proc/net -> .netns/0

The /proc/.netns dir contains subtrees for all the namespaces in the system:

Quoted 8 lines
# ls -l /proc/.netns/
total 0
dr-xr-xr-x  5 root root 0 Feb 28 18:39 0
dr-xr-xr-x  3 root root 0 Feb 28 18:39 1

To provide some security each /proc/.netns/<id> directory allows access to tasks that live in the owning namespace only (with the exception, that init_net tasks can see everything).

Nack. Yet another global set of ids that require us to implement another namespace looks like the wrong way to go.

Quoted 8 lines
Quoted 4 lines

Sentiment granted, but I'm not sure it can be an issue. It *could* be in issue if we moved to a more flexible access control here here any netns could access the .netns/N directories for all it's child namespaces.

However at least for visibility and inspection we want that. We want to inspect what is happening to other processes. If we didn't care then all of the pid namespaces could just be disjoint.

But the way Pavel has it coded, only tasks in the init namespace can view /proc/.net/* for any other net namespaces.

If you object to that (I'm undecided - though on a gut level I do prefer a simpler approach using bind mounts and not forcing any cross-ns access control this way) then the ids become relevant, but the way Pavel has it, it's just not.

Quoted 16 lines

Providing interfaces where people can inspect what is going on through the filesystem is very natural, and a lot easier to support long term then adding a whole new set of interfaces for debuggers and the like.

Quoted 6 lines

But it can't, and /proc/net is set by the kernel. So the <id> can't be an issue for any checkpoint/restart except htat of the whole system, and of course on whole-system resume we have no <id> collision worries.

So userspace can't do anything with <id>, so there is no reason to worry about it becoming another namespace?

I was thinking we might be able to hide the existence of /proc/.netns/NNN/ however we can read the current working directory. So even if we only allow explicit access through /proc/net and all others paths don't work we have something that is visible.

Quoted 6 lines

So we really need something that we are not afraid to air in public. That we are not afraid to use and have it's use expanded upon.

Quoted 1 line

Right?

Think of user space processes inspecting /proc etc.

Well a task in one pid namespace cannot view the /proc for another pid namespace, right?

Quoted 2 lines

Having directory
names change out form under you for no apparent reason is pretty nasty.

Yes, but they won't just 'change out' from under you, you ask for it... But here like I said I do prefer an approach where /proc/net is bind mounted by the user. But I have no good reason to back it up...

Quoted 7 lines

Plus we have the consequence that a user space visible id is likely to get used for reporting in user space programs. Reporting that will go haywire on a migration event.

And if the id is used in reporting people are likely to want to use the id for control (so this may be the edge of a slippery slope).

Quoted 6 lines

Things like inode numbers that are a secondary effect are enough of a problem when looking at how things interact. A directly visible user space visible id is a problem.

All we need to do if we use a pid as an id is:
- Have one directory .netns with all of the net directories listed by pid.

Which pid will be used? This .netns directory still is systemwide so these pids must (a) be globally unique and (b) be available (by your requirements :) upon a container restart so that the restarted process can re-use the same pid...

I don't see the advantage to using a pid.

Quoted 2 lines

- Have readdir and lookup filter the directory entries by the pid namespace of the proc mount.

Yuck, I far prefer to have userspace mount --bind /proc/.net/whatever to /proc/net rather than have the readdir and lookup do magic filtering.

Quoted 3 lines

It looks like we have to tweak things just a bit so that free_pid would not be called until the pid namespace goes away. Something similar to how we do the hash chains.

When you say pid are you talking about a pid_nr or a struct pid? In any case, I still don't see what makes it available for reuse on a restart...

And if not available for reuse on a restart, then we may as well use a simple global unique id as Pavel uses.

Quoted 16 lines

If we make namespaces show up anywhere besides under "/proc/<pid>/task/<tid>/" we have to do something like this, and pids are largely designed for this kind of use.

It looks like the way /proc is currently structured we don't need a reverse map from pid to net namespace. But I would not have a problem with that.

Our limitations are:
- We need an inviolate dentry tree of the VFS dcache goes nuts.
- We need an id that is in a namespace, or else we get pushed into the yet another namespace problem.
- We want to aim for minimal dentry duplication, to keep resource consumption under control. Which makes /proc/<pid>/task/<tid>/net an unfortunate choice.

Quoted 3 lines

So I think /proc/.netns/ or simply /proc/netns/ is a good choice. We just need a non-global id for our directory entries so we don't paint ourselves into a corner.

But I don't see how this is going to work. If you're using a pid_nr inside a pid namespace, then you're not guaranteeing that the pid_nr will be unique, so you may not be able to create th e/proc/.netns/X directory. If you're using the global pid, then you're not guaranteeing that it will be available upon a container restart.

Quoted 4 lines

And honestly pid visibility is a very natural choice for which network namespaces you can see. You can see the namespace of any process you can see. Which especially means your children. It is an arbitrary rule, it is a simple rule to explain, and it works recursively unlike

But apparently not simple enough for a simpleton like me to understand, sorry :(

Quoted 3 lines

any init_net is special rule.

Eric

#7 lore raw

[snip]

Quoted 6 lines
Quoted 3 lines

However at least for visibility and inspection we want that. We want to inspect what is happening to other processes. If we didn't care then all of the pid namespaces could just be disjoint.

But the way Pavel has it coded, only tasks in the init namespace can view /proc/.net/* for any other net namespaces.

This is not essential part of the patch :) I did so to make my life in init namespace easier. This part can be dropped.

[snip]

Quoted 4 lines
Quoted 1 line

Think of user space processes inspecting /proc etc.

Well a task in one pid namespace cannot view the /proc for another pid namespace, right?

No. Pid namespace provides another pid-to-task map, but have noting to do with VFS visibility.

Quoted 6 lines
Quoted 2 lines

Having directory
names change out form under you for no apparent reason is pretty nasty.

Yes, but they won't just 'change out' from under you, you ask for it... But here like I said I do prefer an approach where /proc/net is bind mounted by the user. But I have no good reason to back it up...

If you make /proc/net be a bund mount then you have to force all of the users to update their init scripts. I tried to make so with sysctl filesystem, but this thread was not very popular :)

Another way to do so - is to mount this one from inside the kernel, but are you ready to fight with Al Viro for this? :)

[snip]

Quoted 9 lines
Quoted 3 lines

So I think /proc/.netns/ or simply /proc/netns/ is a good choice. We just need a non-global id for our directory entries so we don't paint ourselves into a corner.

But I don't see how this is going to work. If you're using a pid_nr inside a pid namespace, then you're not guaranteeing that the pid_nr will be unique, so you may not be able to create th e/proc/.netns/X directory. If you're using the global pid, then you're not guaranteeing that it will be available upon a container restart.

Right - this is the same as using other ids, which I propose.

Quoted 12 lines
Quoted 4 lines

And honestly pid visibility is a very natural choice for which network namespaces you can see. You can see the namespace of any process you can see. Which especially means your children. It is an arbitrary rule, it is a simple rule to explain, and it works recursively unlike

But apparently not simple enough for a simpleton like me to understand, sorry :(

Quoted 3 lines

any init_net is special rule.

Eric

#8 lore raw
Quoted 25 lines · Pavel Emelyanov

[snip]

Quoted 6 lines
Quoted 3 lines

However at least for visibility and inspection we want that. We want to inspect what is happening to other processes. If we didn't care then all of the pid namespaces could just be disjoint.

But the way Pavel has it coded, only tasks in the init namespace can view /proc/.net/* for any other net namespaces.

This is not essential part of the patch :) I did so to make my life in init namespace easier. This part can be dropped.

[snip]

Quoted 4 lines
Quoted 1 line

Think of user space processes inspecting /proc etc.

Well a task in one pid namespace cannot view the /proc for another pid namespace, right?

No. Pid namespace provides another pid-to-task map, but have noting to do with VFS visibility.

Quoted 3 lines
Quoted 2 lines

Having directory
names change out form under you for no apparent reason is pretty nasty.

Quoted 7 lines
Quoted 3 lines

Yes, but they won't just 'change out' from under you, you ask for it... But here like I said I do prefer an approach where /proc/net is bind mounted by the user. But I have no good reason to back it up...

If you make /proc/net be a bund mount then you have to force all of the users to update their init scripts. I tried to make so with sysctl filesystem, but this thread was not very popular :)

Ok.

A symlink is far preferable to sneaky redirection imo.

Quoted 2 lines

Another way to do so - is to mount this one from inside the kernel, but are you ready to fight with Al Viro for this? :)

Nope :) Especially since it's an ugly idea.

Quoted 6 lines

[snip]

Quoted 4 lines
Quoted 3 lines

So I think /proc/.netns/ or simply /proc/netns/ is a good choice. We just need a non-global id for our directory entries so we don't paint ourselves into a corner.

Quoted 19 lines
Quoted 5 lines

But I don't see how this is going to work. If you're using a pid_nr inside a pid namespace, then you're not guaranteeing that the pid_nr will be unique, so you may not be able to create th e/proc/.netns/X directory. If you're using the global pid, then you're not guaranteeing that it will be available upon a container restart.

Right - this is the same as using other ids, which I propose.

Quoted 11 lines
Quoted 4 lines

And honestly pid visibility is a very natural choice for which network namespaces you can see. You can see the namespace of any process you can see. Which especially means your children. It is an arbitrary rule, it is a simple rule to explain, and it works recursively unlike

But apparently not simple enough for a simpleton like me to understand, sorry :(

Quoted 3 lines

any init_net is special rule.

Eric

I suspect I'm misunderstanding Eric's proposal, though.

-serge

#9 lore raw
In reply to Eric W. Biederman
Quoted 4 lines

I was thinking we might be able to hide the existence of /proc/.netns/NNN/ however we can read the current working directory. So even if we only allow explicit access through /proc/net and all others paths don't work we have something that is visible.

I have a patch that overrides the ->readdir method for /proc/.netns, so that you can no longer read the directory contents, but you still can guess one by guessing and opening files in it. Overriding the ->lookup to screw one up looks like "shadowing" technics.

OTOH - consider you have the ids of existing net namespaces, but cannot read the contents on any but yours. So what? This information is useless for you. So I dropped this part of a patch.

Quoted 7 lines

So we really need something that we are not afraid to air in public. That we are not afraid to use and have it's use expanded upon.

Quoted 1 line

Right?

Think of user space processes inspecting /proc etc. Having directory names change out form under you for no apparent reason is pretty nasty.

Have you ever bothered about /proc/<pid> change?

Quoted 7 lines

Plus we have the consequence that a user space visible id is likely to get used for reporting in user space programs. Reporting that will go haywire on a migration event.

And if the id is used in reporting people are likely to want to use the id for control (so this may be the edge of a slippery slope).

Quoted 6 lines

Things like inode numbers that are a secondary effect are enough of a problem when looking at how things interact. A directly visible user space visible id is a problem.

All we need to do if we use a pid as an id is:
- Have one directory .netns with all of the net directories listed by pid.

We have one now.

Quoted 2 lines

- Have readdir and lookup filter the directory entries by the pid namespace of the proc mount.

So, how are you going to filter the lookup? The problem I see - you have a process that opened the /proc/.netns/X directory (he onws that namespace) and the other one trying to do the same. The VFS layer finds the hashed dentry corresponding to this /proc/.netns/X. The only way you can prevent VFS from giving one to the second task is to override .d_revalidate method and drop that dentry....

But we've already tried to walk this way with no luck.

Quoted 3 lines

It looks like we have to tweak things just a bit so that free_pid would not be called until the pid namespace goes away. Something similar to how we do the hash chains.

This is not about pid namespace, this is about net namespace and tuning pids management to facilitate networking needs is not the right thing to do.

Quoted 3 lines

If we make namespaces show up anywhere besides under "/proc/<pid>/task/<tid>/" we have to do something like this, and pids are largely designed for this kind of use.

Proc consists of two parts - the <pid>-s one with generated-on-the-fly entries and the static one that is represented by proc_dir_entry tree. Do you propose to mix those two?

Quoted 12 lines

It looks like the way /proc is currently structured we don't need a reverse map from pid to net namespace. But I would not have a problem with that.

Our limitations are:
- We need an inviolate dentry tree of the VFS dcache goes nuts.
- We need an id that is in a namespace, or else we get pushed into the yet another namespace problem.
- We want to aim for minimal dentry duplication, to keep resource consumption under control. Which makes /proc/<pid>/task/<tid>/net an unfortunate choice.

Quoted 1 line

So I think /proc/.netns/ or simply /proc/netns/ is a good choice. We

Thanks.

Quoted 2 lines

just need a non-global id for our directory entries so we don't paint ourselves into a corner.

What namespace do you mean by "non-global"?

Quoted 8 lines

And honestly pid visibility is a very natural choice for which network namespaces you can see. You can see the namespace of any process you can see. Which especially means your children. It is an arbitrary rule, it is a simple rule to explain, and it works recursively unlike any init_net is special rule.

Eric

#10 lore raw

- The experience from vserver, planetlab and OpenVZ is that it is good to be able to monitor processes in other namespaces.

- The linux experience says filesystems are a good way to do that.

- So we really want to filesystem monitoring interfaces to depend on the filesystem mount options instead of current.

- Starting with making /proc and sysctls depend on current is a cheap way to get things up and going.

- When I consider breaking things up into multiple filesystems I run across the occasional file that depends on multiple namespaces. uids in /proc/sysvipc/* for example. Luckily I have yet to find any directory structures that depend on more then one namespace.

Maybe that can be handled properly by capturing multiple namespaces at mount time but I am a bit leery of that.

- The visibility of namespaces should be match the visibility of the
processes that use them. Access control of course can be more
restricted.

- We want to see how namespaces connect to tasks.

Therefore.

/proc/net, /proc/sys, /proc/sysvipc, and probably a few others should migrate under /proc/<pid>/task/<tid> (not under /proc/<pid> so we can finally straighten out the task group vs task issue).

Todays problem of course is /proc/net/

What I had intended to implement was:
/proc/current -> /proc/<pid>/task/<tid>
(A new symlink to the task directory)

/proc/net -> /proc/current/net
(like /proc/mounts)

The only downside of placing files under the task directory is that we use a lot more dentries for /proc.

....

Optimizations.

If the dentry pressure is significant and we don't have data from other namespaces in the files causing us to want to present the information differently for different processes I support using an id and a per namespace upper level directory. With a symlink into there from the task directories.

/proc/<pid>/task/<tid>/net -> ../../.../netns/<netns id>

The id I would use is a struct pid because that makes the id useful for userspace monitoring and control applications and because we can migrate it.

In my view /proc/netns/<pids> would be implemented like /proc/<pids> with readdir and lookup returning different contents based upon the pid namespace captured when we mounted proc.

Further struct pid would be enhanced so that as long as we have a namespace using a struct pid as an id we would not free that pid_nr in any of the pid namespaces. Just like we do with process groups and sessions today.

I think for the network namespace and network /proc files that optimization is safe. I seem to recall checking and not finding any ids from other namespaces in the files under /proc/net.

I will try for some more detailed replies.

Eric

#11 lore raw
In reply to Pavel Emelyanov
Quoted 9 lines · Pavel Emelyanov
Quoted 4 lines

I was thinking we might be able to hide the existence of /proc/.netns/NNN/ however we can read the current working directory. So even if we only allow explicit access through /proc/net and all others paths don't work we have something that is visible.

I have a patch that overrides the ->readdir method for /proc/.netns, so that you can no longer read the directory contents, but you still can guess one by guessing and opening files in it. Overriding the ->lookup to screw one up looks like "shadowing" technics.

Or looking at the symlinks under /proc/<pid>/fd/1 Or opening something under /proc/net/ and calling get pwd.

Quoted 3 lines

OTOH - consider you have the ids of existing net namespaces, but cannot read the contents on any but yours. So what? This information is useless for you. So I dropped this part of a patch.

However it is fundamental that monitoring programs want to inspect the namespaces of other processes.

In theory the resource group stuff was suppose to provide us with all of the names we would need. However the semantics seem a bit to flexible to use for something like this.

Quoted 11 lines
Quoted 2 lines

- Have readdir and lookup filter the directory entries by the pid namespace of the proc mount.

So, how are you going to filter the lookup? The problem I see - you have a process that opened the /proc/.netns/X directory (he onws that namespace) and the other one trying to do the same. The VFS layer finds the hashed dentry corresponding to this /proc/.netns/X. The only way you can prevent VFS from giving one to the second task is to override .d_revalidate method and drop that dentry....

But we've already tried to walk this way with no luck.

I meant a per mount filtering. Exactly like we do for the pids now.

Quoted 7 lines
Quoted 3 lines

It looks like we have to tweak things just a bit so that free_pid would not be called until the pid namespace goes away. Something similar to how we do the hash chains.

This is not about pid namespace, this is about net namespace and tuning pids management to facilitate networking needs is not the right thing to do.

Not exactly. It is about process attribute visibility. Which is what proc is about. In plan9 where the concept comes from namespaces are referred to as process groups, and that is a valid view. At least from a monitoring perspective.

Quoted 7 lines
Quoted 3 lines

If we make namespaces show up anywhere besides under "/proc/<pid>/task/<tid>/" we have to do something like this, and pids are largely designed for this kind of use.

Proc consists of two parts - the <pid>-s one with generated-on-the-fly entries and the static one that is represented by proc_dir_entry tree. Do you propose to mix those two?

Yes. Because the static entries are beginning to depend on process specific attributes. We have already started with /proc/mounts.

Quoted 4 lines
Quoted 2 lines

just need a non-global id for our directory entries so we don't paint ourselves into a corner.

What namespace do you mean by "non-global"?

The best is an id I can take with me when I migrate from machine A to machine B. An id in some namespace or a form that doesn't need an id at all is the core requirement.

Eric

#12 lore raw
Quoted 34 lines · Eric W. Biederman
Quoted 8 lines · Pavel Emelyanov
Quoted 4 lines

I was thinking we might be able to hide the existence of /proc/.netns/NNN/ however we can read the current working directory. So even if we only allow explicit access through /proc/net and all others paths don't work we have something that is visible.

I have a patch that overrides the ->readdir method for /proc/.netns, so that you can no longer read the directory contents, but you still can guess one by guessing and opening files in it. Overriding the ->lookup to screw one up looks like "shadowing" technics.

Or looking at the symlinks under /proc/<pid>/fd/1 Or opening something under /proc/net/ and calling get pwd.

Quoted 3 lines

OTOH - consider you have the ids of existing net namespaces, but cannot read the contents on any but yours. So what? This information is useless for you. So I dropped this part of a patch.

However it is fundamental that monitoring programs want to inspect the namespaces of other processes.

In theory the resource group stuff was suppose to provide us with all of the names we would need. However the semantics seem a bit to flexible to use for something like this.

Quoted 9 lines
Quoted 2 lines

- Have readdir and lookup filter the directory entries by the pid namespace of the proc mount.

So, how are you going to filter the lookup? The problem I see - you have a process that opened the /proc/.netns/X directory (he onws that namespace) and the other one trying to do the same. The VFS layer finds the hashed dentry corresponding to this /proc/.netns/X. The only way you can prevent VFS from giving one to the second task is to override .d_revalidate method and drop that dentry....

Quoted 3 lines
Quoted 1 line

But we've already tried to walk this way with no luck.

I meant a per mount filtering. Exactly like we do for the pids now.

We (me) do not perform any "filtering" in /proc. I just make /proc play the VFS rules - one super-block one tree of dentries.

Quoted 15 lines
Quoted 6 lines
Quoted 3 lines

It looks like we have to tweak things just a bit so that free_pid would not be called until the pid namespace goes away. Something similar to how we do the hash chains.

This is not about pid namespace, this is about net namespace and tuning pids management to facilitate networking needs is not the right thing to do.

Not exactly. It is about process attribute visibility. Which is what proc is about. In plan9 where the concept comes from namespaces are referred to as process groups, and that is a valid view. At least from a monitoring perspective.

Quoted 3 lines
Quoted 3 lines

If we make namespaces show up anywhere besides under "/proc/<pid>/task/<tid>/" we have to do something like this, and pids are largely designed for this kind of use.

Quoted 6 lines
Quoted 3 lines

Proc consists of two parts - the <pid>-s one with generated-on-the-fly entries and the static one that is represented by proc_dir_entry tree. Do you propose to mix those two?

Yes. Because the static entries are beginning to depend on process specific attributes. We have already started with /proc/mounts.

/proc/<pid>/mounts is not represented with any proc_dir_entry, but what you're proposing with /proc/<pid>/net seems like doing this representation.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

just need a non-global id for our directory entries so we don't paint ourselves into a corner.

What namespace do you mean by "non-global"?

The best is an id I can take with me when I migrate from machine A to machine B. An id in some namespace or a form that doesn't need an id at all is the core requirement.

If we're OK in having a /proc/netns/<xxx> for each namespace, then this <xxx> is an id, regardless whatever it is - a pre-generated number, a pointer, etc.

That said, your only wish is to make this <xxx> be preservable across migration, right?

Quoted 2 lines

Eric

#13 lore raw
Quoted 9 lines · Pavel Emelyanov
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

- Have readdir and lookup filter the directory entries by the pid namespace of the proc mount.

So, how are you going to filter the lookup? The problem I see - you have a process that opened the /proc/.netns/X directory (he onws that namespace) and the other one trying to do the same. The VFS layer finds the hashed dentry corresponding to this /proc/.netns/X. The only way you can prevent VFS from giving one to the second task is to override .d_revalidate method and drop that dentry....

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

But we've already tried to walk this way with no luck.

I meant a per mount filtering. Exactly like we do for the pids now.

We (me) do not perform any "filtering" in /proc. I just make /proc play the VFS rules - one super-block one tree of dentries.

Exactly. For different super blocks we return a different set of processes and a different set of numbers of those processes. If you do use ids that do not live in a namespace I agree you do not need to do different things for different mounts, but that seems ugly and problematic.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

If we make namespaces show up anywhere besides under "/proc/<pid>/task/<tid>/" we have to do something like this, and pids are largely designed for this kind of use.

Proc consists of two parts - the <pid>-s one with generated-on-the-fly entries and the static one that is represented by proc_dir_entry tree. Do you propose to mix those two?

Quoted 6 lines
Quoted 2 lines

Yes. Because the static entries are beginning to depend on process specific attributes. We have already started with /proc/mounts.

/proc/<pid>/mounts is not represented with any proc_dir_entry, but what you're proposing with /proc/<pid>/net seems like doing this representation.

Yes. I am talking about placing things represented with a prod_dir_entry and having them show up under a hierarchy not represented with proc_dir_entries under /proc/<pid>.

As that is clean, worked well for /proc/mounts, does not require ids at all, and is essentially the optimal form for monitoring processes.

/proc/mounts used to have a proc_dir_entry. When it was reimplemented to be per fs namespace that was removed.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

just need a non-global id for our directory entries so we don't paint ourselves into a corner.

What namespace do you mean by "non-global"?

The best is an id I can take with me when I migrate from machine A to machine B. An id in some namespace or a form that doesn't need an id at all is the core requirement.

Quoted 6 lines

If we're OK in having a /proc/netns/<xxx> for each namespace, then this <xxx> is an id, regardless whatever it is - a pre-generated number, a pointer, etc.

That said, your only wish is to make this <xxx> be preservable across migration, right?

No, that is not my only wish.

- I wish for a clean maintainable interface.
- I wish for an interface that we can use for monitoring programs like top and ps.
- I wish for an interface that is migration safe.

It is my opinion that using an id is simply an optimization to reduce the number of cached proc dentries.

I gave a full run down of what I wish and the reasons for it earlier in this thread. I have not seen you respond to that message.

Currently I am NOT ok having a /proc/netns/<xxx>. It appears to be a contentious premature optimization.

VFS clean, maintainable, and usable for monitoring is /proc/<pid>/task/<tid>/net.

We can always figure out how to optimize that form later.

Eric

#14 lore raw
Quoted 65 lines · Eric W. Biederman
Quoted 9 lines · Pavel Emelyanov
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines

- Have readdir and lookup filter the directory entries by the pid namespace of the proc mount.

So, how are you going to filter the lookup? The problem I see - you have a process that opened the /proc/.netns/X directory (he onws that namespace) and the other one trying to do the same. The VFS layer finds the hashed dentry corresponding to this /proc/.netns/X. The only way you can prevent VFS from giving one to the second task is to override .d_revalidate method and drop that dentry....

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

But we've already tried to walk this way with no luck.

I meant a per mount filtering. Exactly like we do for the pids now.

We (me) do not perform any "filtering" in /proc. I just make /proc play the VFS rules - one super-block one tree of dentries.

Exactly. For different super blocks we return a different set of processes and a different set of numbers of those processes. If you do use ids that do not live in a namespace I agree you do not need to do different things for different mounts, but that seems ugly and problematic.

Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

If we make namespaces show up anywhere besides under "/proc/<pid>/task/<tid>/" we have to do something like this, and pids are largely designed for this kind of use.

Proc consists of two parts - the <pid>-s one with generated-on-the-fly entries and the static one that is represented by proc_dir_entry tree. Do you propose to mix those two?

Yes. Because the static entries are beginning to depend on process specific attributes. We have already started with /proc/mounts.

/proc/<pid>/mounts is not represented with any proc_dir_entry, but what you're proposing with /proc/<pid>/net seems like doing this representation.

Yes. I am talking about placing things represented with a prod_dir_entry and having them show up under a hierarchy not represented with proc_dir_entries under /proc/<pid>.

As that is clean, worked well for /proc/mounts, does not require ids at all, and is essentially the optimal form for monitoring processes.

/proc/mounts used to have a proc_dir_entry. When it was reimplemented to be per fs namespace that was removed.

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

just need a non-global id for our directory entries so we don't paint ourselves into a corner.

What namespace do you mean by "non-global"?

The best is an id I can take with me when I migrate from machine A to machine B. An id in some namespace or a form that doesn't need an id at all is the core requirement.

Quoted 6 lines

If we're OK in having a /proc/netns/<xxx> for each namespace, then this <xxx> is an id, regardless whatever it is - a pre-generated number, a pointer, etc.

That said, your only wish is to make this <xxx> be preservable across migration, right?

No, that is not my only wish.

- I wish for a clean maintainable interface.
- I wish for an interface that we can use for monitoring programs like top and ps.
- I wish for an interface that is migration safe.

Quoted 5 lines

It is my opinion that using an id is simply an optimization to reduce the number of cached proc dentries.

I gave a full run down of what I wish and the reasons for it earlier in this thread. I have not seen you respond to that message.

I took you opinion, expressed in this letter, into account.

Quoted 2 lines

Currently I am NOT ok having a /proc/netns/<xxx>. It appears to be a contentious premature optimization.

Have you changed your mind suddenly?
You told opposite less than a week ago.

Quoted 2 lines

VFS clean, maintainable, and usable for monitoring is /proc/<pid>/task/<tid>/net.

Why not /proc/pid/net? Are we ever going to move threads in namespace?

Quoted 4 lines

We can always figure out how to optimize that form later.

Eric

#15 lore raw
In reply to [email protected]
Quoted 8 lines
Quoted 2 lines

Nack. Yet another global set of ids that require us to implement another namespace looks like the wrong way to go.

Sentiment granted, but I'm not sure it can be an issue. It *could* be in issue if we moved to a more flexible access control here here any netns could access the .netns/N directories for all it's child namespaces.

Quoted 8 lines

But it can't, and /proc/net is set by the kernel. So the <id> can't be an issue for any checkpoint/restart except htat of the whole system, and of course on whole-system resume we have no <id> collision worries.

So userspace can't do anything with <id>, so there is no reason to worry about it becoming another namespace?

Right?

Right. Thanks, Serge.

Quoted 2 lines

thanks,
-serge

#16 lore raw
In reply to Eric W. Biederman
Quoted 26 lines · Eric W. Biederman
Quoted 24 lines · Pavel Emelyanov

Current /proc/net is done with so called "shadows", but current implementation is broken and has little chances to get fixed.

The problem is that dentries subtree of /proc/net directory has fancy revalidation rules to make processes living in different net namespaces see different entries in /proc/net subtree, but currently, tasks see in the /proc/net subdir the contents of any other namespace, depending on who opened the file first.

The proposed fix is to turn /proc/net into a symlink, which behaves similar to /proc/self link - it points to .netns/<id> directory where the <id> is the id of net namespace, current task lives in.

# ls -l /proc/net
lrwxrwxrwx  1 root root 8 Feb 28 18:38 /proc/net -> .netns/0

The /proc/.netns dir contains subtrees for all the namespaces in the system:

# ls -l /proc/.netns/
total 0
dr-xr-xr-x  5 root root 0 Feb 28 18:39 0
dr-xr-xr-x  3 root root 0 Feb 28 18:39 1
Quoted 7 lines
Quoted 3 lines

To provide some security each /proc/.netns/<id> directory allows access to tasks that live in the owning namespace only (with the exception, that init_net tasks can see everything).

Nack. Yet another global set of ids that require us to implement another namespace looks like the wrong way to go.

I could use the struct net pointer values (obtained with sprintf(id, "%p", net)) instead, but exporting internal kernel addresses seemed even uglier.

Quoted 2 lines

Can you try this approach by capturing a struct pid instead of an id in a new global namespace?

This is a bad approach. When task, that created the namespace dies, his pid is removed from the pidmap and can be reused, so we can get another net with the same id.

Quoted 7 lines

In particular the pid of the process that creates the pid namespace. Like we do with setsid.

I think the implementation difficulty should be about the same, but it will allow us something that works cleanly in the cases of migration and nested namespaces. As well as not adding an unnecessary special case with init_net and visibility.

This net's id is not supposed to be used to address any net in the kernel. And I see no problems with migration - you can change the net's id safely during checkpoint/restart - tasks will always see this one via the /proc/net symlink, which is dynamic.

Quoted 2 lines

Eric

#17 lore raw
Quoted 2 lines · Pavel Emelyanov

I could use the struct net pointer values (obtained with sprintf(id, "%p", net)) instead, but exporting internal kernel addresses seemed even uglier.

Agreed.

Quoted 6 lines
Quoted 2 lines

Can you try this approach by capturing a struct pid instead of an id in a new global namespace?

This is a bad approach. When task, that created the namespace dies, his pid is removed from the pidmap and can be reused, so we can get another net with the same id.

It takes a little updating of how we use pids. The easiest method is to add an extra counter. So we know when someone besides the hash chains is using the pid as an id. However it might make sense to actually have a net namespace pointer in the pid.

Quoted 5 lines

This net's id is not supposed to be used to address any net in the kernel. And I see no problems with migration - you can change the net's id safely during checkpoint/restart - tasks will always see this one via the /proc/net symlink, which is dynamic.

So you are really talking about a hidden id. There are just enough ways for something like that to slip out I'm not especially comfortable with the idea.

I really think we need something clean that we can live with, and be proud of. However we implement the enhancement to /proc/net this has to be maintained for decades.

Eric

#18 lore raw
Quoted 9 lines · Eric W. Biederman
Quoted 2 lines · Pavel Emelyanov

I could use the struct net pointer values (obtained with sprintf(id, "%p", net)) instead, but exporting internal kernel addresses seemed even uglier.

Agreed.

Quoted 2 lines
Quoted 2 lines

Can you try this approach by capturing a struct pid instead of an id in a new global namespace?

Quoted 8 lines
Quoted 3 lines

This is a bad approach. When task, that created the namespace dies, his pid is removed from the pidmap and can be reused, so we can get another net with the same id.

It takes a little updating of how we use pids. The easiest method is to add an extra counter. So we know when someone besides the hash chains is using the pid as an id. However it might make sense to actually have a net namespace pointer in the pid.

No, please, no. I'm strongly opposed to making pids provide identification for anything we need in the kernel.

Quoted 15 lines
Quoted 4 lines

This net's id is not supposed to be used to address any net in the kernel. And I see no problems with migration - you can change the net's id safely during checkpoint/restart - tasks will always see this one via the /proc/net symlink, which is dynamic.

So you are really talking about a hidden id. There are just enough ways for something like that to slip out I'm not especially comfortable with the idea.

I really think we need something clean that we can live with, and be proud of. However we implement the enhancement to /proc/net this has to be maintained for decades.

Eric

#19 lore raw
Quoted 8 lines · Pavel Emelyanov
Quoted 5 lines

It takes a little updating of how we use pids. The easiest method is to add an extra counter. So we know when someone besides the hash chains is using the pid as an id. However it might make sense to actually have a net namespace pointer in the pid.

No, please, no. I'm strongly opposed to making pids provide identification for anything we need in the kernel.

I don't see the problem. Sessions and process groups are roughly the same kinds of concept as namespaces.

However I do agree that not using any kind of id is cleaner, leaves us with less legacy that we have to deal with, and keeps struct pid small, so it is preferable.

Eric