-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Drop usage of SO_EXCLUSIVEADDRUSE on Windows #928
Comments
How do these things work?The official docs on this are here: https://docs.microsoft.com/en-us/windows/desktop/WinSock/using-so-reuseaddr-and-so-exclusiveaddruse Unfortunately, the formatting on that page is mangled. There are some big tables that include crucial information, but they're completely unreadable. Also, they changed the URL format at some point after the mangling happened, so if you just paste that URL into archive.org you don't get anything useful. But, anyway, here's the old URL, in archive.org, with working tables. I'll link to two versions, for reasons that will become apparent soon: May 2015, March 2017 The first table is just a bunch of version info. The second purports to tell you how The most important entry in the table is at the intersection of row "Default / specific" and column " In the May 2015 version of the table (and earlier versions), this entry is "Success", indicating that miscreants can use In the March 2017 version of the table (and later versions ... including the version actually up on the website right now, if you squint at it long enough to figure out how it's been mangled), this entry is "ACCESS", indicating that miscreants cannot use Except for this table, almost everything else between these two snapshots is identical (I used some janky SEO website's "page comparison tool" to check). The only other difference is that in the May 2015 version, the first table has an entry for "Windows 7", and in the March 2017 version, it instead has an entry for "Windows 7 and newer". In particular, they both claim that the table we care about describe what happens on "Windows Server 2003 and later operating systems", which seems unlikely, given that their tables are totally different from each other. So, I wrote a little script to check. Here's the output on Windows 10:
This exactly matches the "March 2017" version of the table, not the "May 2015" version. So... it seems like they actually changed things at some point, to plug up this security hole. You still shouldn't use Also they still have all this text on the page about how if you use What does SO_EXCLUSIVEADDRUSE actually do then?It looks like they decided it should be used to control another unrelated bit of IP configuration. Quirky IP lesson: you can bind a socket to a specific host, like Obviously if two sockets tries to bind to the same specific host + port at the same time, that can't work. And ditto if two sockets try to bind to same port on the wildcard address at the same time. But what if one socket binds to a specific host, and another binds to the wildcard address, on the same port at the same time? Is that a conflict? Conceptually, the answer is .... sorta? Honestly to me it feels like it should conflict. But there's at least a little more wiggle room. And here, platforms differ: On Linux, this is always a conflict. On BSDs, it's not a conflict, if the second socket has OK, so what about Windows? Well, they did both! By default they act like the BSDs with So... that's nice I guess? Which versions do what?OK that's how Windows 10 works. But when did this change happen? Does the security hole still exist in any versions we care about? So... I downloaded Windows 7 and installed it into a VM, and ran my script again. And I got the same results as on Windows 10, so that's nice. (I also got the same results for the Windows Vista's "extended support" period ended April 11, 2017. Python 3.6 was released December 23, 2016. According to PEP 11, this means that Python 3.6 will support Windows Vista until 3.6 itself goes EOL. Also, Windows Server 2008 doesn't go out of "extended support" until January 2020, so even Python 3.8 will support Windows Server 2008. Of course, we don't necessarily have to support the same versions that Python itself does... According to NetMarketShare's estimates, Windows XP is currently 3.96% of desktop installs worldwide. But I definitely don't think we should try to support Windows XP (and it's not even supported by any Python version that we can run on). And Vista is currently 0.26%, which seems like we can probably ignore it? Well, that's good enough for now. Maybe if I'm really bored later I'll try installing a Vista VM. What should we do?So it sounds like In terms of the actual semantics, I don't feel like there's a strong argument for or against So I have a weak feeling that perhaps we should stop using And of course, we should continue to never ever set |
Can now confirm that Windows Vista SP2 (released 2009) also follows the table from the March 2017 docs, and both of my test scripts behave exactly the same way they do on Windows 10. So AFAICT, the timeline is: Win XP did a thing that was unfortunate but made sense given compatibility concerns ( The Windows IP stack is a land of contrasts. |
Added
|
- Add the test script used in python-triogh-928 to decipher Window's port reuse semantics - Note the existence of the 'tree-format' package (found thanks to @itamarst)
Drop usage of SO_EXCLUSIVEADDRUSE on win32 (#928)
Closed by #1108 |
@njsmith I'm struggling to make sense of this, did you possibly reverse it, in other words is it actually |
@jay Entirely possible. The script I ran is here if you want to check definitively: https://github.com/python-trio/trio/blob/master/notes-to-self/how-does-windows-so-reuseaddr-work.py |
- Generate the table headers dynamically. Prior to this change the table headers were static and incorrect, 'specific' and 'wildcard' labels were reversed. ------------------------------------------ Example from before the change (incorrect): | default | | specific| wildcard| --------------------- default | wildcard | INUSE | Success | default | wildcard | Success | INUSE | Example from after the change (correct): | default | | wildcard | specific | ----------------------- default | wildcard | INUSE | Success | default | wildcard | Success | INUSE | ------------------------------------------ Bug: python-trio#928 (comment) Closes #xxxx
- Generate the table headers dynamically. Prior to this change the table headers were static and incorrect, 'specific' and 'wildcard' labels were reversed. Example from before the change (incorrect): ~~~ | default | | specific| wildcard| --------------------- default | wildcard | INUSE | Success | default | wildcard | Success | INUSE | ~~~ Example from after the change (correct): ~~~ | default | | wildcard | specific | ----------------------- default | wildcard | INUSE | Success | default | wildcard | Success | INUSE | ~~~ Bug: python-trio#928 (comment) Closes #xxxx
- Generate the table headers dynamically. Prior to this change the table headers were static and incorrect, 'specific' and 'wildcard' labels were reversed. Example output from before the change (incorrect): ~~~ | default | | specific| wildcard| --------------------- default | wildcard | INUSE | Success | default | wildcard | Success | INUSE | ~~~ Example output from after the change (correct): ~~~ | default | | wildcard | specific | ----------------------- default | wildcard | INUSE | Success | default | wildcard | Success | INUSE | ~~~ Bug: python-trio#928 (comment) Closes #xxxx
I recently saw a claim that contra the MSDN documentation, using
SO_REUSEADDR
on Windows no longer creates a bizarre security hole. We have a script innotes-to-self/
that demonstrates thatSO_EXCLUSIVEADDRUSE
doesn't break things the way MSDN claims it does; but I never did do a test about whether it fixes things the way MSDN claims it does. So... for all I know, this might be true! In fact, it's possible that bothSO_REUSEADDR
andSO_EXCLUSIVEADDRUSE
are no-ops these days. Is this true? If so, when did it become true? Which versions of Windows are affected?I suspect that the answers won't affect what we do in Trio itself, but it seems worthwhile to know in any case, so at least we know why we do the quirky platform-specific things we do.
See #39, #72 for more background.
The text was updated successfully, but these errors were encountered: