From c4d384082fdbc8406cf19e08d05db4cded920a55 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 23 Jan 2021 08:43:59 -0700 Subject: [PATCH] Add sudoedit flag checks in plugin that are consistent with front-end. Don't assume the sudo front-end is sending reasonable mode flags. These checks need to be kept consistent between the sudo front-end and the sudoers plugin. --- plugins/sudoers/policy.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/sudoers/policy.c b/plugins/sudoers/policy.c index d4be26491..d675d2fd4 100644 --- a/plugins/sudoers/policy.c +++ b/plugins/sudoers/policy.c @@ -88,10 +88,11 @@ parse_bool(const char *line, int varlen, int *flags, int fval) int sudoers_policy_deserialize_info(void *v) { + const int edit_mask = MODE_EDIT|MODE_IGNORE_TICKET|MODE_NONINTERACTIVE; struct sudoers_open_info *info = v; - char * const *cur; const char *p, *errstr, *groups = NULL; const char *remhost = NULL; + char * const *cur; int flags = 0; debug_decl(sudoers_policy_deserialize_info, SUDOERS_DEBUG_PLUGIN); @@ -348,6 +349,12 @@ sudoers_policy_deserialize_info(void *v) #endif } + /* Sudo front-end should restrict mode flags for sudoedit. */ + if (ISSET(flags, MODE_EDIT) && (flags & edit_mask) != flags) { + sudo_warnx(U_("invalid mode flags from sudo front end: 0x%x"), flags); + goto bad; + } + user_gid = (gid_t)-1; user_sid = (pid_t)-1; user_uid = (gid_t)-1;