]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
execute: respect selinux_context_ignore
authorTopi Miettinen <toiwoton@gmail.com>
Sat, 30 Oct 2021 16:58:41 +0000 (19:58 +0300)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 31 Oct 2021 23:28:41 +0000 (08:28 +0900)
When `SELinuxContext=` parameter is prefixed with `-`, the documentation states
that any errors determining or changing context should be ignored, but this
doesn't actually happen and the service may fail with `229/SELINUX_CONTEXT`.

Fix by adding checks to `context->selinux_context_ignore`.

Closes: #21057
src/core/execute.c

index d5882999f69938f6ab342e8b2a2bb78379f52088..52a4daf0cb6d60e8aad85a30b781cb1ffa133d8a 100644 (file)
@@ -4566,7 +4566,7 @@ static int exec_child(
 
                 if (fd >= 0) {
                         r = mac_selinux_get_child_mls_label(fd, executable, context->selinux_context, &mac_selinux_context_net);
-                        if (r < 0) {
+                        if (r < 0 && !context->selinux_context_ignore) {
                                 *exit_status = EXIT_SELINUX_CONTEXT;
                                 return log_unit_error_errno(unit, r, "Failed to determine SELinux context: %m");
                         }
@@ -4700,7 +4700,7 @@ static int exec_child(
 
                         if (exec_context) {
                                 r = setexeccon(exec_context);
-                                if (r < 0) {
+                                if (r < 0 && !context->selinux_context_ignore) {
                                         *exit_status = EXIT_SELINUX_CONTEXT;
                                         return log_unit_error_errno(unit, r, "Failed to change SELinux context to %s: %m", exec_context);
                                 }