Blame SOURCES/sudo-1.8.29-CVE-2019-19232.patch

3379fe
diff -up ./doc/sudoers.man.in.CVE-2019-19232 ./doc/sudoers.man.in
3379fe
--- ./doc/sudoers.man.in.CVE-2019-19232	2019-10-28 13:28:52.000000000 +0100
3379fe
+++ ./doc/sudoers.man.in	2020-01-14 15:34:46.908027286 +0100
3379fe
@@ -2942,6 +2942,23 @@ This flag is
3379fe
 \fIoff\fR
3379fe
 by default.
3379fe
 .TP 18n
3379fe
+runas_allow_unknown_id
3379fe
+If enabled, allow matching of runas user and group IDs that are
3379fe
+not present in the password or group databases.
3379fe
+In addition to explicitly matching unknown user or group IDs in a
3379fe
+\fRRunas_List\fR,
3379fe
+this option also allows the
3379fe
+\fBALL\fR
3379fe
+alias to match unknown IDs.
3379fe
+This flag is
3379fe
+\fIoff\fR
3379fe
+by default.
3379fe
+.sp
3379fe
+This setting is only supported by version 1.8.29 or higher.
3379fe
+Older versions of
3379fe
+\fBsudo\fR
3379fe
+always allowed matching of unknown user and group IDs.
3379fe
+.TP 18n
3379fe
 runaspw
3379fe
 If set,
3379fe
 \fBsudo\fR
3379fe
diff -up ./doc/sudoers.mdoc.in.CVE-2019-19232 ./doc/sudoers.mdoc.in
3379fe
--- ./doc/sudoers.mdoc.in.CVE-2019-19232	2019-10-28 13:28:52.000000000 +0100
3379fe
+++ ./doc/sudoers.mdoc.in	2020-01-14 15:34:46.908027286 +0100
3379fe
@@ -2768,6 +2768,22 @@ when running a command or editing a file
3379fe
 This flag is
3379fe
 .Em off
3379fe
 by default.
3379fe
+.It runas_allow_unknown_id
3379fe
+If enabled, allow matching of runas user and group IDs that are
3379fe
+not present in the password or group databases.
3379fe
+In addition to explicitly matching unknown user or group IDs in a
3379fe
+.Li Runas_List ,
3379fe
+this option also allows the
3379fe
+.Sy ALL
3379fe
+alias to match unknown IDs.
3379fe
+This flag is
3379fe
+.Em off
3379fe
+by default.
3379fe
+.Pp
3379fe
+This setting is only supported by version 1.8.29 or higher.
3379fe
+Older versions of
3379fe
+.Nm sudo
3379fe
+always allowed matching of unknown user and group IDs.
3379fe
 .It runaspw
3379fe
 If set,
3379fe
 .Nm sudo
3379fe
diff -up ./plugins/sudoers/defaults.c.CVE-2019-19232 ./plugins/sudoers/defaults.c
3379fe
--- ./plugins/sudoers/defaults.c.CVE-2019-19232	2020-01-14 15:34:46.902027246 +0100
3379fe
+++ ./plugins/sudoers/defaults.c	2020-01-14 15:34:46.909027293 +0100
3379fe
@@ -581,6 +581,7 @@ init_defaults(void)
3379fe
     def_fdexec = digest_only;
3379fe
     def_log_allowed = true;
3379fe
     def_log_denied = true;
3379fe
+    def_runas_allow_unknown_id = false;
3379fe
 
3379fe
     /* Syslog options need special care since they both strings and ints */
3379fe
 #if (LOGGING & SLOG_SYSLOG)
3379fe
diff -up ./plugins/sudoers/def_data.c.CVE-2019-19232 ./plugins/sudoers/def_data.c
3379fe
--- ./plugins/sudoers/def_data.c.CVE-2019-19232	2020-01-14 15:34:46.908027286 +0100
3379fe
+++ ./plugins/sudoers/def_data.c	2020-01-14 15:40:19.441555509 +0100
3379fe
@@ -514,6 +514,10 @@ struct sudo_defs_types sudo_defs_table[]
3379fe
 	N_("Don't fork and wait for the command to finish, just exec it"),
3379fe
 	NULL,
3379fe
     }, {
3379fe
+	"runas_allow_unknown_id", T_FLAG,
3379fe
+	N_("Allow the use of unknown runas user and/or group ID"),
3379fe
+	NULL,
3379fe
+    }, {
3379fe
 	NULL, 0, NULL
3379fe
     }
3379fe
 };
3379fe
diff -up ./plugins/sudoers/def_data.h.CVE-2019-19232 ./plugins/sudoers/def_data.h
3379fe
--- ./plugins/sudoers/def_data.h.CVE-2019-19232	2020-01-14 15:34:46.909027293 +0100
3379fe
+++ ./plugins/sudoers/def_data.h	2020-01-14 15:41:33.658012401 +0100
3379fe
@@ -236,6 +236,8 @@
3379fe
 #define def_legacy_group_processing (sudo_defs_table[I_LEGACY_GROUP_PROCESSING].sd_un.flag)
3379fe
 #define I_CMND_NO_WAIT          118
3379fe
 #define def_cmnd_no_wait        (sudo_defs_table[I_CMND_NO_WAIT].sd_un.flag)
3379fe
+#define I_RUNAS_ALLOW_UNKNOWN_ID 119
3379fe
+#define def_runas_allow_unknown_id (sudo_defs_table[I_RUNAS_ALLOW_UNKNOWN_ID].sd_un.flag)
3379fe
 
3379fe
 enum def_tuple {
3379fe
 	never,
3379fe
diff -up ./plugins/sudoers/def_data.in.CVE-2019-19232 ./plugins/sudoers/def_data.in
3379fe
--- ./plugins/sudoers/def_data.in.CVE-2019-19232	2020-01-14 15:34:46.909027293 +0100
3379fe
+++ ./plugins/sudoers/def_data.in	2020-01-14 15:42:42.176481484 +0100
3379fe
@@ -372,3 +372,6 @@ legacy_group_processing
3379fe
 cmnd_no_wait
3379fe
 	T_FLAG
3379fe
 	"Don't fork and wait for the command to finish, just exec it"
3379fe
+runas_allow_unknown_id
3379fe
+	T_FLAG
3379fe
+	"Allow the use of unknown runas user and/or group ID"
3379fe
diff -up ./plugins/sudoers/sudoers.c.CVE-2019-19232 ./plugins/sudoers/sudoers.c
3379fe
--- ./plugins/sudoers/sudoers.c.CVE-2019-19232	2020-01-14 15:34:46.905027266 +0100
3379fe
+++ ./plugins/sudoers/sudoers.c	2020-01-14 15:34:46.910027299 +0100
3379fe
@@ -105,6 +105,8 @@ static char *prev_user;
3379fe
 static char *runas_user;
3379fe
 static char *runas_group;
3379fe
 static struct sudo_nss_list *snl;
3379fe
+static bool unknown_runas_uid;
3379fe
+static bool unknown_runas_gid;
3379fe
 
3379fe
 #ifdef __linux__
3379fe
 static struct rlimit nproclimit;
3379fe
@@ -354,6 +356,22 @@ sudoers_policy_main(int argc, char * con
3379fe
 	}
3379fe
     }
3379fe
 
3379fe
+    /* Defer uid/gid checks until after defaults have been updated. */
3379fe
+    if (unknown_runas_uid && !def_runas_allow_unknown_id) {
3379fe
+	audit_failure(NewArgc, NewArgv, N_("unknown user: %s"),
3379fe
+	    runas_pw->pw_name);
3379fe
+	sudo_warnx(U_("unknown user: %s"), runas_pw->pw_name);
3379fe
+	goto done;
3379fe
+    }
3379fe
+    if (runas_gr != NULL) {
3379fe
+	if (unknown_runas_gid && !def_runas_allow_unknown_id) {
3379fe
+	    audit_failure(NewArgc, NewArgv, N_("unknown group: %s"),
3379fe
+		runas_gr->gr_name);
3379fe
+	    sudo_warnx(U_("unknown group: %s"), runas_gr->gr_name);
3379fe
+	    goto done;
3379fe
+	}
3379fe
+    }
3379fe
+
3379fe
     /*
3379fe
      * Look up the timestamp dir owner if one is specified.
3379fe
      */
3379fe
@@ -1167,12 +1185,15 @@ set_runaspw(const char *user, bool quiet
3379fe
     struct passwd *pw = NULL;
3379fe
     debug_decl(set_runaspw, SUDOERS_DEBUG_PLUGIN)
3379fe
 
3379fe
+    unknown_runas_uid = false;
3379fe
     if (*user == '#') {
3379fe
 	const char *errstr;
3379fe
 	uid_t uid = sudo_strtoid(user + 1, &errstr);
3379fe
 	if (errstr == NULL) {
3379fe
-	    if ((pw = sudo_getpwuid(uid)) == NULL)
3379fe
+	    if ((pw = sudo_getpwuid(uid)) == NULL) {
3379fe
+		unknown_runas_uid = true;
3379fe
 		pw = sudo_fakepwnam(user, user_gid);
3379fe
+	    }
3379fe
 	}
3379fe
     }
3379fe
     if (pw == NULL) {
3379fe
@@ -1198,12 +1219,15 @@ set_runasgr(const char *group, bool quie
3379fe
     struct group *gr = NULL;
3379fe
     debug_decl(set_runasgr, SUDOERS_DEBUG_PLUGIN)
3379fe
 
3379fe
+    unknown_runas_gid = false;
3379fe
     if (*group == '#') {
3379fe
 	const char *errstr;
3379fe
 	gid_t gid = sudo_strtoid(group + 1, &errstr);
3379fe
 	if (errstr == NULL) {
3379fe
-	    if ((gr = sudo_getgrgid(gid)) == NULL)
3379fe
+	    if ((gr = sudo_getgrgid(gid)) == NULL) {
3379fe
+		unknown_runas_gid = true;
3379fe
 		gr = sudo_fakegrnam(group);
3379fe
+	    }
3379fe
 	}
3379fe
     }
3379fe
     if (gr == NULL) {