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

init: switch away from stateDirFd entirely #1570

Merged
merged 1 commit into from
Aug 25, 2017
Merged

init: switch away from stateDirFd entirely #1570

merged 1 commit into from
Aug 25, 2017

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Aug 24, 2017

While we have significant protections in place against CVE-2016-9962, we
still were holding onto a file descriptor that referenced the host
filesystem. This meant that in certain scenarios it was still possible
for a semi-privileged container to gain access to the host filesystem
(if they had CAP_SYS_PTRACE).

Instead, open the FIFO itself using a O_PATH. This allows us to
reference the FIFO directly without providing the ability for
directory-level access. When opening the FIFO inside the init process,
open it through procfs to re-open the actual FIFO (this is currently the
only supported way to open such a file descriptor).

Signed-off-by: Aleksa Sarai [email protected]

@cyphar
Copy link
Member Author

cyphar commented Aug 24, 2017

@crosbymichael This is the patchset I've been promising for a while that would remove the entire possibility of a CVE-2016-9962-style bug happening again.

@crosbymichael
Copy link
Member

crosbymichael commented Aug 24, 2017

LGTM

Approved with PullApprove

// fd, with _LIBCONTAINER_FIFOFD set to its fd number.
func (c *linuxContainer) includeExecFifo(cmd *exec.Cmd) error {
fifoName := filepath.Join(c.root, execFifoFilename)
fifoFd, err := unix.Open(fifoName, unix.O_PATH|unix.O_RDWR|unix.O_CLOEXEC, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

"When O_PATH is specified in flags, flag bits other than O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW are ignored"

Should we remove O_RDWR since it'll be ignored anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, you're right. I'll remove it.

While we have significant protections in place against CVE-2016-9962, we
still were holding onto a file descriptor that referenced the host
filesystem. This meant that in certain scenarios it was still possible
for a semi-privileged container to gain access to the host filesystem
(if they had CAP_SYS_PTRACE).

Instead, open the FIFO itself using a O_PATH. This allows us to
reference the FIFO directly without providing the ability for
directory-level access. When opening the FIFO inside the init process,
open it through procfs to re-open the actual FIFO (this is currently the
only supported way to open such a file descriptor).

Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar
Copy link
Member Author

cyphar commented Aug 25, 2017

Alright fixed up @hqhq's comment.

@hqhq
Copy link
Contributor

hqhq commented Aug 25, 2017

LGTM

Approved with PullApprove

@TomSweeneyRedHat
Copy link

LGTM, really awesome comments throughout @cyphar. 🥇

@crosbymichael
Copy link
Member

crosbymichael commented Aug 25, 2017

LGTM

Approved with PullApprove

@crosbymichael crosbymichael merged commit 4e33fae into opencontainers:master Aug 25, 2017
@cyphar cyphar deleted the close-statedirfd-hole branch August 25, 2017 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants