Skip to content

Commit b52b456

Browse files
authored
Merge pull request #114 from kolyshkin/wait-kill
Add support for SCMP_FLTATR_CTL_WAITKILL, test against libseccomp v2.6.0 Signed-off-by: Kir Kolyshkin <[email protected]> Acked-by: Tom Hromatka <[email protected]>
2 parents d03f8c3 + c669ab8 commit b52b456

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
go-version: [1.22.x, 1.23.x]
19-
libseccomp: ["v2.3.3", "v2.4.4", "v2.5.5", "HEAD"]
19+
libseccomp: ["v2.3.3", "v2.4.4", "v2.5.6", "v2.6.0", "HEAD"]
2020

2121
steps:
2222

seccomp.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,25 @@ func (f *ScmpFilter) GetRawRC() (bool, error) {
961961
return true, nil
962962
}
963963

964+
// GetWaitKill returns the current state of WaitKill flag,
965+
// or an error if an issue was encountered retrieving the value.
966+
// See SetWaitKill for more details.
967+
func (f *ScmpFilter) GetWaitKill() (bool, error) {
968+
val, err := f.getFilterAttr(filterAttrWaitKill)
969+
if err != nil {
970+
if e := checkAPI("GetWaitKill", 7, 2, 6, 0); e != nil {
971+
err = e
972+
}
973+
974+
return false, err
975+
}
976+
if val == 0 {
977+
return false, nil
978+
}
979+
980+
return true, nil
981+
}
982+
964983
// SetBadArchAction sets the default action taken on a syscall for an
965984
// architecture not in the filter, or an error if an issue was encountered
966985
// setting the value.
@@ -1073,6 +1092,25 @@ func (f *ScmpFilter) SetRawRC(state bool) error {
10731092
return err
10741093
}
10751094

1095+
// SetWaitKill sets whether libseccomp should request wait killable semantics
1096+
// when possible. Defaults to false.
1097+
func (f *ScmpFilter) SetWaitKill(state bool) error {
1098+
var toSet C.uint32_t = 0x0
1099+
1100+
if state {
1101+
toSet = 0x1
1102+
}
1103+
1104+
err := f.setFilterAttr(filterAttrWaitKill, toSet)
1105+
if err != nil {
1106+
if e := checkAPI("SetWaitKill", 7, 2, 6, 0); e != nil {
1107+
err = e
1108+
}
1109+
}
1110+
1111+
return err
1112+
}
1113+
10761114
// SetSyscallPriority sets a syscall's priority.
10771115
// This provides a hint to the filter generator in libseccomp about the
10781116
// importance of this syscall. High-priority syscalls are placed

seccomp_internal.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ const uint32_t C_ACT_NOTIFY = SCMP_ACT_NOTIFY;
148148
#define SCMP_FLTATR_API_SYSRAWRC _SCMP_FLTATR_MIN
149149
#endif
150150
151+
// Added in libseccomp v2.6.0.
152+
#if SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 6
153+
#define SCMP_FLTATR_CTL_WAITKILL _SCMP_FLTATR_MIN
154+
#endif
155+
151156
const uint32_t C_ATTRIBUTE_DEFAULT = (uint32_t)SCMP_FLTATR_ACT_DEFAULT;
152157
const uint32_t C_ATTRIBUTE_BADARCH = (uint32_t)SCMP_FLTATR_ACT_BADARCH;
153158
const uint32_t C_ATTRIBUTE_NNP = (uint32_t)SCMP_FLTATR_CTL_NNP;
@@ -156,6 +161,7 @@ const uint32_t C_ATTRIBUTE_LOG = (uint32_t)SCMP_FLTATR_CTL_LOG;
156161
const uint32_t C_ATTRIBUTE_SSB = (uint32_t)SCMP_FLTATR_CTL_SSB;
157162
const uint32_t C_ATTRIBUTE_OPTIMIZE = (uint32_t)SCMP_FLTATR_CTL_OPTIMIZE;
158163
const uint32_t C_ATTRIBUTE_SYSRAWRC = (uint32_t)SCMP_FLTATR_API_SYSRAWRC;
164+
const uint32_t C_ATTRIBUTE_WAITKILL = (uint32_t)SCMP_FLTATR_CTL_WAITKILL;
159165
160166
const int C_CMP_NE = (int)SCMP_CMP_NE;
161167
const int C_CMP_LT = (int)SCMP_CMP_LT;
@@ -283,6 +289,7 @@ const (
283289
filterAttrSSB
284290
filterAttrOptimize
285291
filterAttrRawRC
292+
filterAttrWaitKill
286293
)
287294

288295
const (
@@ -709,6 +716,8 @@ func (a scmpFilterAttr) toNative() uint32 {
709716
return uint32(C.C_ATTRIBUTE_OPTIMIZE)
710717
case filterAttrRawRC:
711718
return uint32(C.C_ATTRIBUTE_SYSRAWRC)
719+
case filterAttrWaitKill:
720+
return uint32(C.C_ATTRIBUTE_WAITKILL)
712721
default:
713722
return 0x0
714723
}

seccomp_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,24 @@ func TestFilterAttributeGettersAndSetters(t *testing.T) {
503503
} else if rawrc != true {
504504
t.Error("RawRC flag was not set correctly")
505505
}
506+
507+
// Checks that require API level >= 7 and libseccomp >= 2.6.0.
508+
if err := checkAPI(t.Name(), 7, 2, 6, 0); err != nil {
509+
t.Logf("Skipping the rest of the test: %v", err)
510+
return
511+
}
512+
513+
err = filter.SetWaitKill(true)
514+
if err != nil {
515+
t.Errorf("Error setting WaitKill flag: %v", err)
516+
}
517+
518+
wk, err := filter.GetWaitKill()
519+
if err != nil {
520+
t.Errorf("Error getting WaitKill flag: %v", err)
521+
} else if wk != true {
522+
t.Error("WaitKill flag was not set correctly")
523+
}
506524
}
507525

508526
func TestMergeFilters(t *testing.T) {

0 commit comments

Comments
 (0)