diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index 5073870de25..0aeadb92329 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -19,6 +19,7 @@ import ( "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/system" + "github.com/opencontainers/runc/libcontainer/utils" libcontainerUtils "github.com/opencontainers/runc/libcontainer/utils" "github.com/opencontainers/selinux/go-selinux/label" @@ -589,6 +590,12 @@ func createDevices(config *configs.Config) error { useBindMount := system.RunningInUserNS() || config.Namespaces.Contains(configs.NEWUSER) oldMask := unix.Umask(0000) for _, node := range config.Devices { + + // The /dev/ptmx device is setup by setupPtmx() + if utils.CleanPath(node.Path) == "/dev/ptmx" { + continue + } + // containers running in a user namespace are not allowed to mknod // devices so we can just bind mount it from the host. if err := createDeviceNode(config.Rootfs, node, useBindMount); err != nil { diff --git a/tests/integration/dev.bats b/tests/integration/dev.bats index 2ce97615ac2..ef09dcd128d 100644 --- a/tests/integration/dev.bats +++ b/tests/integration/dev.bats @@ -11,9 +11,9 @@ function teardown() { teardown_busybox } -@test "runc run [redundant default dev]" { +@test "runc run [redundant default /dev/tty]" { update_config ' .linux.devices += [{"path": "/dev/tty", "type": "c", "major": 5, "minor": 0}] - | .process.args |= ["ls", "-l", "/dev/tty"]' + | .process.args |= ["ls", "-lL", "/dev/tty"]' runc run test_dev [ "$status" -eq 0 ] @@ -24,3 +24,12 @@ function teardown() { [[ "${lines[0]}" =~ "crw-rw-rw".+"1".+"root".+"root".+"5,".+"0".+"/dev/tty" ]] fi } + +@test "runc run [redundant default /dev/ptmx]" { + update_config ' .linux.devices += [{"path": "/dev/ptmx", "type": "c", "major": 5, "minor": 2}] + | .process.args |= ["ls", "-lL", "/dev/ptmx"]' + + runc run test_dev + [ "$status" -eq 0 ] + [[ "${lines[0]}" =~ "crw-rw-rw".+"1".+"root".+"root".+"5,".+"2".+"/dev/ptmx" ]] +}