Fix panic when starting container with invalid device cgroup rule#41919
Merged
Conversation
Member
Author
|
Some follow-ups I want to do;
|
Member
Author
|
@cpuguy83 @AkihiroSuda @mlaventure ptal /cc @dmm (thanks for reporting the issue), and @aiordache (thanks for the "ping" on slack) |
thaJeztah
commented
Jan 22, 2021
Member
Author
There was a problem hiding this comment.
This is to check the validation, but validation will have to be updated to reflect the correct range; https://github.com/torvalds/linux/blob/v5.10/include/linux/kdev_t.h
Member
Author
|
Opened #41920 to track follow-up enhancements |
Member
Author
|
argh; forgot to push a change I made in the test. hold on |
This fixes a panic when an invalid "device cgroup rule" is passed, resulting in an "index out of range". This bug was introduced in the original implementation in 1756af6, but was not reproducible when using the CLI, because the same commit also added client-side validation on the flag before making an API request. The following example, uses an invalid rule (`c *:* rwm` - two spaces before the permissions); ```console $ docker run --rm --network=host --device-cgroup-rule='c *:* rwm' busybox invalid argument "c *:* rwm" for "--device-cgroup-rule" flag: invalid device cgroup format 'c *:* rwm' ``` Doing the same, but using the API results in a daemon panic when starting the container; Create a container with an invalid device cgroup rule: ```console curl -v \ --unix-socket /var/run/docker.sock \ "http://localhost/v1.41/containers/create?name=foobar" \ -H "Content-Type: application/json" \ -d '{"Image":"busybox:latest", "HostConfig":{"DeviceCgroupRules": ["c *:* rwm"]}}' ``` Start the container: ```console curl -v \ --unix-socket /var/run/docker.sock \ -X POST \ "http://localhost/v1.41/containers/foobar/start" ``` Observe the daemon logs: ``` 2021-01-22 12:53:03.313806 I | http: panic serving @: runtime error: index out of range [0] with length 0 goroutine 571 [running]: net/http.(*conn).serve.func1(0xc000cb2d20) /usr/local/go/src/net/http/server.go:1795 +0x13b panic(0x2f32380, 0xc000aebfc0) /usr/local/go/src/runtime/panic.go:679 +0x1b6 github.com/docker/docker/oci.AppendDevicePermissionsFromCgroupRules(0xc000175c00, 0x8, 0x8, 0xc0000bd380, 0x1, 0x4, 0x0, 0x0, 0xc0000e69c0, 0x0, ...) /go/src/github.com/docker/docker/oci/oci.go:34 +0x64f ``` This patch: - fixes the panic, allowing the daemon to return an error on container start - adds a unit-test to validate various permutations - adds a "todo" to verify the regular expression (and handling) of the "a" (all) value We should also consider performing this validation when _creating_ the container, so that an error is produced early. Signed-off-by: Sebastiaan van Stijn <[email protected]>
thaJeztah
force-pushed
the
fix_cgroup_rule_panic
branch
from
January 22, 2021 15:03
f6fe69d to
5cc1753
Compare
Member
Author
|
s390 failure is unrelated; see #41933 |
tonistiigi
approved these changes
Feb 4, 2021
Member
Author
|
s390x failures are unrelated; bringing this one in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes/addresses docker/compose#8052
This fixes a panic when an invalid "device cgroup rule" is passed, resulting in an "index out of range".
This bug was introduced in the original implementation in 1756af6 (#22563), but was not reproducible when using the CLI, because the same commit also added client-side validation on the flag before making an API request. The following example, uses an invalid rule (
c *:* rwm- two spaces before the permissions);Doing the same, but using the API results in a daemon panic when starting the container;
This patch:
We should also consider performing this validation when creating the container,
so that an error is produced early.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)