mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
seccomp: add support for flags
List of seccomp flags defined in runtime-spec: * SECCOMP_FILTER_FLAG_TSYNC * SECCOMP_FILTER_FLAG_LOG * SECCOMP_FILTER_FLAG_SPEC_ALLOW Note that runc does not apply SECCOMP_FILTER_FLAG_TSYNC. It does not make sense to apply the seccomp filter on only one thread; other threads will be terminated after exec anyway. See similar commit in crun: https://github.com/containers/crun/commit/fefabffa2816ea343068ed036a86944393db189a Note that SECCOMP_FILTER_FLAG_WAIT_KILLABLE_RECV (introduced by https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?id=c2aa2dfef243 in Linux 5.19-rc1) is not added yet because Linux 5.19 is not released yet. Signed-off-by: Alban Crequy <albancrequy@microsoft.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/configs"
|
||||
"github.com/opencontainers/runc/libcontainer/seccomp/patchbpf"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -86,6 +87,29 @@ func InitSeccomp(config *configs.Seccomp) (int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Add extra flags
|
||||
for _, flag := range config.Flags {
|
||||
switch flag {
|
||||
case "SECCOMP_FILTER_FLAG_TSYNC":
|
||||
// libseccomp-golang always use filterAttrTsync when
|
||||
// possible so all goroutines will receive the same
|
||||
// rules, so there is nothing to do. It does not make
|
||||
// sense to apply the seccomp filter on only one
|
||||
// thread; other threads will be terminated after exec
|
||||
// anyway.
|
||||
case specs.LinuxSeccompFlagLog:
|
||||
if err := filter.SetLogBit(true); err != nil {
|
||||
return -1, fmt.Errorf("error adding log flag to seccomp filter: %w", err)
|
||||
}
|
||||
case specs.LinuxSeccompFlagSpecAllow:
|
||||
if err := filter.SetSSB(true); err != nil {
|
||||
return -1, fmt.Errorf("error adding SSB flag to seccomp filter: %w", err)
|
||||
}
|
||||
default:
|
||||
return -1, fmt.Errorf("seccomp flags %q not yet supported by runc", flag)
|
||||
}
|
||||
}
|
||||
|
||||
// Unset no new privs bit
|
||||
if err := filter.SetNoNewPrivsBit(false); err != nil {
|
||||
return -1, fmt.Errorf("error setting no new privileges: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user