Skip to content

Commit 4907259

Browse files
author
Zhou Hao
committed
runtimetest: add validateSeccomp
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
1 parent d445714 commit 4907259

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

cmd/runtimetest/main.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,28 @@ 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 i, name := range sys.Names {
587+
if name == "getcwd" {
588+
_, err := os.Getwd()
589+
if err == nil {
590+
t.Diagnostic("Syscall action ERRNO can not be properly applied in the runtime")
591+
}
592+
} else {
593+
t.Skip(i, fmt.Sprintf("%s syscall returns errno", name))
594+
}
595+
}
596+
}
597+
}
598+
return nil
599+
}
600+
579601
func validateROPaths(spec *rspec.Spec) error {
580602
if spec.Linux == nil {
581603
return nil
@@ -864,6 +886,10 @@ func run(context *cli.Context) error {
864886
test: validateOOMScoreAdj,
865887
description: "oom score adj",
866888
},
889+
{
890+
test: validateSeccomp,
891+
description: "seccomp",
892+
},
867893
{
868894
test: validateROPaths,
869895
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)