Skip to content

proc_read_vec: bound trailing NUL trim to the current string table - #557

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:proc-read-vec-trim-bound
Oct 2, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:proc-read-vec-trim-bound

Conversation

@iefa-m

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

Copy link
Copy Markdown
Contributor

proc_read_vec tests strtab - *bufp >= 2 before trimming the extra trailing NUL, but the string table it just filled starts at *bufp + off rather than at *bufp. The environ read is handed a non-zero off, so when the tracee exec'd with an empty environment and nothing landed in this table, the test looks at the last two bytes of the argv pointer vector written by the previous call; those are its NULL terminator, so the trim always fires and strtab drops below the start of the table. strtab_len then underflows to SIZE_MAX and strtab_to_vec evaluates strtab + SIZE_MAX, which ubsan reports as a pointer overflow; an envp holding one empty string trips the same test and is miscounted as zero entries, so ptrace_verify_post_exec compares the wrong envc.

Compare against *bufp + off, which is what the strtab_len calculation two lines down already uses. The bound belongs next to the table it describes rather than to the whole allocation, so a caller chaining a second read into the same buffer does not have to know the trim exists. Reads where at least two bytes arrive behave exactly as before.

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

Good catch, thanks!

@millert
millert merged commit 7a2f88b into sudo-project:main Oct 2, 2026
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