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

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