Skip to content

Commit

Permalink
Merge pull request moby#38137 from tonistiigi/seccomp-ptrace
Browse files Browse the repository at this point in the history
seccomp: allow ptrace(2) for 4.8+ kernels
  • Loading branch information
justincormack authored Feb 5, 2019
2 parents e7a9a7c + 1124543 commit 1603af9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/types/seccomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ type Arg struct {

// Filter is used to conditionally apply Seccomp rules
type Filter struct {
Caps []string `json:"caps,omitempty"`
Arches []string `json:"arches,omitempty"`
Caps []string `json:"caps,omitempty"`
Arches []string `json:"arches,omitempty"`
MinKernel string `json:"minKernel,omitempty"`
}

// Syscall is used to match a group of syscalls in Seccomp
Expand Down
12 changes: 12 additions & 0 deletions profiles/seccomp/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,18 @@
"includes": {},
"excludes": {}
},
{
"names": [
"ptrace"
],
"action": "SCMP_ACT_ALLOW",
"args": null,
"comment": "",
"includes": {
"minKernel": "4.8.0"
},
"excludes": {}
},
{
"names": [
"personality"
Expand Down
32 changes: 31 additions & 1 deletion profiles/seccomp/seccomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"fmt"

"github.com/docker/docker/api/types"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/docker/docker/pkg/parsers/kernel"
specs "github.com/opencontainers/runtime-spec/specs-go"
libseccomp "github.com/seccomp/libseccomp-golang"
)

Expand Down Expand Up @@ -95,6 +96,21 @@ func setupSeccomp(config *types.Seccomp, rs *specs.Spec) (*specs.LinuxSeccomp, e

newConfig.DefaultAction = specs.LinuxSeccompAction(config.DefaultAction)

var currentKernelVersion *kernel.VersionInfo
kernelGreaterEqualThan := func(v string) (bool, error) {
version, err := kernel.ParseRelease(v)
if err != nil {
return false, err
}
if currentKernelVersion == nil {
currentKernelVersion, err = kernel.GetKernelVersion()
if err != nil {
return false, err
}
}
return kernel.CompareKernelVersion(*version, *currentKernelVersion) <= 0, nil
}

Loop:
// Loop through all syscall blocks and convert them to libcontainer format after filtering them
for _, call := range config.Syscalls {
Expand All @@ -110,6 +126,13 @@ Loop:
}
}
}
if call.Excludes.MinKernel != "" {
if ok, err := kernelGreaterEqualThan(call.Excludes.MinKernel); err != nil {
return nil, err
} else if ok {
continue Loop
}
}
if len(call.Includes.Arches) > 0 {
if !inSlice(call.Includes.Arches, arch) {
continue Loop
Expand All @@ -122,6 +145,13 @@ Loop:
}
}
}
if call.Includes.MinKernel != "" {
if ok, err := kernelGreaterEqualThan(call.Includes.MinKernel); err != nil {
return nil, err
} else if !ok {
continue Loop
}
}

if call.Name != "" && len(call.Names) != 0 {
return nil, errors.New("'name' and 'names' were specified in the seccomp profile, use either 'name' or 'names'")
Expand Down
7 changes: 7 additions & 0 deletions profiles/seccomp/seccomp_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ func DefaultProfile() *types.Seccomp {
Action: types.ActAllow,
Args: []*types.Arg{},
},
{
Names: []string{"ptrace"},
Action: types.ActAllow,
Includes: types.Filter{
MinKernel: "4.8.0",
},
},
{
Names: []string{"personality"},
Action: types.ActAllow,
Expand Down

0 comments on commit 1603af9

Please sign in to comment.