Repository navigation
event_select: don't leave freed fd sets in the event base - #613
Merged
Merged
Conversation
millert
approved these changes
Dec 6, 2026
millert
left a comment
Collaborator
There was a problem hiding this comment.
Yes, that is much safer, thanks.
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.
sudo_ev_add_impl()grows the four select(2) fd sets with four consecutivereallocarray()calls, but only stores the results in the event base once all four have succeeded.reallocarray()frees the old block on success, so when a later call fails the base still points at memory an earlier call already released, and the error path frees the new blocks instead of recording them.sudo_ev_scan_impl()thenmemcpy()s frombase->readfds_in,sudo_ev_del_impl()clears bits in it withFD_CLR(), andsudo_ev_base_free_impl()frees it a second time. Reducing the growth path to a single translation unit,gcc -fanalyzer(GCC 16.2) reports three-Wanalyzer-double-free(CWE-415) paths throughsudo_ev_base_free_impl(), forreadfds_in,readfds_outandwritefds_out, when the second allocation fails.Store each fd set in the base as soon as its
reallocarray()returns and drop thefree()calls from the error path, since the base now owns the new blocks. Leavingbase->maxfdalone on the error path keeps every reader in bounds, becausemaxfdonly grows once all four sets are the new size, and a partial grow leaves the sets larger thanmaxfdimplies rather than smaller. The poll backend commits its singlereallocarray()the same way, and this is the only place left in the tree that reallocates several owning pointers before recording any of them.event_select.cis built only when poll(2) is unavailable or--disable-pollis given, so the default Linux and BSD builds are unaffected.