Skip to content

Commit 9006a28

Browse files
kolyshkinpcmoore
authored andcommitted
TestRuleAddAndLoad: fix for ppc
As reported in [1], the test fails on ppc64le since getpid(2) is not supposed to ever return an error, and somehow glibc relies on that assumption, and returns a positive value of error set by the seccomp rule from its getpid(2) wrapper. This makes the test fail. While seccomp_rule_add(3) man page was amended to note that behavior in [2], the test case here was never fixed so it always fails on ppc. Fix it by replacing getpid(2) with close(2). Make some other cosmetic changes while at it. The test case was tested to fail (when the corresponding FilterAddRule call is commented out): > seccomp_test.go:647: Syscall listen: want no space left on device, got socket operation on non-socket [1] #61 [2] seccomp/libseccomp#333 Signed-off-by: Kir Kolyshkin <[email protected]> Acked-by: Tom Hromatka <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 2722614 commit 9006a28

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

seccomp_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,14 @@ func subprocessRuleAddAndLoad(t *testing.T) {
590590
}
591591
defer filter1.Release()
592592

593-
call, err := GetSyscallFromName("getpid")
593+
const expErr = 28 // ENOSPC, but can be anything not usually returned by listen(2).
594+
call, err := GetSyscallFromName("listen")
594595
if err != nil {
595-
t.Errorf("Error getting syscall number of getpid: %s", err)
596+
t.Errorf("Error getting syscall number of listen: %s", err)
597+
}
598+
err = filter1.AddRule(call, ActErrno.SetReturnCode(expErr))
599+
if err != nil {
600+
t.Errorf("Error adding rule to restrict syscall: %s", err)
596601
}
597602

598603
call2, err := GetSyscallFromName("setreuid")
@@ -608,11 +613,6 @@ func subprocessRuleAddAndLoad(t *testing.T) {
608613
uid := syscall.Getuid()
609614
euid := syscall.Geteuid()
610615

611-
err = filter1.AddRule(call, ActErrno.SetReturnCode(0x1))
612-
if err != nil {
613-
t.Errorf("Error adding rule to restrict syscall: %s", err)
614-
}
615-
616616
cond, err := MakeCondition(1, CompareEqual, uint64(euid))
617617
if err != nil {
618618
t.Errorf("Error making rule to restrict syscall: %s", err)
@@ -640,10 +640,9 @@ func subprocessRuleAddAndLoad(t *testing.T) {
640640
t.Errorf("Error loading filter: %s", err)
641641
}
642642

643-
// Try making a simple syscall, it should error
644-
pid := syscall.Getpid()
645-
if pid != -1 {
646-
t.Errorf("Syscall should have returned error code!")
643+
// Try making a simple syscall which should return an error.
644+
if err := syscall.Listen(0, 0); err != syscall.Errno(expErr) {
645+
t.Errorf("Syscall listen: want %v, got %v", syscall.Errno(expErr), err)
647646
}
648647

649648
// Try making a Geteuid syscall that should normally succeed

0 commit comments

Comments
 (0)