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

BUG: AddRule: fix to handle EACCES #74

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions seccomp_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package seccomp

import (
"errors"
"fmt"
"syscall"
)
Expand Down Expand Up @@ -295,8 +296,9 @@ const (
)

var (
// Error thrown on bad filter context
errBadFilter = fmt.Errorf("filter is invalid or uninitialized")
// errBadFilter is thrown on bad filter context.
errBadFilter = errors.New("filter is invalid or uninitialized")
errDefAction = errors.New("requested action matches default action of filter")
// Constants representing library major, minor, and micro versions
verMajor = uint(C.get_major_version())
verMinor = uint(C.get_minor_version())
Expand Down Expand Up @@ -414,8 +416,10 @@ func (f *ScmpFilter) addRuleWrapper(call ScmpSyscall, action ScmpAction, exact b
switch e := errRc(retCode); e {
case syscall.EFAULT:
return fmt.Errorf("unrecognized syscall %#x", int32(call))
case syscall.EPERM:
return fmt.Errorf("requested action matches default action of filter")
// libseccomp >= v2.5.0 returns EACCES, older versions return EPERM.
// TODO: remove EPERM once libseccomp < v2.5.0 is not supported.
case syscall.EPERM, syscall.EACCES:
return errDefAction
case syscall.EINVAL:
return fmt.Errorf("two checks on same syscall argument")
default:
Expand Down
19 changes: 19 additions & 0 deletions seccomp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,25 @@ func TestMergeFilters(t *testing.T) {
}
}

func TestAddRuleErrors(t *testing.T) {
execInSubprocess(t, subprocessAddRuleErrors)
}

func subprocessAddRuleErrors(t *testing.T) {
filter, err := NewFilter(ActAllow)
if err != nil {
t.Errorf("Error creating filter: %s", err)
}
defer filter.Release()

err = filter.AddRule(ScmpSyscall(0x1), ActAllow)
if err == nil {
t.Error("expected error, got nil")
} else if err != errDefAction {
t.Errorf("expected error %v, got %v", errDefAction, err)
}
}

func TestRuleAddAndLoad(t *testing.T) {
execInSubprocess(t, subprocessRuleAddAndLoad)
}
Expand Down