-
Notifications
You must be signed in to change notification settings - Fork 830
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
AF_UNIX abstract on Windows do not work #4240
Comments
I almost posted this one myself sometime last year after having burned an evening trying to use abstract names. [The announcement blog doesn't say they aren't supported, although no Heads up we lost named AF_UNIX Windows interop in WSL2 (for now anyway). But even if we get that back 🙏, the fact that WSL2 is not in the same network namespace (nvm mount namespace) as win32 speaks to why abstract names is hard. For time being, the way in and out of WSL (notwithstanding extreme unsupported measures) is through interop stdin/stdout/stderr and AF_INET. |
Thanks @therealkenc , but the blog post does explicitly state "The second category is the ‘abstract’ socket address where the first character in ‘sun_path’ is a null byte. Windows implementation of AF_UNIX socket can also accept abstract addresses". I am not really interested in interop with WSL, and while I don't see why they direct support for Winsock here, I hope it reaches someone who cares. There's some real strangeness going on in this "feature" because I can run the code from I guess AF_INET on loopback is always an option for me in my specific use-case. |
Indeed, it does; thanks. I knew there must have been a reason I spent so long trying to make it work.
I actually don't know the right place to reach someone who might care. I do hope someone does. Windows SDK forum maybe? [Noting that I didn't post there at the time either, and punted AF_INET pretty quick.] My scenario at the time was interop with WSL though. If you are pure-play win32, I guess SOP would be win32 pipes. Closing with tag question, since WSL is not the use case. Appreciate the post though, since it's a pretty good question regardless. |
Well, the blog post explicitly points to this issue tracker as a place to provide feedback for AF_UNIX on Windows, and the forums have always been beyond useless. So, I'd like it left open for a real answer if that's possible. thanks. |
Let's leave this open, it was our team that did the AF_UNIX work. |
What I am seeing on Win10 18362 is that a process cannot see another process's abstract sockets, connect(2) fails and bind(2) works uniquely across multiple processes. After debugging this issue and concluding the above, I found this: microsoft/WSL#4240 So it seems I am not the only one to note it.
@therealkenc what do you mean by that? Also, how is WSL connecting to the 9P server to share the Linux filesystem now? I thought it was using a Unix socket in /run/WSL/_interop. |
I mean, we lost named
Wouldn't know. Probably a hyper-v socket, but that's only a guess.
That path is not on |
can we please not bring WSL into this ? I know this is a WSL issue tracker, but I specifically filed a Windows bug. If you have similar WSL issues, please separate them. thanks. |
I also encountered this problem, AF_UNIX abstract on Windows, but connect always returns EINVAL, |
I also have problems with named AF_UNIX sockets, bind & listen & select work, but when I call accept in a response to a successful read select, I mysteriously get a WSAENOTSOCK error. I was not able to find any example code for AF_UNIX sockets on Windows. Do you have some working examples (named and/or abstract)? This doesn't look like the right place to report this, since it is unrelated to WSL, but I am also missing a better feedback channel. |
I have this problem as well: non-abstract The entire reason I am doing this is so that I can implement my own By the way, if you do implement |
This feature is simply not implemented. The |
Why does this blog post from Microsoft claim that "Windows implementation of AF_UNIX socket can also accept abstract addresses" then? And why is @microsoft deleting comments? |
well, that comment was just me ranting, so it definitely deserved to be deleted :) Nothing useful was lost in that deletion. |
Will this ever be worked on? |
Oh and maybe someone can correct the original blog post at https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/? I've lost a day's work due to this (know) limitation :-( |
Windows implementation of AF_UNIX does not support abstract sockets (as already established here so far) and we have very less desire to implement it since it lacks the Windows security model (abstract unix sockets cannot be secured). The blog post is incorrect and we take responsibility for that (we will correct it). And, we do apologize for the confusion caused here. |
Thanks @sunilmut ! |
@sunilmut The entire reason I tried to use abstract sockets was so that I could interrupt As for the security issue, the way I got around the problem of other processes connecting to my socket in the timing window was to use All this could be avoided with a (Yes, you can queue a user-mode APC to a |
@sunilmut So there are no abstract sockets in Windows and I wasted a couple of days and there are also no docs about AF_SOCKET here: https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-start-page-2 Very nice! Maybe the doc issues could be rectified too? |
Your solution is indeed excellent and probably the best right now. The only thing I would do differently is use |
Thanks! That's a great addition. Will include that when I try to contribute it back upstream to https://github.com/ncm/selectable-socketpair/blob/master/socketpair.c |
Sure, no problem! |
Windows forces us to use named-path Unix sockets. Generating a path in the temporary directory, combining current high-res time and PID, seems like a less-bad option. On GitHub, a commenter [suggested](microsoft/WSL#4240 (comment)) that it would be better to use [GetTempFileName](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea) here. However, that function: - Only adds 16 bits of time-based random bits, - Will currently fail if there aren't 14 characters available for the filename, - Might conceivably generate paths longer than UNIX_PATH_MAX, and - Offers no other apparent offsetting advantages Signed-off-by: Daniel Lenski <[email protected]>
Is the socket file not deleted when |
It is not, in the Windows 10 implementation. My temp directory is littered with size-0 files that were Unix domain sockets. |
Solution: call |
https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_EXTENSIONS.html Regarding abstract sockets on Windows: microsoft/WSL#4240
…eeded Small follow-up improvement to https://gitlab.com/openconnect/openconnect/-/merge_requests/320, which made dumb_socketpair() able to use Unix-domain sockets, on those Windows versions that support them albeit only with named paths. This was suggested as a way to prevent the Windows dumb_socketpair() implementation from leaving behind size-0 files, even if normally only in temporary directories. See original suggestion at microsoft/WSL#4240 (comment). Signed-off-by: Daniel Lenski <[email protected]>
…eeded Small follow-up improvement to https://gitlab.com/openconnect/openconnect/-/merge_requests/320, which made dumb_socketpair() able to use Unix-domain sockets, on those Windows versions that support them albeit only with named paths. This was suggested as a way to prevent the Windows dumb_socketpair() implementation from leaving behind size-0 files, even if normally only in temporary directories. See original suggestion at microsoft/WSL#4240 (comment). Signed-off-by: Daniel Lenski <[email protected]>
That misleading blogpost! Lost 2 days. |
Please implement correct support for |
This PR is based on the improvements we made in OpenConnect in https://gitlab.com/openconnect/openconnect/-/merge_requests/320. Unfortunately, and maddeningly, it's possible for the local IPv4 routes (127.0.0.0/8) to be deleted on Windows; this will prevent dumb_socketpair() from working in its current form. Using AF_UNIX sockets - AF_UNIX/SOCK_STREAM became available in Windows 10: https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows - There appears to be no other documentation whatsoever of Windows's support for AF_UNIX sockets. - Contrary to the claims of that blog post, abstract sockets (filesystem-independent) are not implemented: microsoft/WSL#4240 (comment) In order to deal with the above weaknesses, the approach taken here is to first try creating an AF_UNIX socketpair, and then to fallback to AF_INET if it fails. Furthermore, because the AF_UNIX socketpair requires a real, writable filesystem path, it tries binding to each of the following before giving up on AF_UNIX: 1. GetTempDir() \ (filename including PID and 64-bit time ticks) 2. GetWindowsDirectory() \ Temp \ (...) 3. C:\TEMP \ (...) 4. . \ (...) Based on testing so far, this implementation appears to be robust and to avoid the problems with deleted IPv4 localhost routes. Also adds a stub for the <afunix.h>, which defines `UNIX_PATH_MAX` and `struct sockaddr_un`. MinGW lacks this header, but other FLOSS projects show how to embed the needed definitions: - MisterDA/ocaml@5855ce5 - https://github.com/curl/curl/blob/curl-7_74_0/lib/config-win32.h#L725-L734
btw
it would be nice of the unnamed AF_UNIX socket may be changed to a working state. I dont see an security problem, because the used internal name (handle) can be calculated by the members of microsoft themself. no one can do it better and more secure than a microsoft member. To get more secured sockets for internal communication it would be great to get the unnamed AF_UNIX sockets working. Source: But unnamed sockets with length "2" (just sun_family=AF_UNIX not path) lead into the same not available error message. |
where to put this afunix.h file. |
The file afunix.h is part of visual studio / windows kits / wsdk. If not beside winsock2.h or stdio.h on your disk, you may need sdk (Software development kit) / visual studio updates. The file afunix.h is an include file to get header definitions in your code. You should not deliver this file. |
@keith-horton @CatalinFetoiu @OneBlue folks are you able to address this issue and the incorrect blog post? This is causing a lot of confusion, and it's been ~5 years since the issue was reported. |
ver
at a Windows Command Prompt)18362.175
Trying to create an "abstract" namespace AF_UNIX application.
connect always returns EINVAL, regardless of what I try.
The text was updated successfully, but these errors were encountered: