From be57b91ba175ff5f48919472f4a9b1841bc41d96 Mon Sep 17 00:00:00 2001 From: Joshua Kwan Date: Wed, 21 Jan 2004 01:37:16 +0000 Subject: [PATCH] Additional anti-root uid security fixes git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@134 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- config.y | 29 ++++++++++++++++++++++++++--- dgamelaunch.c | 4 ++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/config.y b/config.y index 336f144..485cd11 100644 --- a/config.y +++ b/config.y @@ -45,7 +45,11 @@ KeyPair: KeyType '=' TYPE_VALUE { struct passwd* usr; if (!myconfig) + { myconfig = calloc(1, sizeof(struct dg_config)); + myconfig->shed_uid = (uid_t)-1; + myconfig->shed_gid = (gid_t)-1; + } switch ($1) { @@ -58,12 +62,25 @@ KeyPair: KeyType '=' TYPE_VALUE { break; case TYPE_SUSER: + if (!strcmp($3, "root")) + { + fprintf(stderr, "%s: I refuse to run as root! Aborting.\n", config); + graceful_exit(1); + } myconfig->shed_user = strdup($3); if ((usr = getpwnam($3)) != NULL) - myconfig->shed_uid = usr->pw_uid; + { + if (usr->pw_uid != 0) + myconfig->shed_uid = usr->pw_uid; + else + { + fprintf(stderr, "%s: I refuse to run as %s (uid 0!) Aborting.\n", config, $3); + graceful_exit(1); + } + } else - fprintf(stderr, "%s: no such group '%s'\n", config, $3); - break; + fprintf(stderr, "%s: no such user '%s'\n", config, $3); + break; case TYPE_PATH_CHROOT: if (myconfig->chroot) free(myconfig->chroot); @@ -113,6 +130,12 @@ KeyPair: KeyType '=' TYPE_VALUE { case TYPE_SUID: if (!myconfig->shed_user) { + /* Naive user protection - do not allow running as user root */ + if ($3 == 0) + { + fprintf(stderr, "%s: I refuse to run as root! Aborting.\n", config); + graceful_exit(1); + } myconfig->shed_uid = $3; } diff --git a/dgamelaunch.c b/dgamelaunch.c index 958a372..f056607 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -170,7 +170,7 @@ create_config () } /* Fill the rest with defaults */ - if (!myconfig->shed_user && myconfig->shed_uid == 0) + if (!myconfig->shed_user && myconfig->shed_uid == -1) { struct passwd *pw; if ((pw = getpwnam(defconfig.shed_user))) @@ -179,7 +179,7 @@ create_config () myconfig->shed_uid = defconfig.shed_uid; } - if (!myconfig->shed_group && myconfig->shed_gid == 0) + if (!myconfig->shed_group && myconfig->shed_gid == -1) { struct group *gr; if ((gr = getgrnam(defconfig.shed_group))) -- 2.47.3