]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: warn if a generator is world-writable
authorLukas Nykryn <lnykryn@redhat.com>
Fri, 4 Oct 2024 08:51:02 +0000 (10:51 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Oct 2024 02:02:37 +0000 (11:02 +0900)
... because that is obviously a security risk.

src/core/manager.c
src/shared/exec-util.c
src/shared/exec-util.h

index 18fb8fdaf8cffe95b7aedd8e08a71d6e42693c74..2789f0e3d0c9c6f8f6dda9297aad7f708f78d977 100644 (file)
@@ -4151,7 +4151,7 @@ static int manager_execute_generators(Manager *m, char **paths, bool remount_ro)
                         /* callbacks= */ NULL, /* callback_args= */ NULL,
                         (char**) argv,
                         ge,
-                        EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS | EXEC_DIR_SET_SYSTEMD_EXEC_PID);
+                        EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS | EXEC_DIR_SET_SYSTEMD_EXEC_PID | EXEC_DIR_WARN_WORLD_WRITABLE);
 }
 
 static int manager_run_generators(Manager *m) {
index 870f8f66d82430f0039972502c45b4e7a50cfc6a..628e777da176efb922dd0235c8740270db2f3496 100644 (file)
@@ -156,6 +156,18 @@ static int do_execute(
                         log_debug("About to execute %s%s%s", t, argv ? " " : "", argv ? strnull(args) : "");
                 }
 
+                if (FLAGS_SET(flags, EXEC_DIR_WARN_WORLD_WRITABLE)) {
+                        struct stat st;
+
+                        r = stat(t, &st);
+                        if (r < 0)
+                                log_warning_errno(errno, "Failed to stat '%s', ignoring: %m", t);
+                        else if (S_ISREG(st.st_mode) && (st.st_mode & 0002))
+                                log_warning("'%s' is marked world-writable, which is a security risk as it "
+                                            "is executed with privileges. Please remove world writability "
+                                            "permission bits. Proceeding anyway.", t);
+                }
+
                 r = do_spawn(t, argv, fd, FLAGS_SET(flags, EXEC_DIR_SET_SYSTEMD_EXEC_PID), &pid);
                 if (r <= 0)
                         continue;
index 3940a286aea147d017a99ef54aa1a55928643ca8..4565ddbee086ba3a6ff8a66c1f27ee82d90fcc65 100644 (file)
@@ -20,6 +20,7 @@ typedef enum {
         EXEC_DIR_IGNORE_ERRORS        = 1 << 1, /* Ignore non-zero exit status of scripts */
         EXEC_DIR_SET_SYSTEMD_EXEC_PID = 1 << 2, /* Set $SYSTEMD_EXEC_PID environment variable */
         EXEC_DIR_SKIP_REMAINING       = 1 << 3, /* Ignore remaining executions when one exit with 77. */
+        EXEC_DIR_WARN_WORLD_WRITABLE  = 1 << 4, /* Warn if world writable files are found */
 } ExecDirFlags;
 
 typedef enum ExecCommandFlags {