Skip to content

Add support for SCMP_FLTATR_CTL_WAITKILL, test against libseccomp v2.6.0 #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
go-version: [1.22.x, 1.23.x]
libseccomp: ["v2.3.3", "v2.4.4", "v2.5.5", "HEAD"]
libseccomp: ["v2.3.3", "v2.4.4", "v2.5.6", "v2.6.0", "HEAD"]

steps:

Expand Down
38 changes: 38 additions & 0 deletions seccomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,25 @@ func (f *ScmpFilter) GetRawRC() (bool, error) {
return true, nil
}

// GetWaitKill returns the current state of WaitKill flag,
// or an error if an issue was encountered retrieving the value.
// See SetWaitKill for more details.
func (f *ScmpFilter) GetWaitKill() (bool, error) {
val, err := f.getFilterAttr(filterAttrWaitKill)
if err != nil {
if e := checkAPI("GetWaitKill", 7, 2, 6, 0); e != nil {
err = e
}

return false, err
}
if val == 0 {
return false, nil
}

return true, nil
}

// SetBadArchAction sets the default action taken on a syscall for an
// architecture not in the filter, or an error if an issue was encountered
// setting the value.
Expand Down Expand Up @@ -1073,6 +1092,25 @@ func (f *ScmpFilter) SetRawRC(state bool) error {
return err
}

// SetWaitKill sets whether libseccomp should request wait killable semantics
// when possible. Defaults to false.
func (f *ScmpFilter) SetWaitKill(state bool) error {
var toSet C.uint32_t = 0x0

if state {
toSet = 0x1
}

err := f.setFilterAttr(filterAttrWaitKill, toSet)
if err != nil {
if e := checkAPI("SetWaitKill", 7, 2, 6, 0); e != nil {
err = e
}
}

return err
}

// SetSyscallPriority sets a syscall's priority.
// This provides a hint to the filter generator in libseccomp about the
// importance of this syscall. High-priority syscalls are placed
Expand Down
9 changes: 9 additions & 0 deletions seccomp_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ const uint32_t C_ACT_NOTIFY = SCMP_ACT_NOTIFY;
#define SCMP_FLTATR_API_SYSRAWRC _SCMP_FLTATR_MIN
#endif

// Added in libseccomp v2.6.0.
#if SCMP_VER_MAJOR == 2 && SCMP_VER_MINOR < 6
#define SCMP_FLTATR_CTL_WAITKILL _SCMP_FLTATR_MIN
#endif

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_NNP = (uint32_t)SCMP_FLTATR_CTL_NNP;
Expand All @@ -156,6 +161,7 @@ const uint32_t C_ATTRIBUTE_LOG = (uint32_t)SCMP_FLTATR_CTL_LOG;
const uint32_t C_ATTRIBUTE_SSB = (uint32_t)SCMP_FLTATR_CTL_SSB;
const uint32_t C_ATTRIBUTE_OPTIMIZE = (uint32_t)SCMP_FLTATR_CTL_OPTIMIZE;
const uint32_t C_ATTRIBUTE_SYSRAWRC = (uint32_t)SCMP_FLTATR_API_SYSRAWRC;
const uint32_t C_ATTRIBUTE_WAITKILL = (uint32_t)SCMP_FLTATR_CTL_WAITKILL;

const int C_CMP_NE = (int)SCMP_CMP_NE;
const int C_CMP_LT = (int)SCMP_CMP_LT;
Expand Down Expand Up @@ -283,6 +289,7 @@ const (
filterAttrSSB
filterAttrOptimize
filterAttrRawRC
filterAttrWaitKill
)

const (
Expand Down Expand Up @@ -709,6 +716,8 @@ func (a scmpFilterAttr) toNative() uint32 {
return uint32(C.C_ATTRIBUTE_OPTIMIZE)
case filterAttrRawRC:
return uint32(C.C_ATTRIBUTE_SYSRAWRC)
case filterAttrWaitKill:
return uint32(C.C_ATTRIBUTE_WAITKILL)
default:
return 0x0
}
Expand Down
18 changes: 18 additions & 0 deletions seccomp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,24 @@ func TestFilterAttributeGettersAndSetters(t *testing.T) {
} else if rawrc != true {
t.Error("RawRC flag was not set correctly")
}

// Checks that require API level >= 7 and libseccomp >= 2.6.0.
if err := checkAPI(t.Name(), 7, 2, 6, 0); err != nil {
t.Logf("Skipping the rest of the test: %v", err)
return
}

err = filter.SetWaitKill(true)
if err != nil {
t.Errorf("Error setting WaitKill flag: %v", err)
}

wk, err := filter.GetWaitKill()
if err != nil {
t.Errorf("Error getting WaitKill flag: %v", err)
} else if wk != true {
t.Error("WaitKill flag was not set correctly")
}
}

func TestMergeFilters(t *testing.T) {
Expand Down
Loading