Repository navigation
sudo_ev_add_impl: store the poll slot index as an int - #602
Merged
Merged
Conversation
The pollfd array in the event base can grow to RLIMIT_NOFILE entries, but each event remembers its slot in a short. Once more than 32767 I/O events are registered, slot 32768 is stored as -32768 and the event's fd and events are written 256 KiB before the start of the array, with later deletes and scans using the same bad slot. sudo_logsrvd raises RLIMIT_NOFILE to the hard limit and keeps a read event for every client connection, so enough idle connections are sufficient to reach this. Use an int, like pfd_free, pfd_max and pfd_high.
millert
approved these changes
Nov 21, 2026
millert
left a comment
Collaborator
There was a problem hiding this comment.
Thanks. The event code was written before the log server support; at the time it was only used for keyboard I/O logging.
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.
struct sudo_eventkeeps its slot in the poll backend'spfdsarray in ashort(pfd_idx, already markedXXX), whilesudo_ev_add_impl()lets that array grow up toRLIMIT_NOFILEentries. When the 32769th I/O event is added,(short)base->pfd_freebecomes -32768 and the event's fd and poll flags are written to&base->pfds[-32768], 256 KiB before the heap array.sudo_ev_del_impl()andsudo_ev_scan_impl()then keep using that slot, and the!= -1check in the scan loop doesn't catch it.sudo_logsrvdhits this from the network:unlimit_nofile()raises the soft limit to the hard limit (524288 or more under systemd), there is no cap on concurrent connections, and a plaintext connection gets a persistent read event with no timeout as soon as it is accepted (start_protocol()). A client that opens about 32.8k connections and sends nothing makes the root daemon write outside the array.Making
pfd_idxanintmatchespfd_free,pfd_maxandpfd_high. On LP64 the field sits in the padding beforecallback, so the struct's size and the offsets of later members don't change. I reproduced it with AddressSanitizer by driving the unmodifiedevent_poll.cwith 40000 read events andRLIMIT_NOFILEat 524288: adding event 32768 triggers a 4-byte WRITE atevent_poll.c:120, 256 KiB before the livepfdsallocation. With the patch, all 40000 events get slots 0 through 39999. The select backend doesn't usepfd_idx.