Skip to content

Commit a002fc8

Browse files
authored
Merge pull request #514 from q384566678/runtimetest-seccomp
runtimetest: add validateSeccomp
2 parents bb1f087 + 5bb8754 commit a002fc8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

cmd/runtimetest/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,30 @@ func validateMaskedPaths(spec *rspec.Spec) error {
576576
return nil
577577
}
578578

579+
func validateSeccomp(spec *rspec.Spec) error {
580+
if spec.Linux == nil || spec.Linux.Seccomp == nil {
581+
return nil
582+
}
583+
t := tap.New()
584+
for _, sys := range spec.Linux.Seccomp.Syscalls {
585+
if sys.Action == "SCMP_ACT_ERRNO" {
586+
for _, name := range sys.Names {
587+
if name == "getcwd" {
588+
_, err := os.Getwd()
589+
if err == nil {
590+
t.Diagnostic("getcwd did not return an error")
591+
}
592+
} else {
593+
t.Skip(1, fmt.Sprintf("%s syscall returns errno", name))
594+
}
595+
}
596+
} else {
597+
t.Skip(1, fmt.Sprintf("syscall action %s", sys.Action))
598+
}
599+
}
600+
return nil
601+
}
602+
579603
func validateROPaths(spec *rspec.Spec) error {
580604
if spec.Linux == nil {
581605
return nil
@@ -864,6 +888,10 @@ func run(context *cli.Context) error {
864888
test: validateOOMScoreAdj,
865889
description: "oom score adj",
866890
},
891+
{
892+
test: validateSeccomp,
893+
description: "seccomp",
894+
},
867895
{
868896
test: validateROPaths,
869897
description: "read only paths",

validation/linux_seccomp.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"github.com/opencontainers/runtime-tools/generate/seccomp"
5+
"github.com/opencontainers/runtime-tools/validation/util"
6+
)
7+
8+
func main() {
9+
g := util.GetDefaultGenerator()
10+
syscallArgs := seccomp.SyscallOpts{
11+
Action: "errno",
12+
Syscall: "getcwd",
13+
}
14+
g.SetDefaultSeccompAction("allow")
15+
g.SetSyscallAction(syscallArgs)
16+
err := util.RuntimeInsideValidate(g, nil)
17+
if err != nil {
18+
util.Fatal(err)
19+
}
20+
}

0 commit comments

Comments
 (0)