Navigation Menu

Skip to content
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

EM select loop crashes when fd >= FD_SETSIZE #501

Closed
piki opened this issue Mar 11, 2014 · 3 comments · Fixed by #502
Closed

EM select loop crashes when fd >= FD_SETSIZE #501

piki opened this issue Mar 11, 2014 · 3 comments · Fixed by #502

Comments

@piki
Copy link
Contributor

piki commented Mar 11, 2014

The [_RunSelectOnce](void EventMachine_t::_RunSelectOnce%28%29) function crashes the whole Ruby VM when it hits FDs over FD_SETSIZE. In my case, a too-high fd becomes available for reading. The fdreads and fdwrites sets overlap, so when fd N is available for reading, EM thinks that fd N-1024 is available for writing. The descriptor in question is a server socket (AcceptorDescriptor), which throws in its Write function. Down comes the VM.

It appears I can fix this with a simple EM.epoll, so it's not urgent for me. But it would be nice to have assert(fd < FD_SETSIZE) before each call to FD_SET here. Then at least the crashes would be straightforward and in the right place.

It's also possible, at least on Linux, to malloc fd_sets with more than FD_SETSIZE bits in them. So instead of crashing when fd >= FD_SETSIZE, just realloc.

I'm happy to write and PR either solution.

@piki
Copy link
Contributor Author

piki commented Mar 11, 2014

Theoretically, this is a remote-exploitable defect. 💣 💥

SelectData is a local variable in _RunSelectOnce, so overflows in fdreads can escape up into the stack frame. By manipulating when FDs above 1024*3 are readable, an attacker can put arbitrary bits in the stack frame.

@tmm1
Copy link
Contributor

tmm1 commented Mar 11, 2014

We can use rb_fdset_t in newer rubies to handle dynamic sizing for us. See https://github.com/redis/hiredis-rb/pull/18/files as an example

@piki
Copy link
Contributor Author

piki commented Mar 11, 2014

What do you want to do about older Rubies?

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 a pull request may close this issue.

2 participants