Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove runc default devices that overlap with spec devices. #2522

Merged
merged 2 commits into from
Aug 19, 2020

Conversation

ctalledo
Copy link
Contributor

Runc has a set of default devices that it includes in Linux containers
(e.g., /dev/null, /dev/random, /dev/tty, etc.)

However if the container's OCI spec includes all or a subset of those same devices,
runc is currently not detecting the redundancy, causing it to create a lib
container config that has redundant device configurations.

This causes a failure in rootless mode, in particular when the /dev/tty device
has a redundant config:

container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:70: creating device nodes caused: open /tmp/busyboxtest/rootfs/dev/tty: no such device or address"

The reason this fails in rootless mode only is that in this case runc sets up
/dev/tty not by doing mknod (it's not allowed within a user-ns) but rather by
creating a regular file under /dev/tty and bind-mounting the host's /dev/tty to
the container's /dev/tty. When this operation is done redundantly, it fails the
second time.

This change fixes this problem by ensuring runc checks for redundant devices
between the OCI spec it receives and the default devices it configures. If
a redundant device is detected, the OCI spec takes priority.

The change adds both a unit test and an integration test to verify the
behavior. Without this fix, this new integration test fails as shown above.

Signed-off-by: Cesar Talledo [email protected]

@ctalledo
Copy link
Contributor Author

Hi @AkihiroSuda, I added a test for /dev/ptmx per your request. In fact that test caught a bug which my initial change did not address, so I had to add a second commit to the PR.

Please take a look when you get a chance.

Thanks!

AkihiroSuda
AkihiroSuda previously approved these changes Jul 23, 2020
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@ctalledo
Copy link
Contributor Author

Hi @cyphar, @kolyshkin, let me know if this PR looks good to you please. Thanks!

AkihiroSuda
AkihiroSuda previously approved these changes Jul 29, 2020
@ctalledo
Copy link
Contributor Author

ctalledo commented Aug 3, 2020

Kind ping to @cyphar and @kolyshkin for approval. Thanks!

@AkihiroSuda AkihiroSuda added this to the 1.0.0-rc92 (nee rc12) milestone Aug 5, 2020
@AkihiroSuda
Copy link
Member

ping @cyphar @kolyshkin @mrunalp Let's have rc92 with this

Runc has a set of default devices that it includes in Linux containers
(e.g., /dev/null, /dev/random, /dev/tty, etc.)

However if the container's OCI spec includes all or a subset of those same devices,
runc is currently not detecting the redundancy, causing it to create a lib
container config that has redundant device configurations.

This causes a failure in rootless mode, in particular when the /dev/tty device
has a redundant config:

container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:70: creating device nodes caused: open /tmp/busyboxtest/rootfs/dev/tty: no such device or address"

The reason this fails in rootless mode only is that in this case runc sets up
/dev/tty not by doing mknod (it's not allowed within a user-ns) but rather by
creating a regular file under /dev/tty and bind-mounting the host's /dev/tty to
the container's /dev/tty. When this operation is done redundantly, it fails the
second time.

This change fixes this problem by ensuring runc checks for redundant devices
between the OCI spec it receives and the default devices it configures. If
a redundant device is detected, the OCI spec takes priority.

The change adds both a unit test and an integration test to verify the
behavior. Without this fix, this new integration test fails as shown above.

Signed-off-by: Cesar Talledo <[email protected]>
…CI spec.

Per the OCI spec, /dev/ptmx is always a symlink to /dev/pts/ptmx. As such, if
the OCI spec has an explicit entry for /dev/ptmx, runc shall ignore it.

This change ensures this is the case. A integration test was also added
(in tests/integration/dev.bats).

Signed-off-by: Cesar Talledo <[email protected]>
@thaJeztah
Copy link
Member

ping @kolyshkin PTAL

@ctalledo
Copy link
Contributor Author

Hi @kolyshkin, would it be possible to get another review? Thanks!

Copy link
Member

@cyphar cyphar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think the dedup devices code could still be made simpler, but this does solve the issue.

@cyphar cyphar closed this in 2265daa Aug 19, 2020
@cyphar cyphar merged commit 2265daa into opencontainers:master Aug 19, 2020
@ctalledo
Copy link
Contributor Author

Thanks @cyphar, @AkihiroSuda, @kolyshkin !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants