Skip to content

Remove dependency in dockerd on libseccomp#41395

Merged
thaJeztah merged 3 commits into
moby:masterfrom
cpuguy83:no_libseccomp
Sep 15, 2020
Merged

Remove dependency in dockerd on libseccomp#41395
thaJeztah merged 3 commits into
moby:masterfrom
cpuguy83:no_libseccomp

Conversation

@cpuguy83

Copy link
Copy Markdown
Member

This was just using libseccomp to get the right arch, but we can use
GOARCH to get this.
The nativeToSeccomp map needed to be adjusted a bit for mipsle vs mipsel
since that's go how refers to it. Also added some other arches to it.

Closes #41299

Comment thread profiles/seccomp/seccomp.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be removed from vendor?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also Dockerfile should no longer need aptgetting libseccomp

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.

Still need libseccomp to build runc at least.

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.

I may push some images for runc and containerd since these rarely change and just consume those in our Dockerfile...

@thaJeztah

Copy link
Copy Markdown
Member

Build is failing;

[2020-08-27T23:32:31.365Z] === Errors
[2020-08-27T23:32:31.365Z] profiles/seccomp/seccomp.go:102:37: undefined: arch
[2020-08-27T23:32:31.365Z] profiles/seccomp/seccomp.go:121:38: undefined: arch
[2020-08-27T23:32:31.365Z] profiles/seccomp/seccomp.go:102: undefined: arch
[2020-08-27T23:32:31.365Z] profiles/seccomp/seccomp.go:121: undefined: arch

@thaJeztah thaJeztah added this to the 20.03.0 milestone Aug 28, 2020
@cpuguy83

Copy link
Copy Markdown
Member Author

Updated to remove seccomp build tag and instead check at runtime if seccomp is supported.
Also removes vendor and moves libseccomp-dev install to just run runc build stage.

@cpuguy83
cpuguy83 force-pushed the no_libseccomp branch 2 times, most recently from 003d82b to de6600f Compare August 28, 2020 19:39
Comment thread profiles/seccomp/default_linux.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wondering; what would happen if we didn't even check, and just passed this down to containerd/runc (having them deal with wether or not to do something with it)?

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.

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.

Sorry that's different... when runc is not compiled with seccomp support.

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.

Most likely what will happen here is the kernel will throw an error.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's if runc applies it; I wonder if runc should do the check, and skip that part of the spec if it's not supported 🤔

Basically; if could have multiple OCI runtimes configured, and the docker daemon doesn't know what they support (hope you follow my train of thought)

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.

I follow, but I think at the runc level you just want it to execute what you told it to.
If you pass a seccomp profile and it doesn't load it but continues anyway, seems like this would cause some security issues at the very least.

@cpuguy83

cpuguy83 commented Sep 3, 2020

Copy link
Copy Markdown
Member Author

Hold off on merging... realized there's an issue here where some files are still depending on the 'seccomp' build tag.

@cpuguy83

cpuguy83 commented Sep 3, 2020

Copy link
Copy Markdown
Member Author

I pulled back on those buildtag changes just because there's a ton of places where it's used.
I can deal with this in a follow up since it's really a different change.

@tianon tianon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM (although test failure looks weird)

@thaJeztah

Copy link
Copy Markdown
Member

@cpuguy83 tests are still failing, so looks related

@cpuguy83

cpuguy83 commented Sep 11, 2020

Copy link
Copy Markdown
Member Author

Old profile -> New profile... 🤔

-                                 "arch_prctl"
-                         ],
-                         "action": "SCMP_ACT_ALLOW"
-                 },
-                 {
-                         "names": [
-                                 "modify_ldt"
-                         ],
-                         "action": "SCMP_ACT_ALLOW"
-                 },
-                 {
-                         "names": [

@cpuguy83

Copy link
Copy Markdown
Member Author

Should be fixed now.
Had to add a mapping from goarch -> libseccomp string -> docker arch type

Comment thread profiles/seccomp/seccomp_linux.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice catch that this was inside the loop 👍

Comment thread profiles/seccomp/seccomp_linux.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

couldn't we change this to goarchToSeccomp ?

so change this to "386" ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah, nevermind; looks like arch is used further down (didn't show in the diff)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Guess we could still do it, but we would need both mapping (but it would change to GOARCH -> native, and GOARCH -> seccomp)

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.

Yeah this was pretty much why it was failing. Didn't realize we were using the libseccomp arch string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think it will be cleaner to have GOARCH -> nativeArch and GOARCh -> seccompArch, so that they can be used independently?

diff --git a/profiles/seccomp/seccomp_linux.go b/profiles/seccomp/seccomp_linux.go
index 7847085a0a..ac6441d6c3 100644
--- a/profiles/seccomp/seccomp_linux.go
+++ b/profiles/seccomp/seccomp_linux.go
@@ -27,16 +27,16 @@ func LoadProfile(body string, rs *specs.Spec) (*specs.LinuxSeccomp, error) {
        return setupSeccomp(&config, rs)
 }

-// libseccomp string => seccomp arch
-var nativeToSeccomp = map[string]types.Arch{
-       "x86":         types.ArchX86,
+// GOARCH => seccomp arch
+var goToSeccomp = map[string]types.Arch{
+       "386":         types.ArchX86,
        "amd64":       types.ArchX86_64,
        "arm":         types.ArchARM,
        "arm64":       types.ArchAARCH64,
        "mips64":      types.ArchMIPS64,
-       "mips64n32":   types.ArchMIPS64N32,
-       "mipsel64":    types.ArchMIPSEL64,
-       "mips3l64n32": types.ArchMIPSEL64N32,
+       "mips64p32":   types.ArchMIPS64N32,
+       "mips64le":    types.ArchMIPSEL64,
+       "mips64p32le": types.ArchMIPSEL64N32,
        "mipsle":      types.ArchMIPSEL,
        "ppc":         types.ArchPPC,
        "ppc64":       types.ArchPPC64,
@@ -97,8 +97,7 @@ func setupSeccomp(config *types.Seccomp, rs *specs.Spec) (*specs.LinuxSeccomp, e
                }
        }

-       arch := goToNative[runtime.GOARCH]
-       seccompArch, archExists := nativeToSeccomp[arch]
+       seccompArch, archExists := goToSeccomp[runtime.GOARCH]

        if len(config.ArchMap) != 0 && archExists {
                for _, a := range config.ArchMap {
@@ -115,6 +114,8 @@ func setupSeccomp(config *types.Seccomp, rs *specs.Spec) (*specs.LinuxSeccomp, e
        newConfig.DefaultAction = specs.LinuxSeccompAction(config.DefaultAction)

 Loop:
+       arch := goToNative[runtime.GOARCH]
+
        // Loop through all syscall blocks and convert them to libcontainer format after filtering them
        for _, call := range config.Syscalls {
                if len(call.Excludes.Arches) > 0 {

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.

It's different, I don't think it's better or worse.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, it's not a blocker, as non of this is exported. Thought it would be slightly easier to understand, as we wouldn't be mapping twice (GOOS -> native -> seccomp).

I can open a follow-up to discuss

Comment thread profiles/seccomp/seccomp_linux.go Outdated
This was just using libseccomp to get the right arch, but we can use
GOARCH to get this.
The nativeToSeccomp map needed to be adjusted a bit for mipsle vs mipsel
since that's go how refers to it. Also added some other arches to it.

Signed-off-by: Brian Goff <[email protected]>
As it turns out, we call this function every time someone calls `docker
info`, every time a contianer is created, and every time a container is
started.
Certainly this should be refactored as a whole, but for now, memoize the
seccomp value.

Signed-off-by: Brian Goff <[email protected]>

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
thaJeztah merged commit 1155b6b into moby:master Sep 15, 2020
@cpuguy83
cpuguy83 deleted the no_libseccomp branch September 15, 2020 16:21
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.

Remove libseccomp cgo dependency

4 participants