mirror of
https://github.com/opencontainers/runc.git
synced 2026-11-06 05:17:05 +00:00
Merge pull request #5439 from kolyshkin/fix-5438-selinux-defer
libct: don't reset selinux labels on init error path
This commit is contained in:
3 files changed
+17
-4
No files matched your search
@@ -38,7 +38,6 @@ func (l *linuxSetnsInit) Init() error {
|
||||
if err := selinux.SetKeyLabel(l.config.ProcessLabel); err != nil {
|
||||
return err
|
||||
}
|
||||
defer selinux.SetKeyLabel("") //nolint: errcheck
|
||||
}
|
||||
// Do not inherit the parent's session keyring.
|
||||
if _, err := keys.JoinSessionKeyring(l.getSessionRingName()); err != nil {
|
||||
@@ -102,7 +101,6 @@ func (l *linuxSetnsInit) Init() error {
|
||||
if err := selinux.SetExecLabel(l.config.ProcessLabel); err != nil {
|
||||
return err
|
||||
}
|
||||
defer selinux.SetExecLabel("") //nolint: errcheck
|
||||
}
|
||||
// Without NoNewPrivileges seccomp is a privileged operation, so we need to
|
||||
// do this before dropping capabilities; otherwise do it as late as possible
|
||||
|
||||
@@ -54,7 +54,6 @@ func (l *linuxStandardInit) Init() error {
|
||||
if err := selinux.SetKeyLabel(l.config.ProcessLabel); err != nil {
|
||||
return err
|
||||
}
|
||||
defer selinux.SetKeyLabel("") //nolint: errcheck
|
||||
}
|
||||
ringname, keepperms, newperms := l.getSessionRingParams()
|
||||
|
||||
@@ -185,7 +184,6 @@ func (l *linuxStandardInit) Init() error {
|
||||
if err := selinux.SetExecLabel(l.config.ProcessLabel); err != nil {
|
||||
return fmt.Errorf("can't set process label: %w", err)
|
||||
}
|
||||
defer selinux.SetExecLabel("") //nolint: errcheck
|
||||
}
|
||||
// Without NoNewPrivileges seccomp is a privileged operation, so we need to
|
||||
// do this before dropping capabilities; otherwise do it as late as possible
|
||||
|
||||
@@ -104,3 +104,20 @@ function enable_userns() {
|
||||
enable_userns
|
||||
exec_check_label
|
||||
}
|
||||
|
||||
# Check that an execve failure is reported as such, rather than aborting
|
||||
# runc init. See https://github.com/opencontainers/runc/issues/5438.
|
||||
@test "runc run (execve error + custom selinux label)" {
|
||||
cat <<-EOF >rootfs/run.sh
|
||||
#!/mmnnttbb foo bar
|
||||
sh
|
||||
EOF
|
||||
chmod +x rootfs/run.sh
|
||||
|
||||
update_config ' .process.selinuxLabel |= "system_u:system_r:container_t:s0:c4,c5"
|
||||
| .process.args = ["/run.sh"]'
|
||||
runc run tst
|
||||
[ "$status" -ne 0 ]
|
||||
[ ${#lines[@]} -eq 1 ]
|
||||
[[ "${lines[0]}" = "exec /run.sh: no such file or directory" ]]
|
||||
}
|
||||
Reference in new issue
Block a user