Repository navigation
do_syslog_sudo: clamp the split length to avoid an infinite loop - #569
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
do_syslog_sudo()splits a long log line into severalsyslog(3)calls, computing the per-line budget asmaxlen = syslog_maxlen - (strlen(fmt) - 5 + strlen(submituser)). On sudo_logsrvd the submit user comes straight from the client's AcceptMessage (evlog_new()fillsevlog->submituserfrom thesubmituserkey), so its length is attacker controlled. When the escaped submit user is exactlysyslog_maxlenminus the continuation overhead (23 bytes, so 937 at the defaultsyslog_maxlenof 960) the continuationmaxlenworks out to 0.memrchr(p, ' ', 0)returns NULL,tmpis set top, the line is truncated to empty andpnever advances, so theforloop spins forever emitting empty "(command continued)" records. It is reachable on the default logsrvd config (syslog, sudo format) with no TLS client certificate, and hangs the single event-loop daemon for every client.Compute the overhead separately and clamp
maxlento a minimum of 1 at both the first-line and continuation sites, so the loop always advances. The same guard also avoids thesize_twrap whensyslog_maxlenis smaller than the overhead. I confirmed the hang by replaying the split loop with the 937-byte submit user: unpacked it never advancesp, and with the clamp it terminates.make checkpasses.