Skip to content

Commit ba38d58

Browse files
committed
Make mqueue container specific
mqueue can not be mounted on the host os and then shared into the container. There is only one mqueue per mount namespace, so current code ends up leaking the /dev/mqueue from the host into ALL containers. Since SELinux changes the label of the mqueue, only the last container is able to use the mqueue, all other containers will get a permission denied. If you don't have SELinux protections sharing of the /dev/mqueue allows one container to interact in potentially hostile ways with other containers. Signed-off-by: Dan Walsh <dwalsh@redhat.com>
1 parent d13e8d8 commit ba38d58

File tree

3 files changed

+8
-36
lines changed

3 files changed

+8
-36
lines changed

container/container_unix.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -559,18 +559,6 @@ func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
559559
}
560560
}
561561

562-
if !container.HasMountFor("/dev/mqueue") {
563-
mqueuePath, err := container.MqueueResourcePath()
564-
if err != nil {
565-
logrus.Error(err)
566-
warnings = append(warnings, err.Error())
567-
} else if mqueuePath != "" {
568-
if err := unmount(mqueuePath); err != nil {
569-
warnings = append(warnings, fmt.Sprintf("failed to umount %s: %v", mqueuePath, err))
570-
}
571-
}
572-
}
573-
574562
if len(warnings) > 0 {
575563
logrus.Warnf("failed to cleanup ipc mounts:\n%v", strings.Join(warnings, "\n"))
576564
}
@@ -589,9 +577,8 @@ func (container *Container) IpcMounts() []execdriver.Mount {
589577
Propagation: volume.DefaultPropagationMode,
590578
})
591579
}
592-
593-
if !container.HasMountFor("/dev/mqueue") {
594-
label.SetFileLabel(container.MqueuePath, container.MountLabel)
580+
if !container.HasMountFor("/dev/mqueue") &&
581+
container.MqueuePath != "" {
595582
mounts = append(mounts, execdriver.Mount{
596583
Source: container.MqueuePath,
597584
Destination: "/dev/mqueue",

daemon/container_operations_unix.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,13 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
9393
return err
9494
}
9595

96-
c.MqueuePath, err = c.MqueueResourcePath()
97-
if err != nil {
98-
return err
99-
}
100-
10196
if c.HostConfig.IpcMode.IsContainer() {
10297
ic, err := daemon.getIpcContainer(c)
10398
if err != nil {
10499
return err
105100
}
106101
ipc.ContainerID = ic.ID
107102
c.ShmPath = ic.ShmPath
108-
c.MqueuePath = ic.MqueuePath
109103
} else {
110104
ipc.HostIpc = c.HostConfig.IpcMode.IsHost()
111105
if ipc.HostIpc {
@@ -1062,21 +1056,6 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
10621056
}
10631057
}
10641058

1065-
if !c.HasMountFor("/dev/mqueue") {
1066-
mqueuePath, err := c.MqueueResourcePath()
1067-
if err != nil {
1068-
return err
1069-
}
1070-
1071-
if err := idtools.MkdirAllAs(mqueuePath, 0700, rootUID, rootGID); err != nil {
1072-
return err
1073-
}
1074-
1075-
if err := syscall.Mount("mqueue", mqueuePath, "mqueue", uintptr(syscall.MS_NOEXEC|syscall.MS_NOSUID|syscall.MS_NODEV), ""); err != nil {
1076-
return fmt.Errorf("mounting mqueue mqueue : %s", err)
1077-
}
1078-
}
1079-
10801059
return nil
10811060
}
10821061

daemon/execdriver/native/template/default_template_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ func New() *configs.Config {
6464
Flags: syscall.MS_NOSUID | syscall.MS_NOEXEC,
6565
Data: "newinstance,ptmxmode=0666,mode=0620,gid=5",
6666
},
67+
{
68+
Source: "mqueue",
69+
Destination: "/dev/mqueue",
70+
Device: "mqueue",
71+
Flags: defaultMountFlags,
72+
},
6773
{
6874
Source: "sysfs",
6975
Destination: "/sys",

0 commit comments

Comments
 (0)