Skip to content

Commit 798ec96

Browse files
tyhicksmheon
authored andcommitted
golang: Add support for SCMP_ACT_LOG
Represent libseccomp's SCMP_ACT_LOG action with ActLog. This action logs before allowing the syscall. Signed-off-by: Tyler Hicks <[email protected]> Signed-off-by: Matthew Heon <[email protected]>
1 parent 23edf06 commit 798ec96

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

seccomp.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ const (
137137
ActTrace ScmpAction = iota
138138
// ActAllow permits the syscall to continue execution
139139
ActAllow ScmpAction = iota
140+
// ActLog permits the syscall to continue execution after logging it.
141+
// This action is only usable when libseccomp API level 3 or higher is
142+
// supported.
143+
ActLog ScmpAction = iota
140144
)
141145

142146
const (
@@ -295,6 +299,8 @@ func (a ScmpAction) String() string {
295299
case ActTrace:
296300
return fmt.Sprintf("Action: Notify tracing processes with code %d",
297301
(a >> 16))
302+
case ActLog:
303+
return "Action: Log system call"
298304
case ActAllow:
299305
return "Action: Allow system call"
300306
default:

seccomp_internal.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,15 @@ const uint32_t C_ARCH_PPC64LE = SCMP_ARCH_PPC64LE;
6868
const uint32_t C_ARCH_S390 = SCMP_ARCH_S390;
6969
const uint32_t C_ARCH_S390X = SCMP_ARCH_S390X;
7070
71+
#ifndef SCMP_ACT_LOG
72+
#define SCMP_ACT_LOG 0x7ffc0000U
73+
#endif
74+
7175
const uint32_t C_ACT_KILL = SCMP_ACT_KILL;
7276
const uint32_t C_ACT_TRAP = SCMP_ACT_TRAP;
7377
const uint32_t C_ACT_ERRNO = SCMP_ACT_ERRNO(0);
7478
const uint32_t C_ACT_TRACE = SCMP_ACT_TRACE(0);
79+
const uint32_t C_ACT_LOG = SCMP_ACT_LOG;
7580
const uint32_t C_ACT_ALLOW = SCMP_ACT_ALLOW;
7681
7782
// The libseccomp SCMP_FLTATR_CTL_LOG member of the scmp_filter_attr enum was
@@ -198,7 +203,7 @@ const (
198203
archEnd ScmpArch = ArchS390X
199204
// Comparison boundaries to check for action validity
200205
actionStart ScmpAction = ActKill
201-
actionEnd ScmpAction = ActAllow
206+
actionEnd ScmpAction = ActLog
202207
// Comparison boundaries to check for comparison operator validity
203208
compareOpStart ScmpCompareOp = CompareNotEqual
204209
compareOpEnd ScmpCompareOp = CompareMaskedEqual
@@ -518,6 +523,8 @@ func actionFromNative(a C.uint32_t) (ScmpAction, error) {
518523
return ActErrno.SetReturnCode(int16(aTmp)), nil
519524
case C.C_ACT_TRACE:
520525
return ActTrace.SetReturnCode(int16(aTmp)), nil
526+
case C.C_ACT_LOG:
527+
return ActLog, nil
521528
case C.C_ACT_ALLOW:
522529
return ActAllow, nil
523530
default:
@@ -536,6 +543,8 @@ func (a ScmpAction) toNative() C.uint32_t {
536543
return C.C_ACT_ERRNO | (C.uint32_t(a) >> 16)
537544
case ActTrace:
538545
return C.C_ACT_TRACE | (C.uint32_t(a) >> 16)
546+
case ActLog:
547+
return C.C_ACT_LOG
539548
case ActAllow:
540549
return C.C_ACT_ALLOW
541550
default:

0 commit comments

Comments
 (0)