Skip to content

Commit e5df66e

Browse files
ratapcmoore
authored andcommitted
all: remove SetTsync()
Now that we don't allow seccomp notify without tsync, we require apiLevel 6 (simultaneous use of SCMP_FLTATR_CTL_TSYNC and the notify APIs.) Also, revert documentation changes to NewFilter to remove reference to SetTsync(). Signed-off-by: Rodrigo Campos <[email protected]> Acked-by: Tom Hromatka <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent b5fd076 commit e5df66e

File tree

4 files changed

+22
-62
lines changed

4 files changed

+22
-62
lines changed

Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,8 @@ vet:
2424
# be noticed earlier in the CI.
2525
TEST_TIMEOUT=10s
2626

27-
# Some tests run with SetTsync(false) and some tests with SetTsync(true). Once
28-
# the threads are not using the same seccomp filters anymore, the kernel will
29-
# refuse to use Tsync, causing next tests to fail. This issue could be left
30-
# unnoticed if the test with SetTsync(false) is executed last.
31-
#
32-
# Run tests twice ensure that no test leave the testing process in a state
33-
# unable to run following tests, regardless of the subset of tests selected.
34-
TEST_COUNT=2
35-
3627
test:
37-
go test -v -timeout $(TEST_TIMEOUT) -count $(TEST_COUNT)
28+
go test -v -timeout $(TEST_TIMEOUT)
3829

3930
lint:
4031
@$(if $(shell which golint),true,$(error "install golint and include it in your PATH"))

