Skip to content

cgroups: fs: fix cgroup.Parent path sanitisation - #451

Merged
LK4D4 merged 1 commit into
opencontainers:masterfrom
cyphar:fix-infinite-recursion
Jan 11, 2016
Merged

LK4D4 merged 1 commit into
opencontainers:masterfrom
cyphar:fix-infinite-recursion

Conversation

@cyphar

@cyphar cyphar commented Dec 31, 2015

Copy link
Copy Markdown
Member

Properly sanitise the --cgroup-parent path, to avoid potential issues
(as it starts creating directories and writing to files as root). In
addition, fix an infinite recursion due to incomplete base cases.

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

/cc @security-team @diogomonica

Comment thread libcontainer/cgroups/fs/cpuset.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In what case would parent equals to current? Did you hit this in real life?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. It causes Docker to crash in not-very-fun ways. But any path where filepath.Dir(path) == path (such as /) will cause this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you be more specific, like how can we reproduce this with docker? I still don't know how could filepath.Dir(path) == path and it's not returned by "filepath.Clean(parent) == root".

And I think it'll help to add more comments for such code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The case --cgroup-parent=../../../../../hello/this/is/a/crash will cause Docker to crash due to an infinite recursion error (take a look at the upstream vendor commit for a test case). While this is solved with my path cleaning code, it implies that there are base cases not accounted for.

root isn't /, it's just a regular path. So if path is a not a subdirectory of root, this will break. I can make it panic (or return an error) if we ever hit the case that root is a subdirectory of path, if that'll make you happier.

@dqminh

dqminh commented Jan 4, 2016

Copy link
Copy Markdown
Contributor

Mmm i think we should have test for edge case like this, maybe eventually runc should test itself instead of depending on the docker test suite.

For now, can we add a test on the corresponding vendor update in docker ?

@cyphar

cyphar commented Jan 4, 2016

Copy link
Copy Markdown
Member Author

@dqminh I'll include it in the vendor patch now It's been updated. The issue with doing this is that the test suite will cause Docker to crash. Is this patch fine, though?

@cyphar

cyphar commented Jan 6, 2016

Copy link
Copy Markdown
Member Author

@hqhq I've made it emit an error (and have a slightly more descriptive comment). I don't think it makes sense to omit this check, even though the parent path stuff fixes the root cause (this incomplete base case causes lots of versions of Docker to be vulnerable to a DoS, and it's cheap to check the single case).

PTAL
/cc @dqminh @mrunalp @vishh @crosbymichael

Comment thread libcontainer/cgroups/fs/apply_raw.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If path = /a/b/c, absClean(path) will end up with a/b/c, seems not correct.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wait what? This isn't the latest version of the commit. One sec.

Properly sanitise the --cgroup-parent path, to avoid potential issues
(as it starts creating directories and writing to files as root). In
addition, fix an infinite recursion due to incomplete base cases.

It might be a good idea to move pathClean to a separate library (which
deals with path safety concerns, so all of runC and Docker can take
advantage of it).

Signed-off-by: Aleksa Sarai <[email protected]>
@cyphar

cyphar commented Jan 11, 2016

Copy link
Copy Markdown
Member Author

Sorry for the wrong version of the patch. Check it again.

/ping @dqminh @mrunalp @vishh @crosbymichael @hqhq

@hqhq

hqhq commented Jan 11, 2016

Copy link
Copy Markdown
Contributor

LGTM

1 similar comment
@LK4D4

LK4D4 commented Jan 11, 2016

Copy link
Copy Markdown
Contributor

LGTM

LK4D4 added a commit that referenced this pull request Jan 11, 2016
cgroups: fs: fix cgroup.Parent path sanitisation
@LK4D4
LK4D4 merged commit c0cad6a into opencontainers:master Jan 11, 2016
@cyphar
cyphar deleted the fix-infinite-recursion branch January 11, 2016 22:30
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
…dependent

specs-go/config: Drop platform-independent comment
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