Browse code

Merge pull request #20133 from mlaventure/dont-bind-mount-mqueue

Prevent mqueue from implicitely becoming a bind mount with --ipc=host

Tibor Vass authored on 2016/02/10 09:55:57
Showing 3 changed files
... ...
@@ -44,7 +44,6 @@ type Container struct {
44 44
 	HostnamePath    string
45 45
 	HostsPath       string
46 46
 	ShmPath         string
47
-	MqueuePath      string
48 47
 	ResolvConfPath  string
49 48
 	SeccompProfile  string
50 49
 }
... ...
@@ -549,15 +548,6 @@ func (container *Container) IpcMounts() []execdriver.Mount {
549 549
 			Propagation: volume.DefaultPropagationMode,
550 550
 		})
551 551
 	}
552
-	if !container.HasMountFor("/dev/mqueue") &&
553
-		container.MqueuePath != "" {
554
-		mounts = append(mounts, execdriver.Mount{
555
-			Source:      container.MqueuePath,
556
-			Destination: "/dev/mqueue",
557
-			Writable:    true,
558
-			Propagation: volume.DefaultPropagationMode,
559
-		})
560
-	}
561 552
 	return mounts
562 553
 }
563 554
 
... ...
@@ -106,11 +106,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
106 106
 			if _, err := os.Stat("/dev/shm"); err != nil {
107 107
 				return fmt.Errorf("/dev/shm is not mounted, but must be for --ipc=host")
108 108
 			}
109
-			if _, err := os.Stat("/dev/mqueue"); err != nil {
110
-				return fmt.Errorf("/dev/mqueue is not mounted, but must be for --ipc=host")
111
-			}
112 109
 			c.ShmPath = "/dev/shm"
113
-			c.MqueuePath = "/dev/mqueue"
114 110
 		}
115 111
 	}
116 112
 
... ...
@@ -2371,7 +2371,7 @@ func (s *DockerSuite) TestRunModeIpcContainer(c *check.C) {
2371 2371
 	// Not applicable on Windows as uses Unix-specific capabilities
2372 2372
 	testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace)
2373 2373
 
2374
-	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && top")
2374
+	out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && touch /dev/mqueue/toto && top")
2375 2375
 
2376 2376
 	id := strings.TrimSpace(out)
2377 2377
 	state := inspectField(c, id, "State.Running")
... ...
@@ -2395,6 +2395,18 @@ func (s *DockerSuite) TestRunModeIpcContainer(c *check.C) {
2395 2395
 	if catOutput != "test" {
2396 2396
 		c.Fatalf("Output of /dev/shm/test expected test but found: %s", catOutput)
2397 2397
 	}
2398
+
2399
+	// check that /dev/mqueue is actually of mqueue type
2400
+	grepOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "grep", "/dev/mqueue", "/proc/mounts")
2401
+	if !strings.HasPrefix(grepOutput, "mqueue /dev/mqueue mqueue rw") {
2402
+		c.Fatalf("Output of 'grep /proc/mounts' expected 'mqueue /dev/mqueue mqueue rw' but found: %s", grepOutput)
2403
+	}
2404
+
2405
+	lsOutput, _ := dockerCmd(c, "run", fmt.Sprintf("--ipc=container:%s", id), "busybox", "ls", "/dev/mqueue")
2406
+	lsOutput = strings.Trim(lsOutput, "\n")
2407
+	if lsOutput != "toto" {
2408
+		c.Fatalf("Output of 'ls /dev/mqueue' expected 'toto' but found: %s", lsOutput)
2409
+	}
2398 2410
 }
2399 2411
 
2400 2412
 func (s *DockerSuite) TestRunModeIpcContainerNotExists(c *check.C) {
... ...
@@ -2421,9 +2433,11 @@ func (s *DockerSuite) TestRunModeIpcContainerNotRunning(c *check.C) {
2421 2421
 
2422 2422
 func (s *DockerSuite) TestRunMountShmMqueueFromHost(c *check.C) {
2423 2423
 	// Not applicable on Windows as uses Unix-specific capabilities
2424
-	testRequires(c, SameHostDaemon, DaemonIsLinux)
2424
+	testRequires(c, SameHostDaemon, DaemonIsLinux, NotUserNamespace)
2425 2425
 
2426
-	dockerCmd(c, "run", "-d", "--name", "shmfromhost", "-v", "/dev/shm:/dev/shm", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && top")
2426
+	dockerCmd(c, "run", "-d", "--name", "shmfromhost", "-v", "/dev/shm:/dev/shm", "-v", "/dev/mqueue:/dev/mqueue", "busybox", "sh", "-c", "echo -n test > /dev/shm/test && touch /dev/mqueue/toto && top")
2427
+	defer os.Remove("/dev/mqueue/toto")
2428
+	defer os.Remove("/dev/shm/test")
2427 2429
 	volPath, err := inspectMountSourceField("shmfromhost", "/dev/shm")
2428 2430
 	c.Assert(err, checker.IsNil)
2429 2431
 	if volPath != "/dev/shm" {
... ...
@@ -2434,6 +2448,11 @@ func (s *DockerSuite) TestRunMountShmMqueueFromHost(c *check.C) {
2434 2434
 	if out != "test" {
2435 2435
 		c.Fatalf("Output of /dev/shm/test expected test but found: %s", out)
2436 2436
 	}
2437
+
2438
+	// Check that the mq was created
2439
+	if _, err := os.Stat("/dev/mqueue/toto"); err != nil {
2440
+		c.Fatalf("Failed to confirm '/dev/mqueue/toto' presence on host: %s", err.Error())
2441
+	}
2437 2442
 }
2438 2443
 
2439 2444
 func (s *DockerSuite) TestContainerNetworkMode(c *check.C) {