diff options
author | 2020-02-10 21:29:26 -0500 | |
---|---|---|
committer | 2020-02-11 10:17:45 +0100 | |
commit | 31a83bd48d9aad2a039565fc39f1a52bd0cdf17d (patch) | |
tree | 995bf9eebad763834ebca1c72ea74b14fb93c00c | |
parent | container_at_{tabbed,stacked}: check x-axis bounds (diff) | |
download | sway-31a83bd48d9aad2a039565fc39f1a52bd0cdf17d.tar.gz sway-31a83bd48d9aad2a039565fc39f1a52bd0cdf17d.tar.zst sway-31a83bd48d9aad2a039565fc39f1a52bd0cdf17d.zip |
Fix ordering of setgid and setuid
It looks like the code to drop privileges may have been broken via
commit 37f0e1f. That commit reverted the correct order from #911, which
first drops the gid then the uid. If setuid is called first then the
target user may not have the ability to setgid.
-rw-r--r-- | sway/main.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/sway/main.c b/sway/main.c index e0af4a79..d4585f73 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -186,12 +186,17 @@ static void log_kernel(void) { | |||
186 | 186 | ||
187 | static bool drop_permissions(void) { | 187 | static bool drop_permissions(void) { |
188 | if (getuid() != geteuid() || getgid() != getegid()) { | 188 | if (getuid() != geteuid() || getgid() != getegid()) { |
189 | if (setuid(getuid()) != 0 || setgid(getgid()) != 0) { | 189 | // Set the gid and uid in the correct order. |
190 | sway_log(SWAY_ERROR, "Unable to drop root, refusing to start"); | 190 | if (setgid(getgid()) != 0) { |
191 | sway_log(SWAY_ERROR, "Unable to drop root group, refusing to start"); | ||
192 | return false; | ||
193 | } | ||
194 | if (setuid(getuid()) != 0) { | ||
195 | sway_log(SWAY_ERROR, "Unable to drop root user, refusing to start"); | ||
191 | return false; | 196 | return false; |
192 | } | 197 | } |
193 | } | 198 | } |
194 | if (setuid(0) != -1) { | 199 | if (setgid(0) != -1 || setuid(0) != -1) { |
195 | sway_log(SWAY_ERROR, "Unable to drop root (we shouldn't be able to " | 200 | sway_log(SWAY_ERROR, "Unable to drop root (we shouldn't be able to " |
196 | "restore it after setuid), refusing to start"); | 201 | "restore it after setuid), refusing to start"); |
197 | return false; | 202 | return false; |