WSL: gzip from Ubuntu Eoan doesn't execute

  • Your Windows build number: 1903 (18362.295)

  • What you’re doing and what’s happening:

    wsl@MSI-GS73:~ $ gzip
    -bash: /bin/gzip: cannot execute binary file: Exec format error
    126|wsl@MSI-GS73:~ $ apt list gzip
    Listing... Done
    gzip/eoan,now 1.10-0ubuntu3 amd64 [installed]
    wsl@MSI-GS73:~ $
    
  • What’s wrong / what should be happening instead:

    gzip from Ubuntu Eoan gives the above unexpected error. The same binary behaves perfectly well on a native Linux box (tested on Ubuntu Bionic / Disco and Debian Stretch / Buster).

  • Strace of the failing command, if applicable: No strace because the binary doesn’t run at all 😦

  • For WSL launch issues, please collect detailed logs.

See our contributing instructions for assistance.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 11
  • Comments: 64 (5 by maintainers)

Most upvoted comments

I am also affected by this bug again in Ubuntu 22.04. Weirdly enough, the rest of the binaries work fine. Only gzip seems to fail.

use this command may help

echo -en '\x10' | sudo dd of=/usr/bin/gzip count=1 bs=1 conv=notrunc seek=$((0x189))

Given the Ubuntu/Debian patches to gzip, it may be safest to follow @maxb’s recommendation to downgrade to Disco’s gzip:

  1. Grab the package from here: https://packages.ubuntu.com/disco/amd64/gzip/download
  2. Install it: sudo dpkg -i ./gzip_1.9-3_amd64.deb
  3. Protect it from automatic upgrade: sudo apt-mark hold gzip

When this issue has been resolved:

  1. Enable upgrade: sudo apt-mark unhold gzip

I got the same error under Ubuntu 22.04, gzip 1.10, WSL1. Solved by upgrading gzip to a newer version, in my case 1.12.

  1. Download it from here (with wget / curl): http://ftp.debian.org/debian/pool/main/g/gzip/
  2. Install it: sudo dpkg -i ./gzip_1.12-1_amd64.deb

The current issue with GZip on Ubuntu is better described in #8219 and it’s cause is different from this thread. It’s caused by the WSL 1 ELF loader. While there might be ways to fix that distro side, it’s quite unpredictable when and which binary will be the next affected by such problem.

Anyone willing to confirm what’s been reported in the referred issue can try the following command to patch the gzip binary and clarify whether that’s accurate or a new issue arose:

echo -en '\x10' | sudo dd of=/usr/bin/gzip count=1 bs=1 conv=notrunc seek=$((0x189))

@nsynecs it works well,thanks!! my WSL1 version is Ubuntu 22.04 LTS.

wget http://ftp.debian.org/debian/pool/main/g/gzip/gzip_1.12-1_amd64.deb   
sudo dpkg -i ./gzip_1.12-1_arm64.deb

The current issue with GZip on Ubuntu is better described in #8219 and it’s cause is different from this thread. It’s caused by the WSL 1 ELF loader. While there might be ways to fix that distro side, it’s quite unpredictable when and which binary will be the next affected by such problem.

Anyone willing to confirm what’s been reported in the referred issue can try the following command to patch the gzip binary and clarify whether that’s accurate or a new issue arose:

echo -en '\x10' | sudo dd of=/usr/bin/gzip count=1 bs=1 conv=notrunc seek=$((0x189))

I can confirm that this works! I had the same problem as the people above. With WSL 1 Ubuntu 22.04 installing Visual Studio Code would throw the following error:

$ code .
Updating VS Code Server to version b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a
Removing previous installation...
Installing VS Code Server for x64 (b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a)
Downloading: 100%
@@@@: Permission denied
/usr/bin/gzip: 3: : not found
/usr/bin/gzip: 4: Syntax error: "(" unexpected
tar: Child returned status 2
tar: Error is not recoverable: exiting now

tar is unable to read /home/alange/.vscode-server/bin/b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a-1658171981.tar.gz. Either the file is corrupt or tar has an issue.
There's a known WSL issue with tar on Ubuntu 19.10.
See workaround in https://github.com/microsoft/vscode-remote-release/issues/1856.
Reload the window to initiate a new server download.

After running your magic line it immediately worked:

$ code .
Updating VS Code Server to version b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a
Removing previous installation...
Installing VS Code Server for x64 (b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a)
Downloading: 100%
Unpacking: 100%
Unpacked 2799 files and folders to /home/<user>/.vscode-server/bin/b06ae3b2d2dbfe28bca3134cc6be65935cdfea6a.

Hitting this on rocky linux and fixed by

yum install tar
echo -en '\x10' | sudo dd of=/usr/bin/gzip count=1 bs=1 conv=notrunc seek=$((0x189))

Fixed it for me as well.

We have also released a fixed gzip in Ubuntu. Just run apt update && apt install gzip on Eoan to get the fix and make gzip work with earlier Windows 10 releases as well.

Confirmed better in 19025 WSL 1.

image

Reported to Ubuntu here.

@nsynecs, thank you, fixed right now. I used this version for WSL Ubuntu 22.04 x86_x64.

@rbalint - Yes, I will see about getting this backported.

