Skip to content

Commit d3683ff

Browse files
lnykrynbluca
authored andcommitted
core: warn if a generator is world-writable
... because that is obviously a security risk. (cherry picked from commit da32cac) (cherry picked from commit 7ac5894) (cherry picked from commit 3b0731b) (cherry picked from commit 7c72562)
1 parent 916fb2d commit d3683ff

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/core/manager.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3826,7 +3826,7 @@ static int manager_execute_generators(Manager *m, char **paths, bool remount_ro)
38263826
/* callbacks= */ NULL, /* callback_args= */ NULL,
38273827
(char**) argv,
38283828
ge,
3829-
EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS | EXEC_DIR_SET_SYSTEMD_EXEC_PID);
3829+
EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS | EXEC_DIR_SET_SYSTEMD_EXEC_PID | EXEC_DIR_WARN_WORLD_WRITABLE);
38303830
}
38313831

38323832
static int manager_run_generators(Manager *m) {

src/shared/exec-util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ static int do_execute(
149149
log_debug("About to execute %s%s%s", t, argv ? " " : "", argv ? strnull(args) : "");
150150
}
151151

152+
if (FLAGS_SET(flags, EXEC_DIR_WARN_WORLD_WRITABLE)) {
153+
struct stat st;
154+
155+
r = stat(t, &st);
156+
if (r < 0)
157+
log_warning_errno(errno, "Failed to stat '%s', ignoring: %m", t);
158+
else if (S_ISREG(st.st_mode) && (st.st_mode & 0002))
159+
log_warning("'%s' is marked world-writable, which is a security risk as it "
160+
"is executed with privileges. Please remove world writability "
161+
"permission bits. Proceeding anyway.", t);
162+
}
163+
152164
r = do_spawn(t, argv, fd, &pid, FLAGS_SET(flags, EXEC_DIR_SET_SYSTEMD_EXEC_PID));
153165
if (r <= 0)
154166
continue;

src/shared/exec-util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef enum {
1919
EXEC_DIR_PARALLEL = 1 << 0, /* Execute scripts in parallel, if possible */
2020
EXEC_DIR_IGNORE_ERRORS = 1 << 1, /* Ignore non-zero exit status of scripts */
2121
EXEC_DIR_SET_SYSTEMD_EXEC_PID = 1 << 2, /* Set $SYSTEMD_EXEC_PID environment variable */
22+
EXEC_DIR_WARN_WORLD_WRITABLE = 1 << 3, /* Warn if world writable files are found */
2223
} ExecDirFlags;
2324

2425
typedef enum ExecCommandFlags {

0 commit comments

Comments
 (0)