[PATCH iproute2] netns: make /var/run/netns bind-mount recursive

Subsystems: the rest

STALE3363d

3 messages, 3 authors, 2017-08-04 · open the first message on its own page

[PATCH iproute2] netns: make /var/run/netns bind-mount recursive

From: Casey Callendrello <hidden>
Date: 2017-08-01 15:46:12

When ip netns {add|delete} is first run, it bind-mounts /var/run/netns
on top of itself, then marks it as shared. However, if there are already
bind-mounts in the directory from other tools, these would not be
propagated. Fix this by recursively bind-mounting.

Signed-off-by: Casey Callendrello <redacted>
---
 ip/ipnetns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 198e9de8..9ee1fe6a 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -636,7 +636,7 @@ static int netns_add(int argc, char **argv)
 		}
 
 		/* Upgrade NETNS_RUN_DIR to a mount point */
-		if (mount(NETNS_RUN_DIR, NETNS_RUN_DIR, "none", MS_BIND, NULL)) {
+		if (mount(NETNS_RUN_DIR, NETNS_RUN_DIR, "none", MS_BIND | MS_REC, NULL)) {
 			fprintf(stderr, "mount --bind %s %s failed: %s\n",
 				NETNS_RUN_DIR, NETNS_RUN_DIR, strerror(errno));
 			return -1;
-- 
2.13.3

Re: [PATCH iproute2] netns: make /var/run/netns bind-mount recursive

From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2017-08-03 23:04:23

On Tue,  1 Aug 2017 17:46:09 +0200
Casey Callendrello [off-list ref] wrote:
When ip netns {add|delete} is first run, it bind-mounts /var/run/netns
on top of itself, then marks it as shared. However, if there are already
bind-mounts in the directory from other tools, these would not be
propagated. Fix this by recursively bind-mounting.

Signed-off-by: Casey Callendrello <redacted>
---
 ip/ipnetns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Looks good, but I want a review by Eric to make sure this doesn't break other things.

Re: [PATCH iproute2] netns: make /var/run/netns bind-mount recursive

From: Eric W. Biederman <hidden>
Date: 2017-08-04 13:49:48

Stephen Hemminger [off-list ref] writes:
On Tue,  1 Aug 2017 17:46:09 +0200
Casey Callendrello [off-list ref] wrote:
quoted
When ip netns {add|delete} is first run, it bind-mounts /var/run/netns
on top of itself, then marks it as shared. However, if there are already
bind-mounts in the directory from other tools, these would not be
propagated. Fix this by recursively bind-mounting.

Signed-off-by: Casey Callendrello <redacted>
---
 ip/ipnetns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Looks good, but I want a review by Eric to make sure this doesn't
break other things.
Acked-by: "Eric W. Biederman" <redacted>

I don't see any possible problems with this.  This will just keep all of
the mounts showing up.

It would be really nice if we could at some point detect that a parent
directory is shared (which happens with a common init system) and skip
the steps of the bind mount and making them shared as they are
redundant.  However while that might also solve this issue that is
something for another day.

Eric
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help