summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-01-16 19:05:41 -0500
committerGitHub <noreply@github.com>2019-01-16 19:05:41 -0500
commit5303a5f3004e9e8e9f43b805086b1aee9376ba49 (patch)
tree7d7c515fba9bb27710d847daab75f55664c0567a
parentb44d7a0e48951376c187a847f401765a3b0fee04 (diff)
parent3bdf58a455f8a0188024d0c3f0118bcb4c68fb59 (diff)
Merge pull request #14 from swaywm/shadow-fortify-drop-root
Make sure we can't restore root after setuid
-rw-r--r--shadow.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/shadow.c b/shadow.c
index 7c3a5cc..a1b664b 100644
--- a/shadow.c
+++ b/shadow.c
@@ -21,7 +21,7 @@ static void clear_buffer(void *buf, size_t bytes) {
}
}
-void run_child(void) {
+static void run_child(void) {
/* This code runs as root */
struct passwd *pwent = getpwuid(getuid());
if (!pwent) {
@@ -46,6 +46,9 @@ void run_child(void) {
if (setuid(getuid()) != 0) {
exit(EXIT_FAILURE);
}
+ if (setuid(0) != -1) {
+ exit(EXIT_FAILURE);
+ }
/* This code does not run as root */
swaylock_log(LOG_DEBUG, "prepared to authorize user %s", pwent->pw_name);
@@ -127,6 +130,11 @@ void initialize_pw_backend(void) {
swaylock_log_errno(LOG_ERROR, "Unable to drop root");
exit(EXIT_FAILURE);
}
+ if (setuid(0) != -1) {
+ swaylock_log_errno(LOG_ERROR, "Unable to drop root (we shouldn't be "
+ "able to restore it after setuid)");
+ return false;
+ }
}
bool attempt_password(struct swaylock_password *pw) {