Skip to content

handle_winsize, handle_exit: reject negative values from the client - #603

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:logsrvd-negative-numbers
Nov 25, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:logsrvd-negative-numbers

Conversation

@iefa-m

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

Copy link
Copy Markdown
Contributor

handle_winsize() and handle_exit() validate the other fields of their messages, the delay with valid_timespec() and the signal name against an allowlist, but not the int32 numbers. store_winsize_local() writes the client's rows and cols into the timing file with %d and store_exit_info_json() writes exit_value into log.json, and neither value can be read back when it is negative: iolog_parse_timing() refuses a negative lines or cols field and json_store_exit_value() refuses an exit value below zero, which fails the whole log.json. A client can therefore make its recorded session unreplayable from a record of its choosing, and sudo_logsrvd can no longer resume that log either; the sudoers I/O plugin cannot produce such a record locally because sudoers_io_change_winsize_local() formats it with %u.

The check belongs in the message handlers next to the existing field validation rather than in each writer, since that covers the local, relay and journal back ends. Negative is the only range worth rejecting here because both readers accept 0 through INT_MAX.

Repro: feeding the exact bytes the two writers emit back through iolog_parse_timing() and eventlog_json_read()/eventlog_json_parse(), 5 0.000000000 -1 80 and "exit_value": -1 are both refused. make check passes.

@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.

I don't think the comments add value here. Can you remove those and just include the range checks?

handle_winsize() and handle_exit() check the other fields of their
messages but not the int32 numbers, and store_winsize_local() writes
rows and cols into the timing file with "%d" while
store_exit_info_json() writes exit_value into log.json.  A client can
therefore store values that sudo will not read back:
iolog_parse_timing() rejects a negative lines or cols field and
json_store_exit_value() rejects an exit value below zero, which fails
the whole log.json.  The session then stops being replayable at that
record and sudo_logsrvd can no longer resume the log.

Reject a negative rows, cols or exit value where the rest of each
message is already validated, which covers the local, relay and
journal back ends.
@iefa-m
iefa-m force-pushed the logsrvd-negative-numbers branch from a3b3a8f to b7c89ee Compare November 25, 2026 07:27
@iefa-m

iefa-m commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Fair enough, dropped both comments and left the existing ones alone, so the diff is just the two range checks now. Rebuilt and make check still passes.

@millert
millert merged commit 2ad8a35 into sudo-project:main Nov 25, 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