Skip to content

sudoers_check_cmnd: don't convert an intercepted sudoedit to edit mode - #578

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:sudoedit-intercept-mode
Oct 23, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:sudoedit-intercept-mode

Conversation

@iefa-m

@iefa-m iefa-m commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

With Defaults intercept, a command that execs a file named sudoedit (the real /usr/bin/sudoedit or any file with that basename) reaches sudoers_check_cmnd() as an intercepted MODE_RUN request. MODE_INTERCEPT_MASK removes MODE_EDIT on purpose, but the "sudo sudoedit" conversion puts it back. The plugin then returns command=<editor> with argv {editor, --, file}, and exec_intercept.c execs that in the intercepted process, which already runs as the runas user and ignores sudoedit=true. A user with an intercepted command that can exec an arbitrary path plus any sudoedit rule therefore gets the editor running as root on the real file instead of on a temporary copy. The path lookup is skipped in edit mode, so the intercept_allow_setid check sees an empty stat. Authentication is also skipped for intercepted commands.

Skip the conversion for intercepted commands so the exec is checked as an ordinary command. To confirm, I drove sudoers_policy.check_policy() twice with the fuzz_policy stubs: first an initial command, then the intercepted sub-command /usr/bin/sudoedit /etc/motd. Before the change the second call returned command=/usr/bin/vi, argv vi -- /etc/motd, runas_uid=0. After it, the call is checked as /usr/bin/sudoedit in run mode. make check in plugins/sudoers passes except sudoers/test2 (toke), which also fails on an unmodified tree.

When a command running under intercept execs a file named "sudoedit",
the policy check for it converted the request to edit mode just like
"sudo sudoedit".  MODE_INTERCEPT_MASK strips MODE_EDIT on purpose, but
the conversion added it back, so the plugin returned the editor as the
command to run with the files to edit as its arguments.  The front end
execs that directly in the intercepted process, so the editor ran as
the runas user on the real file instead of on a temporary copy.

Only do the "sudo sudoedit" conversion for the initial command.  An
intercepted exec of sudoedit is now checked as an ordinary command.

@millert millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I didn't consider and intercepted sudoedit when that change was made.

@millert
millert merged commit 34085bf into sudo-project:main Oct 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants