2015-08-25 02:30:45 +08:00
|
|
|
package seccomp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
|
|
)
|
|
|
|
|
2015-10-23 10:17:39 +08:00
|
|
|
var operators = map[string]configs.Operator{
|
|
|
|
"SCMP_CMP_NE": configs.NotEqualTo,
|
|
|
|
"SCMP_CMP_LT": configs.LessThan,
|
|
|
|
"SCMP_CMP_LE": configs.LessThanOrEqualTo,
|
|
|
|
"SCMP_CMP_EQ": configs.EqualTo,
|
|
|
|
"SCMP_CMP_GE": configs.GreaterThanOrEqualTo,
|
|
|
|
"SCMP_CMP_GT": configs.GreaterThan,
|
|
|
|
"SCMP_CMP_MASKED_EQ": configs.MaskEqualTo,
|
|
|
|
}
|
|
|
|
|
|
|
|
var actions = map[string]configs.Action{
|
|
|
|
"SCMP_ACT_KILL": configs.Kill,
|
|
|
|
"SCMP_ACT_ERRNO": configs.Errno,
|
|
|
|
"SCMP_ACT_TRAP": configs.Trap,
|
|
|
|
"SCMP_ACT_ALLOW": configs.Allow,
|
2015-11-13 09:03:53 +08:00
|
|
|
"SCMP_ACT_TRACE": configs.Trace,
|
2015-10-23 10:17:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var archs = map[string]string{
|
|
|
|
"SCMP_ARCH_X86": "x86",
|
|
|
|
"SCMP_ARCH_X86_64": "amd64",
|
|
|
|
"SCMP_ARCH_X32": "x32",
|
|
|
|
"SCMP_ARCH_ARM": "arm",
|
|
|
|
"SCMP_ARCH_AARCH64": "arm64",
|
|
|
|
"SCMP_ARCH_MIPS": "mips",
|
|
|
|
"SCMP_ARCH_MIPS64": "mips64",
|
|
|
|
"SCMP_ARCH_MIPS64N32": "mips64n32",
|
|
|
|
"SCMP_ARCH_MIPSEL": "mipsel",
|
|
|
|
"SCMP_ARCH_MIPSEL64": "mipsel64",
|
|
|
|
"SCMP_ARCH_MIPSEL64N32": "mipsel64n32",
|
|
|
|
}
|
|
|
|
|
2015-08-25 02:30:45 +08:00
|
|
|
// ConvertStringToOperator converts a string into a Seccomp comparison operator.
|
|
|
|
// Comparison operators use the names they are assigned by Libseccomp's header.
|
|
|
|
// Attempting to convert a string that is not a valid operator results in an
|
|
|
|
// error.
|
|
|
|
func ConvertStringToOperator(in string) (configs.Operator, error) {
|
2015-10-23 10:17:39 +08:00
|
|
|
if op, ok := operators[in]; ok == true {
|
|
|
|
return op, nil
|
2015-08-25 02:30:45 +08:00
|
|
|
}
|
2015-10-23 10:17:39 +08:00
|
|
|
return 0, fmt.Errorf("string %s is not a valid operator for seccomp", in)
|
2015-08-25 02:30:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertStringToAction converts a string into a Seccomp rule match action.
|
2015-10-08 21:44:23 +08:00
|
|
|
// Actions use the names they are assigned in Libseccomp's header, though some
|
2015-08-25 02:30:45 +08:00
|
|
|
// (notable, SCMP_ACT_TRACE) are not available in this implementation and will
|
|
|
|
// return errors.
|
|
|
|
// Attempting to convert a string that is not a valid action results in an
|
|
|
|
// error.
|
|
|
|
func ConvertStringToAction(in string) (configs.Action, error) {
|
2015-10-23 10:17:39 +08:00
|
|
|
if act, ok := actions[in]; ok == true {
|
|
|
|
return act, nil
|
|
|
|
}
|
|
|
|
return 0, fmt.Errorf("string %s is not a valid action for seccomp", in)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConvertStringToArch converts a string into a Seccomp comparison arch.
|
|
|
|
func ConvertStringToArch(in string) (string, error) {
|
|
|
|
if arch, ok := archs[in]; ok == true {
|
|
|
|
return arch, nil
|
2015-08-25 02:30:45 +08:00
|
|
|
}
|
2015-10-23 10:17:39 +08:00
|
|
|
return "", fmt.Errorf("string %s is not a valid arch for seccomp", in)
|
2015-08-25 02:30:45 +08:00
|
|
|
}
|