microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.41k stars 821 forks source link

Windows/WSL AF_UNIX Interop doesn't work in WSL2 #5961

Open conioh opened 4 years ago

conioh commented 4 years ago

Environment

Windows build number: 10.0.19041.508
Your Distribution version: Ubuntu 18.04
Whether the issue is on WSL 2 and/or WSL 1: Regression in WSL2

Steps to reproduce

  1. Launch Ubuntu 18.04 in WSL2.
  2. Run python3 -c "import socket; sock = socket.socket(socket.AF_UNIX); sock.bind('/mnt/d/test.sock')"

python_unix_socket.strace.txt

WSL logs: https://aka.ms/AA9q0yn

Expected behavior

As In WSL1, I expect no error and the D:\test.sock file created:

image

Actual behavior

Error and no file created:

image

therealkenc commented 4 years ago

image

Ref #4240 (message) but that is a different ask for abstract.

conioh commented 4 years ago

@therealkenc Thanks for pointing me to the comment. I've seen the issue but didn't go through all the comments as the issue itself was limited to abstract addresses.

I'm no expert but I see no obvious reason why the enlightened WSL kernel shouldn't be able to communicate with the host and afunix.sys would handle these files on the host too.

Since I'm interested in existing binaries, using AF_INET (or anything else that requires source change) doesn't help me. I used Python just because it was easier to reproduce. Even if it did, I opened this issue for the broader issue and not just to solve my problem with this or that program.

At one point I even considered a temporary solution of hooking both sides and using AF_HYPERV as the underlying transport, but it requires some work and by the time I'm done you might just implement the real deal.

ivan046 commented 3 years ago

@conioh did you get a chance to enable AF_UNIX in WSL2 ?

conioh commented 3 years ago

@conioh did you get a chance to enable AF_UNIX in WSL2 ?

@ivan046, unfortunately I haven't. It's not a matter of simply enabling something. I'd have to multiplex multiple UNIX socket connections over a VSOCK connection. It's not that simple and it wasn't important enough yet. For specific cases there may be simple workarounds like using netcat/socat.

conioh commented 1 year ago

Now that the official way to install WSL means install only WSL2, it is a good time to ask again support for AF_UNIX interop with WSL2.

Sure, WSL1 isn't deprecated and "we currently have no plans to deprecate WSL 1", but we all know what that means:

image

There's no reason to treat WSL2 as a second-class citizen, especially since Microsoft is promoting it so much and since implementing it is basically the same as the current implementation, just with a different enlightenment on the Linux kernel side.

magoerlich commented 8 months ago

Another 2 years later... RollingToasterGIF (2)

maartenvanmalland commented 8 months ago

Isn't this fixed now..see https://github.com/microsoft/WSL/releases/tag/2.0.14 ?

magoerlich commented 8 months ago

Latest Version i can get from the store is 2.0.9.0

psh ❯ wsl -v -l
WSL-Version: 2.0.9.0
Kernelversion: 5.15.133.1-1
WSLg-Version: 1.0.59
MSRDC-Version: 1.2.4677
Direct3D-Version: 1.611.1-81528511
DXCore-Version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows-Version: 10.0.22631.3155

psh ❯ wsl

zsh ❯ python3 -c "import socket; sock = socket.socket(socket.AF_UNIX); sock.bind('/mnt/c/test.sock')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
OSError: [Errno 95] Operation not supported
iongion commented 1 month ago

Are there any recommendations to this ? Some mitigations ? I am trying to relay unix sockets to named pipes, but I have to spawn an additional program and use its stdin and stdout, even that is difficult.