Skip to content

Commit 06eeacb

Browse files
committed
basic: fix touch() creating files with 07777 mode
mode_t is unsigned, so MODE_INVALID < 0 can never be true. This fixes a possible DoS where any user could fill /run by writing to a world-writable /run/systemd/show-status.
1 parent 7d82cd4 commit 06eeacb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: src/basic/fs-util.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi
341341
if (parents)
342342
mkdir_parents(path, 0755);
343343

344-
fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, mode > 0 ? mode : 0644);
344+
fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY,
345+
(mode == 0 || mode == MODE_INVALID) ? 0644 : mode);
345346
if (fd < 0)
346347
return -errno;
347348

0 commit comments

Comments
 (0)