genie icon indicating copy to clipboard operation
genie copied to clipboard

Genie 2.4 breaks WSL interop on Windows 10

Open Elberet opened this issue 2 years ago • 6 comments

Windows version (build number): Windows 10 21H2 (19044.1766)

Linux distribution: Ubuntu 20.04

Kernel version: 5.10.102.1-microsoft-standard-WSL2

Genie version: genie 2.4

Describe the bug Genie 2.4 by default installs /usr/lib/binfmt.d/WSLInterop.conf. This file is used by systemd to register the miscellaneous binary wrapper for WSL interop in the kernel. The registration includes a set of flags that tell the kernel how to interact with the wrapper. At least for my local Windows machine, these flags are wrong and result in WSL Linux becoming unable to launch any Windows binaries through the WSL /init wrapper.

To Reproduce Steps to reproduce the behavior:

  1. Create new WSL space:
    wsl --unregister Ubuntu-20.04
    wsl --install -d Ubuntu-20.04
    
  2. Install genie (wsl -u root or sudo su -):
    curl -Ls -o /etc/apt/trusted.gpg.d/wsl-transdebian.gpg "https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg"
    echo "deb https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main" >/etc/apt/sources.list.d/wsl-transdebian.list
    echo "deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main" >>/etc/apt/sources.list.d/wsl-transdebian.list
    ssh-keygen -A
    awk -i inplace '($2=="/" && /^[^#]/){ print "#"$0; next } 1' /etc/fstab
    systemctl mask getty.target
    systemctl mask multipathd.service
    systemctl mask multipathd.socket
    systemctl mask apport-forward.
    systemctl mask iscsid.socket
    systemctl mask apport-autoreport.path
    systemctl mask systemd-modules-load.service
    systemctl set-default multi-user.target
    systemctl disable sshd.service
    systemctl disable ModemManager.service
    systemctl disable ufw.service
    systemctl disable apport.service
    systemctl disable unattended-upgrades.service
    apt-get update && apt-get install -y systemd-genie
    
  3. Check WSL interop binfmt_misc configuration:
    # genie -b
    no-bottle
    # cat /proc/sys/fs/binfmt_misc/WSLInterop
    enabled
    interpreter /tools/init
    flags: F
    offset 0
    magic 4d5a
    
  4. Start genie and repeat above:
    # genie -s
    Waiting for systemd....!!
    # genie -b
    inside
    # cat /proc/sys/fs/binfmt_misc/WSLInterop
    enabled
    interpreter /init
    flags: PF
    offset 0
    magic 4d5a
    
    Note that the flags have changed.
  5. Attempt to run any Windows binary from within WSL:
    $ genie -b
    inside
    $ /mnt/c/Windows/System32/reg.exe "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage"
    FEHLER: Ungültiges Argument/Option - '/mnt/c/Windows/System32/reg.exe'.
    Geben Sie "REG /?" ein, um die Syntax anzuzeigen.
    
    Due to the altered binfmt flags, reg.exe ended up being called with the Linux argv[0] as an additional command line argument, preceding the expected arguments, and failed with an error message.

Expected behavior Genie should not break WSL interop. Specifically, if the binfmt misc configuration depends on the Windows version, Genie should detect the version it is running on and adjust the binfmt configuration to match. If the Windows version is not or no longer supported, Genie should at least emit a noticeable warning.

Additional context The change to /usr/lib/binfmt.d/WSLInterop.conf was introduced in response to #267, where a user on Windows 10.0.22598.200 reported a problem with WSL interop. Build 22598 is a Windows 11 insider preview build, not a full release.

I confirm that I have read the ENTIRE supplied readme file and checked for relevant information on the repository wiki before raising this issue, and that if the solution to this issue is found in either location, it will be closed without further comment:

  • [X] Yes.

Elberet avatar Jun 29 '22 12:06 Elberet

I just noticed #264. Apparently, the binfmt wrapper's behaviour is inconsistent between Windows 10 and release versions of Windows 11, not just insider previews. So for Windows 10 users (like myself, because my perfectly good i7 7700K is not recent enough for Windows 11 😖), the change introduced in ebca3e32 straight up breaks WSL, while it is absolutely required on Windows 11...

Elberet avatar Jun 29 '22 13:06 Elberet

Manual update of /usr/lib/binfmt.d/WSLInterop.conf to revert change mentioned above seems to fix issue on Win10/Debian.

denskh avatar Jun 30 '22 13:06 denskh

@Elberet Not that it has anything to do with your issue, but I'm curious about the following in your installation procedure:

systemctl mask apport-forward.

Where does that come from? I see the same in another bug report, but is that the correct syntax? Shouldn't it be?

systemctl mask apport-forward.socket
# or
systemctl mask apport-forward@

The line as it is creates:

/etc/systemd/system/apport-forward..service -> /dev/null

With double-dots, which doesn't seem correct, right?

NotTheDr01ds avatar Jul 17 '22 14:07 NotTheDr01ds

You're right, that's probably a simple typo in my script. It shouldn't have any effect on the interop issue, tho.

Elberet avatar Jul 17 '22 16:07 Elberet

Trying to parse this, so to fix /usr/lib/binfmt.d/WSLInterop.conf is set with P or PF?

YenLegion avatar Jul 30 '22 22:07 YenLegion

The correct set of flags depends on the Windows version:

  • Windows 10 21H2 requires F.
  • Windows 11 requires PF.

Genie 2.4 now defaults to PF. If you are running Windows 10, set the flags field in /usr/lib/binfmt.d/WSLInterop.conf to F.

The reason for this difference is that the behaviour of the WSL helper binary (/init) changes. It is not known exactly when that change was or will be introduced, only that it's sometime between Windows versions 19044.1826 (mine) and 22598.200 (as per #267).

A full explanation of what these flags mean can be found at https://www.kernel.org/doc/Documentation/admin-guide/binfmt-misc.rst.

Elberet avatar Jul 31 '22 03:07 Elberet

Fixed in 2.5, shipping as soon as a psutil issue is resolved.

cerebrate avatar Sep 07 '22 18:09 cerebrate