-
Notifications
You must be signed in to change notification settings - Fork 50
Protect uses of select() from crash on too many file descriptors #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The fd_set macros don't check for overflow and will cause an out-of-bounds access when given a file description >= FD_SETSIZE (1024) This doesn't fix the fundamental issue, but prevents a crash and should allow partial functionality. The full fix requires switching to poll() instead.
penguin359
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, seems I am still unable to assign this to @apconole for a review.
| return; | ||
|
|
||
| if (sock >= FD_SETSIZE) { | ||
| warn_too_many_fds(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with this being added, but a quick grep through the code doesn't seem to find any in-tree callers for eloop_wait_for_read_sock.
Maybe we should delete it instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I only see eloop_register_read_sock() and eloop_unregister_read_sock() used, but not eloop_wait_for_read_sock(). Also, it looks like eloop_register_sock(), eloop_unregister_sock(), and os_get_time() can all be made static.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I found several things to clean-up in eloop.c/eloop.h including function prototypes in the header files that refer to functions that have never existed in the Git history. I'll save that clean-up for another PR, but I think I can drop that function for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are okay with it, I'll merge this patch and backport it to the 1.1 branch.
|
Merged and backported. Thanks! |
The fd_set macros don't check for overflow and will cause an
out-of-bounds access when given a file description >= FD_SETSIZE (1024)
This is to address issue #118 which originally reported this crash. Ultimately, we should switch to using either
poll()orepoll()for handling file descriptor events, but this PR will at least preventlldpadfrom a crash when used with a large (> ~500) interfaces. Some interfaces will fail to operate correctly, but this at least allows for partial functionality until the full fix can be included.