Skip to content

Commit 3f1f3ca

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

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cmd/runtimetest/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,25 @@ func validateMaskedPaths(spec *rspec.Spec) error {
496496
return nil
497497
}
498498

499+
func validateSeccomp(spec *rspec.Spec) error {
500+
if spec.Linux == nil || spec.Linux.Seccomp == nil {
501+
return nil
502+
}
503+
for _, sys := range spec.Linux.Seccomp.Syscalls {
504+
if sys.Action == "SCMP_ACT_ERRON" {
505+
for _, name := range sys.Names {
506+
if name == "getcwd" {
507+
_, err := os.Getwd()
508+
if err == nil {
509+
logrus.Warnf("Syscall action %v can not be properly implemented in the runtime", sys.Action)
510+
}
511+
}
512+
}
513+
}
514+
}
515+
return nil
516+
}
517+
499518
func validateROPaths(spec *rspec.Spec) error {
500519
if spec.Linux == nil {
501520
return nil
@@ -775,6 +794,10 @@ func run(context *cli.Context) error {
775794
test: validateOOMScoreAdj,
776795
description: "oom score adj",
777796
},
797+
{
798+
test: validateSeccomp,
799+
description: "seccomp",
800+
},
778801
{
779802
test: validateROPaths,
780803
description: "read only paths",

validation/validation_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/stretchr/testify/assert"
1616

1717
"github.com/opencontainers/runtime-tools/generate"
18+
"github.com/opencontainers/runtime-tools/generate/seccomp"
1819
"github.com/opencontainers/runtime-tools/specerror"
1920
)
2021

@@ -130,6 +131,19 @@ func TestValidateRlimits(t *testing.T) {
130131
assert.Nil(t, runtimeInsideValidate(g))
131132
}
132133

134+
// Test whether seccomp can be applied or not
135+
func TestValidateSeccomp(t *testing.T) {
136+
g := getDefaultGenerator()
137+
syscallArgs := seccomp.SyscallOpts{
138+
Action: "errno",
139+
Syscall: "getcwd",
140+
}
141+
g.SetDefaultSeccompAction("allow")
142+
g.SetSyscallAction(syscallArgs)
143+
144+
assert.Nil(t, runtimeInsideValidate(g))
145+
}
146+
133147
// Test whether sysctls can be applied or not
134148
func TestValidateSysctls(t *testing.T) {
135149
g := getDefaultGenerator()

0 commit comments

Comments
 (0)