From 895c347006b92a4fe553a8ebcc95a73c543325c0 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 13 Sep 2021 13:30:59 +0000 Subject: [PATCH] main: allow running as root when not using setuid bit --- sway/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/main.c b/sway/main.c index 0611e80bf..60ad1212a 100644 --- a/sway/main.c +++ b/sway/main.c @@ -150,7 +150,12 @@ static void log_kernel(void) { static bool drop_permissions(void) { + if (getuid() == 0 || getgid() == 0) { + sway_log(SWAY_INFO, "Running as root user, this is dangerous"); + return true; + } if (getuid() != geteuid() || getgid() != getegid()) { + sway_log(SWAY_INFO, "setuid/setgid bit detected, dropping permissions"); // Set the gid and uid in the correct order. if (setgid(getgid()) != 0) { sway_log(SWAY_ERROR, "Unable to drop root group, refusing to start");