Skip to content

Commit 8443ab4

Browse files
committed
command_matches_fnmatch: use canonicalized path if user path contains ".."
We already fall back on the canonicalized path if the user-specified path is relative. The FNM_PATHNAME flag is already used, which means a '/' in the user-specified command must match a '/' in the sudoers pattern. However, there is still the potential for unintended matches given a user-specified command path that contains "..". For example, given a sudoers rule like: user ALL = /usr/*/bin/* The user would also be able to run "/bin/sh" as "sudo /usr/../bin/sh" which is probably not what was intended.
1 parent 620ba7a commit 8443ab4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

plugins/sudoers/match_command.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ command_matches_fnmatch(struct sudoers_context *ctx, const char *sudoers_cmnd,
418418
* We do not attempt to match a relative path unless there is a
419419
* canonicalized version.
420420
*/
421-
if (cmnd[0] != '/' || fnmatch(sudoers_cmnd, cmnd, FNM_PATHNAME) != 0) {
421+
if (cmnd[0] != '/' || sudo_contains_dot_dot(cmnd) ||
422+
fnmatch(sudoers_cmnd, cmnd, FNM_PATHNAME) != 0) {
422423
/* No match, retry using the canonicalized path (if possible). */
423424
if (ctx->user.cmnd_dir == NULL)
424425
debug_return_int(DENY);

0 commit comments

Comments
 (0)