Skip to content

do_syslog_sudo, do_logfile_sudo: escape control chars in submituser - #560

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:eventlog-escape-submituser
Oct 12, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:eventlog-escape-submituser

Conversation

@iefa-m

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

Copy link
Copy Markdown
Contributor

new_logline escapes control characters in every field it formats, but the submit user is not one of them: do_logfile_sudo prepends it with asprintf and do_syslog_sudo hands it to syslog, both unescaped. In the sudoers plugin that name comes from the password database, while sudo_logsrvd fills it from the submituser key of a client AcceptMessage and never inspects the bytes, so on a log server it is whatever the client decided to send. A submituser containing a newline ends the record early and starts a second, well-formed one, so with log_format at its default of sudo a client sending "nobody\nJan 1 00:00:00 : root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/sh" gets an entry for a root shell that never ran, written straight into the event log file or passed on to syslog. Every other field on that line is already escaped, which leaves the submit user as the one way to break out of it. sudoreplay gets the identical prefix right: list_session builds "date : user : " through sudo_lbuf_append_esc with LBUF_ESC_CNTRL. Both callers now escape the same way, so a newline comes out as #12 like the rest of the line and ordinary user names are unchanged. send_mail is left alone because EVLOG_MAIL is only set by the sudoers plugin, where the name comes from getpwuid.

@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 for this. Most of the logging code dates from before logsrvd was written and it shows.

@millert
millert merged commit e6f482a into sudo-project:main Oct 12, 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