Skip to content

Commit d43320d

Browse files
cypharstefanberger
authored andcommitted
setns init: delay seccomp as late as possible
This mirrors the standard_init_linux.go seccomp code, which only applies seccomp early if NoNewPrivileges is enabled. Otherwise it's done immediately before execve to reduce the amount of syscalls necessary for users to enable in their seccomp profiles. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 77e6d53 commit d43320d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

libcontainer/setns_init_linux.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ func (l *linuxSetnsInit) Init() error {
4747
return err
4848
}
4949
}
50-
if l.config.Config.Seccomp != nil {
50+
// Without NoNewPrivileges seccomp is a privileged operation, so we need to
51+
// do this before dropping capabilities; otherwise do it as late as possible
52+
// just before execve so as few syscalls take place after it as possible.
53+
if l.config.Config.Seccomp != nil && !l.config.NoNewPrivileges {
5154
if err := seccomp.InitSeccomp(l.config.Config.Seccomp); err != nil {
5255
return err
5356
}
@@ -61,5 +64,13 @@ func (l *linuxSetnsInit) Init() error {
6164
if err := label.SetProcessLabel(l.config.ProcessLabel); err != nil {
6265
return err
6366
}
67+
// Set seccomp as close to execve as possible, so as few syscalls take
68+
// place afterward (reducing the amount of syscalls that users need to
69+
// enable in their seccomp profiles).
70+
if l.config.Config.Seccomp != nil && l.config.NoNewPrivileges {
71+
if err := seccomp.InitSeccomp(l.config.Config.Seccomp); err != nil {
72+
return newSystemErrorWithCause(err, "init seccomp")
73+
}
74+
}
6475
return system.Execv(l.config.Args[0], l.config.Args[0:], os.Environ())
6576
}

0 commit comments

Comments
 (0)