-
Notifications
You must be signed in to change notification settings - Fork 916
Fix TOCTOU vulnerability in unused_port module #8016
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
base: unstable
Are you sure you want to change the base?
Conversation
* Add co-author to mergify commits. * Remove unnecessary pull request rules from mergify config. * Revert automation removals
|
Thanks! We are aware of this issue and had been phasing these functions out in favour of using 0 ports explicitly. The hard part is replacing the uses of the old functions in code that assumes it can determine an unused port without binding a socket, e.g. here: lighthouse/lighthouse/tests/beacon_node.rs Lines 955 to 970 in fd10b63
If you would be interested in coming up with clever fixes for these cases, that would be extremely helpful. That would then allow us to delete rather than deprecate the unsafe functions. |
Most of the uses are in tests, but it's still important for us to get rid of them (if possible), as they sometimes contribute to CI flakiness. |
@sashaodessa Can you also please rebase on |
Looks good at a glance, I've requested a review from some our networking experts on the changes that impact prod |
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.
These changes look good to me.
Agree a future PR to remove deprecation would be nice.
{% for commit in commits | unique(attribute='email_author') %} | ||
Co-Authored-By: {{ commit.author }} <{{ commit.email_author }}> | ||
{% endfor %} |
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.
Are these changes relevant?
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.
No this is some leftover stuff from stable
that hasn't been backmerged to unstable
yet (see https://github.com/sigp/lighthouse/commits/stable/), it should be deleted from this PR.
I think we can probably just delete the deprecated functions in this PR, AFAICT all (?) usages have been removed |
Replaces unsafe port-finding functions with secure bound socket APIs to eliminate race conditions.
Problem
The existing
unused_tcp*_port()
andunused_udp*_port()
functions had a classic Time-of-Check-Time-of-Use (TOCTOU) vulnerability:Solution
Added new safe APIs that return already-bound sockets:
bind_tcp4_any()
/bind_tcp6_any()
→ returnsTcpListener
bind_udp4_any()
/bind_udp6_any()
→ returnsUdpSocket