diff mbox

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

Message ID 20170801154609.29895-1-casey.callendrello@coreos.com
State Accepted, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Casey Callendrello Aug. 1, 2017, 3:46 p.m. UTC
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 <casey.callendrello@coreos.com>
---
 ip/ipnetns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stephen Hemminger Aug. 3, 2017, 11:04 p.m. UTC | #1
On Tue,  1 Aug 2017 17:46:09 +0200
Casey Callendrello <casey.callendrello@coreos.com> 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 <casey.callendrello@coreos.com>
> ---
>  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.
Eric W. Biederman Aug. 4, 2017, 1:41 p.m. UTC | #2
Stephen Hemminger <stephen@networkplumber.org> writes:

> On Tue,  1 Aug 2017 17:46:09 +0200
> Casey Callendrello <casey.callendrello@coreos.com> 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 <casey.callendrello@coreos.com>
>> ---
>>  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" <ebiederm@xmission.com>

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
diff mbox

Patch

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;