From 66362c85779f341b661e45e90ea1ff26f04f1cf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mantas=20Mikul=C4=97nas?= Date: Fri, 29 Jan 2016 23:36:08 +0200 Subject: [PATCH] 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/elogind/show-status. --- src/basic/fs-util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index b13a9cbea..e895cac4f 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -333,7 +333,8 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi if (parents) mkdir_parents(path, 0755); - fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, mode > 0 ? mode : 0644); + fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY, + (mode == 0 || mode == MODE_INVALID) ? 0644 : mode); if (fd < 0) return -errno; -- 2.30.2