Thanks for filing this issue, I identified where this is blowing up in our elf loader and will submit a fix.

  • Ubuntu Disco and lower: file $(which gzip) command shows ELF 64-bit LSB shared object.
  • Ubuntu Eoan: file $(which gzip) command shows ELF 64-bit LSB pie executable.

The difference here isn’t related to a change in gzip, but to a change in file. Ubuntu binaries have been built with PIE for a while; but it’s only recently (coreutils 5.33) that file has started identifying them as PIE executables rather than shared objects.

@as17501 's solution works for WSL 1, Ubuntu 22.04. eg:

wget http://ftp.debian.org/debian/pool/main/g/gzip/gzip_1.12-1_amd64.deb   
sudo dpkg -i ./gzip_1.12-1_arm64.deb

That being said - I’m surprised this bug to a core piece of Ubuntu software (gzip) used in a distribution somehow made it into production. Am I missing something and there’s very little testing of WSL, or is this a separation of concerns issue where “WSL works” from a Microsoft standpoint, but the Ubuntu distribution doesn’t; eg it’s Canonical’s issue. Should we be raising it with Canonical as the issue has been around since 2019. Cheers

Note binaries are built with debug symbols, which are then stripped. Maybe stripping is bad. Also maybe dwz debug symbols are not compatible with our stripping. Possibly binutils regression in eoan.

Things to try:

  • use disco binutils
  • build with nostrip in eoan
  • build without dwz & with stripping in eoan

@rbalint - File is only 97496 bytes, this PT_LOAD header is outside of that range.

        Entry #6: PT_LOAD
            Element Type: PT_LOAD (0x00000001)
            0000 .... .... .... .... .... .... .... = Processor Specific Flags: False
            .... 0000 0000 .... .... .... .... .... = Operating System Specific Flags: False
            .... .... .... 0000 0000 0000 0000 0... = Reserrved Flags: False
            .... .... .... .... .... .... .... .1.. = Read Flag: True
            .... .... .... .... .... .... .... ..1. = Write Flag: True
            .... .... .... .... .... .... .... ...0 = Execute Flag: False
            File Offset: 98304 (0x0000000000018000)
            Virtual Address: 0x000000000001a000
            Physical Address: 0x000000000001a000
            File Image Size: 0 (0x0000000000000000)
            Memory Image Size: 827464 (0x00000000000ca048)
            Align: 4096 (0x0000000000001000)

Nope. Because WSL2 works.

gzip package version 1.10-4ubuntu4.1 was published with a patch that addresses this particular issue. sudo apt update && sudo apt install gzip is enough to install it.

I thought the gzip patch fixed my issue on WSL 2, but as it turned out, I was using WSL 1 and didn’t realize it! run wsl -l -v to be sure.

@as17501 in your example you wget amd but then dpkg arm

@benhillis fixed binutil’s strip and recompiled gzip. The fixed binutils tries to not point the offset past EOF, so we don’t trigger the problem in WSL1 with new binaries. It is funny that only gzip was affected in the archive. Ubuntu 20.04 and later also have the fix already.

Given the Ubuntu/Debian patches to gzip, it may be safest to follow @maxb’s recommendation to downgrade to Disco’s gzip:

  1. Grab the package from here: https://packages.ubuntu.com/disco/amd64/gzip/download
  2. Install it: sudo dpkg -i ./gzip_1.9-3_amd64.deb
  3. Protect it from automatic upgrade: sudo apt-mark hold gzip

When this issue has been resolved:

  1. Enable upgrade: sudo apt-mark unhold gzip

Thank you. It seems like it is a temporary solution for:

  1. https://github.com/tj/n/issues/594
  2. https://github.com/microsoft/vscode-remote-release/issues/1744

@maxb - Sure. The issue is that our loader was not correctly handling program headers that would exceed the size of the file itself. The offending program header file size of zero but an offset that was greater than the size of the binary. Hope that helps.

@benhillis could you please backport the fix to non-insider versions?

From upstream:

I tried comparing the binaries with diffoscope, and one difference which jumped out at me is the .plt.sec section which is present in the Eoan binary. This presumably comes from CET (gcc -fcf-protection). There are other differences, less significant IMO; .plt.sec is a likely candidate for something WSL1 might not support.

The interesting thing is they are all PIE (f.e. /bin/ls), and yet the whole Ubuntu edifice doesn’t fall down. I took a quick look with readelf(1) and there isn’t anything glaring, but isn’t saying much.

Reasonable enough WSL1 work around would be to install your own /usr/local/bin/gzip I guess, although we can’t know what other executables other than gzip might be problematic.

I can reproduce your issue in latest Windows 10 Pro insider build 18970. Here are some points that I found:

  • Ubuntu Disco and lower: file $(which gzip) command shows ELF 64-bit LSB shared object.
  • Ubuntu Eoan: file $(which gzip) command shows ELF 64-bit LSB pie executable.
  • KD output: LX: (FFFF800368A7C2C0, FFFF800367A04080) (-bash) LxpElfInfoParse: ElfSizeAdd
  • Conclusion: The bug is in the ELF parsing function in LxCore driver.
  • Workaround: Use WSL2.