seccomp.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const (
200200
// ActTrap throws SIGSYS
201201
ActTrap ScmpAction = iota
202202
// ActNotify triggers a userspace notification. This action is only usable when
203-
// libseccomp API level 5 or higher is supported.
203+
// libseccomp API level 6 or higher is supported.
204204
ActNotify ScmpAction = iota
205205
// ActErrno causes the syscall to return a negative error code. This
206206
// code can be set with the SetReturnCode method
@@ -604,9 +604,7 @@ type ScmpFilter struct {
604604
}
605605

606606
// NewFilter creates and returns a new filter context. Accepts a default action to be
607-
// taken for syscalls which match no rules in the filter. The newly created filter applies
608-
// to all threads of the calling process. Use SetTsync() to change this behavior prior to
609-
// loading the filter.
607+
// taken for syscalls which match no rules in the filter.
610608
// Returns a reference to a valid filter context, or nil and an error
611609
// if the filter context could not be created or an invalid default action was given.
612610
func NewFilter(defaultAction ScmpAction) (*ScmpFilter, error) {
@@ -638,27 +636,6 @@ func NewFilter(defaultAction ScmpAction) (*ScmpFilter, error) {
638636
return filter, nil
639637
}
640638

641-
// SetTsync sets or clears the filter's thread-sync (TSYNC) attribute. When set, this attribute
642-
// tells the kernel to synchronize all threads of the calling process to the same seccomp filter.
643-
// When using filters with the seccomp notification action (ActNotify), the TSYNC attribute
644-
// must be cleared prior to loading the filter. Refer to the seccomp manual page (seccomp(2)) for
645-
// further details.
646-
func (f *ScmpFilter) SetTsync(val bool) error {
647-
var cval C.uint32_t
648-
649-
if val == true {
650-
cval = 1
651-
} else {
652-
cval = 0
653-
}
654-
655-
err := f.setFilterAttr(filterAttrTsync, cval)
656-
if err != nil && val == false && err == syscall.ENOTSUP {
657-
return nil
658-
}
659-
return err
660-
}
661-
662639
// IsValid determines whether a filter context is valid to use.
663640
// Some operations (Release and Merge) render filter contexts invalid and
664641
// consequently prevent further use.

seccomp_internal.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ func (f *ScmpFilter) getNotifFd() (ScmpFd, error) {
737737

738738
// Ignore error, if not supported returns apiLevel == 0
739739
apiLevel, _ := GetAPI()
740-
if apiLevel < 5 {
741-
return -1, fmt.Errorf("seccomp notification requires API level >= 5; current level = %d", apiLevel)
740+
if apiLevel < 6 {
741+
return -1, fmt.Errorf("seccomp notification requires API level >= 6; current level = %d", apiLevel)
742742
}
743743

744744
fd := C.seccomp_notify_fd(f.filterCtx)
@@ -752,8 +752,8 @@ func notifReceive(fd ScmpFd) (*ScmpNotifReq, error) {
752752

753753
// Ignore error, if not supported returns apiLevel == 0
754754
apiLevel, _ := GetAPI()
755-
if apiLevel < 5 {
756-
return nil, fmt.Errorf("seccomp notification requires API level >= 5; current level = %d", apiLevel)
755+
if apiLevel < 6 {
756+
return nil, fmt.Errorf("seccomp notification requires API level >= 6; current level = %d", apiLevel)
757757
}
758758

759759
// we only use the request here; the response is unused
@@ -778,8 +778,8 @@ func notifRespond(fd ScmpFd, scmpResp *ScmpNotifResp) error {
778778

779779
// Ignore error, if not supported returns apiLevel == 0
780780
apiLevel, _ := GetAPI()
781-
if apiLevel < 5 {
782-
return fmt.Errorf("seccomp notification requires API level >= 5; current level = %d", apiLevel)
781+
if apiLevel < 6 {
782+
return fmt.Errorf("seccomp notification requires API level >= 6; current level = %d", apiLevel)
783783
}
784784

785785
// we only use the reponse here; the request is discarded
@@ -803,8 +803,8 @@ func notifRespond(fd ScmpFd, scmpResp *ScmpNotifResp) error {
803803
func notifIDValid(fd ScmpFd, id uint64) error {
804804
// Ignore error, if not supported returns apiLevel == 0
805805
apiLevel, _ := GetAPI()
806-
if apiLevel < 5 {
807-
return fmt.Errorf("seccomp notification requires API level >= 5; current level = %d", apiLevel)
806+
if apiLevel < 6 {
807+
return fmt.Errorf("seccomp notification requires API level >= 6; current level = %d", apiLevel)
808808
}
809809

810810
if retCode := C.seccomp_notify_id_valid(C.int(fd), C.uint64_t(id)); retCode != 0 {

seccomp_test.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"os"
1010
"os/exec"
11-
"runtime"
1211
"strings"
1312
"syscall"
1413
"testing"
@@ -843,7 +842,7 @@ func TestNotif(t *testing.T) {
843842
execInSubprocess(t, subprocessNotif)
844843
}
845844
func subprocessNotif(t *testing.T) {
846-
// seccomp notification requires API level >= 5
845+
// seccomp notification requires API level >= 6
847846
api, err := GetAPI()
848847
if err != nil {
849848
if !APILevelIsSupported() {
@@ -853,10 +852,10 @@ func subprocessNotif(t *testing.T) {
853852
t.Errorf("Error getting API level: %s", err)
854853
} else {
855854
t.Logf("Got API level %v", api)
856-
if api < 5 {
857-
err = SetAPI(5)
855+
if api < 6 {
856+
err = SetAPI(6)
858857
if err != nil {
859-
t.Skipf("Skipping test: API level %d is less than 5 and could not set it to 5", api)
858+
t.Skipf("Skipping test: API level %d is less than 6 and could not set it to 6", api)
860859
return
861860
}
862861
}
@@ -874,18 +873,16 @@ func subprocessNotif(t *testing.T) {
874873
return
875874
}
876875

876+
// Create a filter that only notifies on chdir. This way, while the
877+
// seccomp filter applies to all threads, we can run the target and
878+
// handling in different go routines with no problem as only the target
879+
// goroutine uses chdir.
877880
filter, err := NewFilter(ActAllow)
878881
if err != nil {
879882
t.Errorf("Error creating filter: %s", err)
880883
}
881884
defer filter.Release()
882885

883-
// Seccomp notification is only supported on single-thread filters
884-
err = filter.SetTsync(false)
885-
if err != nil {
886-
t.Errorf("Error setting tsync on filter: %s", err)
887-
}
888-
889886
call, err := GetSyscallFromName("chdir")
890887
if err != nil {
891888
t.Errorf("Error getting syscall number: %s", err)
@@ -954,11 +951,6 @@ func subprocessNotif(t *testing.T) {
954951
done := make(chan struct{})
955952

956953
go func() {
957-
// Lock this goroutine to it's current kernel thread; otherwise the go runtime may
958-
// switch us to a different OS thread, bypassing the seccomp notification filter.
959-
runtime.LockOSThread()
960-
defer runtime.UnlockOSThread()
961-
962954
err = filter.Load()
963955
if err != nil {
964956
t.Errorf("Error loading filter: %s", err)
@@ -1017,14 +1009,14 @@ func TestNotifUnsupported(t *testing.T) {
10171009
execInSubprocess(t, subprocessNotifUnsupported)
10181010
}
10191011
func subprocessNotifUnsupported(t *testing.T) {
1020-
// seccomp notification requires API level >= 5
1012+
// seccomp notification requires API level >= 6
10211013
api := 0
10221014
if APILevelIsSupported() {
10231015
api, err := GetAPI()
10241016
if err != nil {
10251017
t.Errorf("Error getting API level: %s", err)
1026-
} else if api >= 5 {
1027-
t.Skipf("Skipping test for old libseccomp support: API level %d is >= 5", api)
1018+
} else if api >= 6 {
1019+
t.Skipf("Skipping test for old libseccomp support: API level %d is >= 6", api)
10281020
}
10291021
}
10301022

0 commit comments

Comments
 (0)