|
@@ -7,7 +7,6 @@ package seccomp
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
- "os"
|
|
|
|
"syscall"
|
|
"syscall"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -17,47 +16,20 @@ import (
|
|
|
|
|
|
// #cgo pkg-config: libseccomp
|
|
// #cgo pkg-config: libseccomp
|
|
/*
|
|
/*
|
|
|
|
+#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
#include <seccomp.h>
|
|
#include <seccomp.h>
|
|
|
|
|
|
#if SCMP_VER_MAJOR < 2
|
|
#if SCMP_VER_MAJOR < 2
|
|
-#error Minimum supported version of Libseccomp is v2.1.0
|
|
|
|
-#elif SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 1
|
|
|
|
-#error Minimum supported version of Libseccomp is v2.1.0
|
|
|
|
|
|
+#error Minimum supported version of Libseccomp is v2.2.0
|
|
|
|
+#elif SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 2
|
|
|
|
+#error Minimum supported version of Libseccomp is v2.2.0
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#define ARCH_BAD ~0
|
|
#define ARCH_BAD ~0
|
|
|
|
|
|
const uint32_t C_ARCH_BAD = ARCH_BAD;
|
|
const uint32_t C_ARCH_BAD = ARCH_BAD;
|
|
|
|
|
|
-#ifndef SCMP_ARCH_AARCH64
|
|
|
|
-#define SCMP_ARCH_AARCH64 ARCH_BAD
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifndef SCMP_ARCH_MIPS
|
|
|
|
-#define SCMP_ARCH_MIPS ARCH_BAD
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifndef SCMP_ARCH_MIPS64
|
|
|
|
-#define SCMP_ARCH_MIPS64 ARCH_BAD
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifndef SCMP_ARCH_MIPS64N32
|
|
|
|
-#define SCMP_ARCH_MIPS64N32 ARCH_BAD
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifndef SCMP_ARCH_MIPSEL
|
|
|
|
-#define SCMP_ARCH_MIPSEL ARCH_BAD
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifndef SCMP_ARCH_MIPSEL64
|
|
|
|
-#define SCMP_ARCH_MIPSEL64 ARCH_BAD
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifndef SCMP_ARCH_MIPSEL64N32
|
|
|
|
-#define SCMP_ARCH_MIPSEL64N32 ARCH_BAD
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
#ifndef SCMP_ARCH_PPC
|
|
#ifndef SCMP_ARCH_PPC
|
|
#define SCMP_ARCH_PPC ARCH_BAD
|
|
#define SCMP_ARCH_PPC ARCH_BAD
|
|
#endif
|
|
#endif
|
|
@@ -96,22 +68,29 @@ const uint32_t C_ARCH_PPC64LE = SCMP_ARCH_PPC64LE;
|
|
const uint32_t C_ARCH_S390 = SCMP_ARCH_S390;
|
|
const uint32_t C_ARCH_S390 = SCMP_ARCH_S390;
|
|
const uint32_t C_ARCH_S390X = SCMP_ARCH_S390X;
|
|
const uint32_t C_ARCH_S390X = SCMP_ARCH_S390X;
|
|
|
|
|
|
|
|
+#ifndef SCMP_ACT_LOG
|
|
|
|
+#define SCMP_ACT_LOG 0x7ffc0000U
|
|
|
|
+#endif
|
|
|
|
+
|
|
const uint32_t C_ACT_KILL = SCMP_ACT_KILL;
|
|
const uint32_t C_ACT_KILL = SCMP_ACT_KILL;
|
|
const uint32_t C_ACT_TRAP = SCMP_ACT_TRAP;
|
|
const uint32_t C_ACT_TRAP = SCMP_ACT_TRAP;
|
|
const uint32_t C_ACT_ERRNO = SCMP_ACT_ERRNO(0);
|
|
const uint32_t C_ACT_ERRNO = SCMP_ACT_ERRNO(0);
|
|
const uint32_t C_ACT_TRACE = SCMP_ACT_TRACE(0);
|
|
const uint32_t C_ACT_TRACE = SCMP_ACT_TRACE(0);
|
|
|
|
+const uint32_t C_ACT_LOG = SCMP_ACT_LOG;
|
|
const uint32_t C_ACT_ALLOW = SCMP_ACT_ALLOW;
|
|
const uint32_t C_ACT_ALLOW = SCMP_ACT_ALLOW;
|
|
|
|
|
|
-// If TSync is not supported, make sure it doesn't map to a supported filter attribute
|
|
|
|
-// Don't worry about major version < 2, the minimum version checks should catch that case
|
|
|
|
-#if SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 2
|
|
|
|
-#define SCMP_FLTATR_CTL_TSYNC _SCMP_CMP_MIN
|
|
|
|
|
|
+// The libseccomp SCMP_FLTATR_CTL_LOG member of the scmp_filter_attr enum was
|
|
|
|
+// added in v2.4.0
|
|
|
|
+#if (SCMP_VER_MAJOR < 2) || \
|
|
|
|
+ (SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 4)
|
|
|
|
+#define SCMP_FLTATR_CTL_LOG _SCMP_FLTATR_MIN
|
|
#endif
|
|
#endif
|
|
|
|
|
|
const uint32_t C_ATTRIBUTE_DEFAULT = (uint32_t)SCMP_FLTATR_ACT_DEFAULT;
|
|
const uint32_t C_ATTRIBUTE_DEFAULT = (uint32_t)SCMP_FLTATR_ACT_DEFAULT;
|
|
const uint32_t C_ATTRIBUTE_BADARCH = (uint32_t)SCMP_FLTATR_ACT_BADARCH;
|
|
const uint32_t C_ATTRIBUTE_BADARCH = (uint32_t)SCMP_FLTATR_ACT_BADARCH;
|
|
const uint32_t C_ATTRIBUTE_NNP = (uint32_t)SCMP_FLTATR_CTL_NNP;
|
|
const uint32_t C_ATTRIBUTE_NNP = (uint32_t)SCMP_FLTATR_CTL_NNP;
|
|
const uint32_t C_ATTRIBUTE_TSYNC = (uint32_t)SCMP_FLTATR_CTL_TSYNC;
|
|
const uint32_t C_ATTRIBUTE_TSYNC = (uint32_t)SCMP_FLTATR_CTL_TSYNC;
|
|
|
|
+const uint32_t C_ATTRIBUTE_LOG = (uint32_t)SCMP_FLTATR_CTL_LOG;
|
|
|
|
|
|
const int C_CMP_NE = (int)SCMP_CMP_NE;
|
|
const int C_CMP_NE = (int)SCMP_CMP_NE;
|
|
const int C_CMP_LT = (int)SCMP_CMP_LT;
|
|
const int C_CMP_LT = (int)SCMP_CMP_LT;
|
|
@@ -125,25 +104,80 @@ const int C_VERSION_MAJOR = SCMP_VER_MAJOR;
|
|
const int C_VERSION_MINOR = SCMP_VER_MINOR;
|
|
const int C_VERSION_MINOR = SCMP_VER_MINOR;
|
|
const int C_VERSION_MICRO = SCMP_VER_MICRO;
|
|
const int C_VERSION_MICRO = SCMP_VER_MICRO;
|
|
|
|
|
|
|
|
+#if SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR >= 3
|
|
|
|
+unsigned int get_major_version()
|
|
|
|
+{
|
|
|
|
+ return seccomp_version()->major;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+unsigned int get_minor_version()
|
|
|
|
+{
|
|
|
|
+ return seccomp_version()->minor;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+unsigned int get_micro_version()
|
|
|
|
+{
|
|
|
|
+ return seccomp_version()->micro;
|
|
|
|
+}
|
|
|
|
+#else
|
|
|
|
+unsigned int get_major_version()
|
|
|
|
+{
|
|
|
|
+ return (unsigned int)C_VERSION_MAJOR;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+unsigned int get_minor_version()
|
|
|
|
+{
|
|
|
|
+ return (unsigned int)C_VERSION_MINOR;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+unsigned int get_micro_version()
|
|
|
|
+{
|
|
|
|
+ return (unsigned int)C_VERSION_MICRO;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+// The libseccomp API level functions were added in v2.4.0
|
|
|
|
+#if (SCMP_VER_MAJOR < 2) || \
|
|
|
|
+ (SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 4)
|
|
|
|
+const unsigned int seccomp_api_get(void)
|
|
|
|
+{
|
|
|
|
+ // libseccomp-golang requires libseccomp v2.2.0, at a minimum, which
|
|
|
|
+ // supported API level 2. However, the kernel may not support API level
|
|
|
|
+ // 2 constructs which are the seccomp() system call and the TSYNC
|
|
|
|
+ // filter flag. Return the "reserved" value of 0 here to indicate that
|
|
|
|
+ // proper API level support is not available in libseccomp.
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int seccomp_api_set(unsigned int level)
|
|
|
|
+{
|
|
|
|
+ return -EOPNOTSUPP;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
typedef struct scmp_arg_cmp* scmp_cast_t;
|
|
typedef struct scmp_arg_cmp* scmp_cast_t;
|
|
|
|
|
|
-// Wrapper to create an scmp_arg_cmp struct
|
|
|
|
-void*
|
|
|
|
-make_struct_arg_cmp(
|
|
|
|
- unsigned int arg,
|
|
|
|
- int compare,
|
|
|
|
- uint64_t a,
|
|
|
|
- uint64_t b
|
|
|
|
- )
|
|
|
|
|
|
+void* make_arg_cmp_array(unsigned int length)
|
|
{
|
|
{
|
|
- struct scmp_arg_cmp *s = malloc(sizeof(struct scmp_arg_cmp));
|
|
|
|
|
|
+ return calloc(length, sizeof(struct scmp_arg_cmp));
|
|
|
|
+}
|
|
|
|
|
|
- s->arg = arg;
|
|
|
|
- s->op = compare;
|
|
|
|
- s->datum_a = a;
|
|
|
|
- s->datum_b = b;
|
|
|
|
|
|
+// Wrapper to add an scmp_arg_cmp struct to an existing arg_cmp array
|
|
|
|
+void add_struct_arg_cmp(
|
|
|
|
+ struct scmp_arg_cmp* arr,
|
|
|
|
+ unsigned int pos,
|
|
|
|
+ unsigned int arg,
|
|
|
|
+ int compare,
|
|
|
|
+ uint64_t a,
|
|
|
|
+ uint64_t b
|
|
|
|
+ )
|
|
|
|
+{
|
|
|
|
+ arr[pos].arg = arg;
|
|
|
|
+ arr[pos].op = compare;
|
|
|
|
+ arr[pos].datum_a = a;
|
|
|
|
+ arr[pos].datum_b = b;
|
|
|
|
|
|
- return s;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
import "C"
|
|
import "C"
|
|
@@ -158,6 +192,7 @@ const (
|
|
filterAttrActBadArch scmpFilterAttr = iota
|
|
filterAttrActBadArch scmpFilterAttr = iota
|
|
filterAttrNNP scmpFilterAttr = iota
|
|
filterAttrNNP scmpFilterAttr = iota
|
|
filterAttrTsync scmpFilterAttr = iota
|
|
filterAttrTsync scmpFilterAttr = iota
|
|
|
|
+ filterAttrLog scmpFilterAttr = iota
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -168,7 +203,7 @@ const (
|
|
archEnd ScmpArch = ArchS390X
|
|
archEnd ScmpArch = ArchS390X
|
|
// Comparison boundaries to check for action validity
|
|
// Comparison boundaries to check for action validity
|
|
actionStart ScmpAction = ActKill
|
|
actionStart ScmpAction = ActKill
|
|
- actionEnd ScmpAction = ActAllow
|
|
|
|
|
|
+ actionEnd ScmpAction = ActLog
|
|
// Comparison boundaries to check for comparison operator validity
|
|
// Comparison boundaries to check for comparison operator validity
|
|
compareOpStart ScmpCompareOp = CompareNotEqual
|
|
compareOpStart ScmpCompareOp = CompareNotEqual
|
|
compareOpEnd ScmpCompareOp = CompareMaskedEqual
|
|
compareOpEnd ScmpCompareOp = CompareMaskedEqual
|
|
@@ -178,26 +213,49 @@ var (
|
|
// Error thrown on bad filter context
|
|
// Error thrown on bad filter context
|
|
errBadFilter = fmt.Errorf("filter is invalid or uninitialized")
|
|
errBadFilter = fmt.Errorf("filter is invalid or uninitialized")
|
|
// Constants representing library major, minor, and micro versions
|
|
// Constants representing library major, minor, and micro versions
|
|
- verMajor = int(C.C_VERSION_MAJOR)
|
|
|
|
- verMinor = int(C.C_VERSION_MINOR)
|
|
|
|
- verMicro = int(C.C_VERSION_MICRO)
|
|
|
|
|
|
+ verMajor = uint(C.get_major_version())
|
|
|
|
+ verMinor = uint(C.get_minor_version())
|
|
|
|
+ verMicro = uint(C.get_micro_version())
|
|
)
|
|
)
|
|
|
|
|
|
// Nonexported functions
|
|
// Nonexported functions
|
|
|
|
|
|
// Check if library version is greater than or equal to the given one
|
|
// Check if library version is greater than or equal to the given one
|
|
-func checkVersionAbove(major, minor, micro int) bool {
|
|
|
|
|
|
+func checkVersionAbove(major, minor, micro uint) bool {
|
|
return (verMajor > major) ||
|
|
return (verMajor > major) ||
|
|
(verMajor == major && verMinor > minor) ||
|
|
(verMajor == major && verMinor > minor) ||
|
|
(verMajor == major && verMinor == minor && verMicro >= micro)
|
|
(verMajor == major && verMinor == minor && verMicro >= micro)
|
|
}
|
|
}
|
|
|
|
|
|
-// Init function: Verify library version is appropriate
|
|
|
|
-func init() {
|
|
|
|
- if !checkVersionAbove(2, 1, 0) {
|
|
|
|
- fmt.Fprintf(os.Stderr, "Libseccomp version too low: minimum supported is 2.1.0, detected %d.%d.%d", C.C_VERSION_MAJOR, C.C_VERSION_MINOR, C.C_VERSION_MICRO)
|
|
|
|
- os.Exit(-1)
|
|
|
|
|
|
+// Ensure that the library is supported, i.e. >= 2.2.0.
|
|
|
|
+func ensureSupportedVersion() error {
|
|
|
|
+ if !checkVersionAbove(2, 2, 0) {
|
|
|
|
+ return VersionError{}
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Get the API level
|
|
|
|
+func getApi() (uint, error) {
|
|
|
|
+ api := C.seccomp_api_get()
|
|
|
|
+ if api == 0 {
|
|
|
|
+ return 0, fmt.Errorf("API level operations are not supported")
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return uint(api), nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// Set the API level
|
|
|
|
+func setApi(api uint) error {
|
|
|
|
+ if retCode := C.seccomp_api_set(C.uint(api)); retCode != 0 {
|
|
|
|
+ if syscall.Errno(-1*retCode) == syscall.EOPNOTSUPP {
|
|
|
|
+ return fmt.Errorf("API level operations are not supported")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fmt.Errorf("could not set API level: %v", retCode)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
|
|
|
|
// Filter helpers
|
|
// Filter helpers
|
|
@@ -216,10 +274,6 @@ func (f *ScmpFilter) getFilterAttr(attr scmpFilterAttr) (C.uint32_t, error) {
|
|
return 0x0, errBadFilter
|
|
return 0x0, errBadFilter
|
|
}
|
|
}
|
|
|
|
|
|
- if !checkVersionAbove(2, 2, 0) && attr == filterAttrTsync {
|
|
|
|
- return 0x0, fmt.Errorf("the thread synchronization attribute is not supported in this version of the library")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
var attribute C.uint32_t
|
|
var attribute C.uint32_t
|
|
|
|
|
|
retCode := C.seccomp_attr_get(f.filterCtx, attr.toNative(), &attribute)
|
|
retCode := C.seccomp_attr_get(f.filterCtx, attr.toNative(), &attribute)
|
|
@@ -239,10 +293,6 @@ func (f *ScmpFilter) setFilterAttr(attr scmpFilterAttr, value C.uint32_t) error
|
|
return errBadFilter
|
|
return errBadFilter
|
|
}
|
|
}
|
|
|
|
|
|
- if !checkVersionAbove(2, 2, 0) && attr == filterAttrTsync {
|
|
|
|
- return fmt.Errorf("the thread synchronization attribute is not supported in this version of the library")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
retCode := C.seccomp_attr_set(f.filterCtx, attr.toNative(), value)
|
|
retCode := C.seccomp_attr_set(f.filterCtx, attr.toNative(), value)
|
|
if retCode != 0 {
|
|
if retCode != 0 {
|
|
return syscall.Errno(-1 * retCode)
|
|
return syscall.Errno(-1 * retCode)
|
|
@@ -254,12 +304,9 @@ func (f *ScmpFilter) setFilterAttr(attr scmpFilterAttr, value C.uint32_t) error
|
|
// DOES NOT LOCK OR CHECK VALIDITY
|
|
// DOES NOT LOCK OR CHECK VALIDITY
|
|
// Assumes caller has already done this
|
|
// Assumes caller has already done this
|
|
// Wrapper for seccomp_rule_add_... functions
|
|
// Wrapper for seccomp_rule_add_... functions
|
|
-func (f *ScmpFilter) addRuleWrapper(call ScmpSyscall, action ScmpAction, exact bool, cond C.scmp_cast_t) error {
|
|
|
|
- var length C.uint
|
|
|
|
- if cond != nil {
|
|
|
|
- length = 1
|
|
|
|
- } else {
|
|
|
|
- length = 0
|
|
|
|
|
|
+func (f *ScmpFilter) addRuleWrapper(call ScmpSyscall, action ScmpAction, exact bool, length C.uint, cond C.scmp_cast_t) error {
|
|
|
|
+ if length != 0 && cond == nil {
|
|
|
|
+ return fmt.Errorf("null conditions list, but length is nonzero")
|
|
}
|
|
}
|
|
|
|
|
|
var retCode C.int
|
|
var retCode C.int
|
|
@@ -270,9 +317,11 @@ func (f *ScmpFilter) addRuleWrapper(call ScmpSyscall, action ScmpAction, exact b
|
|
}
|
|
}
|
|
|
|
|
|
if syscall.Errno(-1*retCode) == syscall.EFAULT {
|
|
if syscall.Errno(-1*retCode) == syscall.EFAULT {
|
|
- return fmt.Errorf("unrecognized syscall")
|
|
|
|
|
|
+ return fmt.Errorf("unrecognized syscall %#x", int32(call))
|
|
} else if syscall.Errno(-1*retCode) == syscall.EPERM {
|
|
} else if syscall.Errno(-1*retCode) == syscall.EPERM {
|
|
return fmt.Errorf("requested action matches default action of filter")
|
|
return fmt.Errorf("requested action matches default action of filter")
|
|
|
|
+ } else if syscall.Errno(-1*retCode) == syscall.EINVAL {
|
|
|
|
+ return fmt.Errorf("two checks on same syscall argument")
|
|
} else if retCode != 0 {
|
|
} else if retCode != 0 {
|
|
return syscall.Errno(-1 * retCode)
|
|
return syscall.Errno(-1 * retCode)
|
|
}
|
|
}
|
|
@@ -290,22 +339,32 @@ func (f *ScmpFilter) addRuleGeneric(call ScmpSyscall, action ScmpAction, exact b
|
|
}
|
|
}
|
|
|
|
|
|
if len(conds) == 0 {
|
|
if len(conds) == 0 {
|
|
- if err := f.addRuleWrapper(call, action, exact, nil); err != nil {
|
|
|
|
|
|
+ if err := f.addRuleWrapper(call, action, exact, 0, nil); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// We don't support conditional filtering in library version v2.1
|
|
// We don't support conditional filtering in library version v2.1
|
|
if !checkVersionAbove(2, 2, 1) {
|
|
if !checkVersionAbove(2, 2, 1) {
|
|
- return fmt.Errorf("conditional filtering requires libseccomp version >= 2.2.1")
|
|
|
|
|
|
+ return VersionError{
|
|
|
|
+ message: "conditional filtering is not supported",
|
|
|
|
+ minimum: "2.2.1",
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ argsArr := C.make_arg_cmp_array(C.uint(len(conds)))
|
|
|
|
+ if argsArr == nil {
|
|
|
|
+ return fmt.Errorf("error allocating memory for conditions")
|
|
}
|
|
}
|
|
|
|
+ defer C.free(argsArr)
|
|
|
|
|
|
- for _, cond := range conds {
|
|
|
|
- cmpStruct := C.make_struct_arg_cmp(C.uint(cond.Argument), cond.Op.toNative(), C.uint64_t(cond.Operand1), C.uint64_t(cond.Operand2))
|
|
|
|
- defer C.free(cmpStruct)
|
|
|
|
|
|
+ for i, cond := range conds {
|
|
|
|
+ C.add_struct_arg_cmp(C.scmp_cast_t(argsArr), C.uint(i),
|
|
|
|
+ C.uint(cond.Argument), cond.Op.toNative(),
|
|
|
|
+ C.uint64_t(cond.Operand1), C.uint64_t(cond.Operand2))
|
|
|
|
+ }
|
|
|
|
|
|
- if err := f.addRuleWrapper(call, action, exact, C.scmp_cast_t(cmpStruct)); err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
|
|
+ if err := f.addRuleWrapper(call, action, exact, C.uint(len(conds)), C.scmp_cast_t(argsArr)); err != nil {
|
|
|
|
+ return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -317,11 +376,11 @@ func (f *ScmpFilter) addRuleGeneric(call ScmpSyscall, action ScmpAction, exact b
|
|
// Helper - Sanitize Arch token input
|
|
// Helper - Sanitize Arch token input
|
|
func sanitizeArch(in ScmpArch) error {
|
|
func sanitizeArch(in ScmpArch) error {
|
|
if in < archStart || in > archEnd {
|
|
if in < archStart || in > archEnd {
|
|
- return fmt.Errorf("unrecognized architecture")
|
|
|
|
|
|
+ return fmt.Errorf("unrecognized architecture %#x", uint(in))
|
|
}
|
|
}
|
|
|
|
|
|
if in.toNative() == C.C_ARCH_BAD {
|
|
if in.toNative() == C.C_ARCH_BAD {
|
|
- return fmt.Errorf("architecture is not supported on this version of the library")
|
|
|
|
|
|
+ return fmt.Errorf("architecture %v is not supported on this version of the library", in)
|
|
}
|
|
}
|
|
|
|
|
|
return nil
|
|
return nil
|
|
@@ -330,7 +389,7 @@ func sanitizeArch(in ScmpArch) error {
|
|
func sanitizeAction(in ScmpAction) error {
|
|
func sanitizeAction(in ScmpAction) error {
|
|
inTmp := in & 0x0000FFFF
|
|
inTmp := in & 0x0000FFFF
|
|
if inTmp < actionStart || inTmp > actionEnd {
|
|
if inTmp < actionStart || inTmp > actionEnd {
|
|
- return fmt.Errorf("unrecognized action")
|
|
|
|
|
|
+ return fmt.Errorf("unrecognized action %#x", uint(inTmp))
|
|
}
|
|
}
|
|
|
|
|
|
if inTmp != ActTrace && inTmp != ActErrno && (in&0xFFFF0000) != 0 {
|
|
if inTmp != ActTrace && inTmp != ActErrno && (in&0xFFFF0000) != 0 {
|
|
@@ -342,7 +401,7 @@ func sanitizeAction(in ScmpAction) error {
|
|
|
|
|
|
func sanitizeCompareOp(in ScmpCompareOp) error {
|
|
func sanitizeCompareOp(in ScmpCompareOp) error {
|
|
if in < compareOpStart || in > compareOpEnd {
|
|
if in < compareOpStart || in > compareOpEnd {
|
|
- return fmt.Errorf("unrecognized comparison operator")
|
|
|
|
|
|
+ return fmt.Errorf("unrecognized comparison operator %#x", uint(in))
|
|
}
|
|
}
|
|
|
|
|
|
return nil
|
|
return nil
|
|
@@ -385,7 +444,7 @@ func archFromNative(a C.uint32_t) (ScmpArch, error) {
|
|
case C.C_ARCH_S390X:
|
|
case C.C_ARCH_S390X:
|
|
return ArchS390X, nil
|
|
return ArchS390X, nil
|
|
default:
|
|
default:
|
|
- return 0x0, fmt.Errorf("unrecognized architecture")
|
|
|
|
|
|
+ return 0x0, fmt.Errorf("unrecognized architecture %#x", uint32(a))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -464,10 +523,12 @@ func actionFromNative(a C.uint32_t) (ScmpAction, error) {
|
|
return ActErrno.SetReturnCode(int16(aTmp)), nil
|
|
return ActErrno.SetReturnCode(int16(aTmp)), nil
|
|
case C.C_ACT_TRACE:
|
|
case C.C_ACT_TRACE:
|
|
return ActTrace.SetReturnCode(int16(aTmp)), nil
|
|
return ActTrace.SetReturnCode(int16(aTmp)), nil
|
|
|
|
+ case C.C_ACT_LOG:
|
|
|
|
+ return ActLog, nil
|
|
case C.C_ACT_ALLOW:
|
|
case C.C_ACT_ALLOW:
|
|
return ActAllow, nil
|
|
return ActAllow, nil
|
|
default:
|
|
default:
|
|
- return 0x0, fmt.Errorf("unrecognized action")
|
|
|
|
|
|
+ return 0x0, fmt.Errorf("unrecognized action %#x", uint32(a))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -482,6 +543,8 @@ func (a ScmpAction) toNative() C.uint32_t {
|
|
return C.C_ACT_ERRNO | (C.uint32_t(a) >> 16)
|
|
return C.C_ACT_ERRNO | (C.uint32_t(a) >> 16)
|
|
case ActTrace:
|
|
case ActTrace:
|
|
return C.C_ACT_TRACE | (C.uint32_t(a) >> 16)
|
|
return C.C_ACT_TRACE | (C.uint32_t(a) >> 16)
|
|
|
|
+ case ActLog:
|
|
|
|
+ return C.C_ACT_LOG
|
|
case ActAllow:
|
|
case ActAllow:
|
|
return C.C_ACT_ALLOW
|
|
return C.C_ACT_ALLOW
|
|
default:
|
|
default:
|
|
@@ -500,6 +563,8 @@ func (a scmpFilterAttr) toNative() uint32 {
|
|
return uint32(C.C_ATTRIBUTE_NNP)
|
|
return uint32(C.C_ATTRIBUTE_NNP)
|
|
case filterAttrTsync:
|
|
case filterAttrTsync:
|
|
return uint32(C.C_ATTRIBUTE_TSYNC)
|
|
return uint32(C.C_ATTRIBUTE_TSYNC)
|
|
|
|
+ case filterAttrLog:
|
|
|
|
+ return uint32(C.C_ATTRIBUTE_LOG)
|
|
default:
|
|
default:
|
|
return 0x0
|
|
return 0x0
|
|
}
|
|
}
|