WSL icon indicating copy to clipboard operation
WSL copied to clipboard

gzip from Ubuntu Eoan doesn't execute

Open iBug opened this issue 7 years ago • 66 comments

  • 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.

iBug avatar Sep 01 '19 05:09 iBug

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.

Biswa96 avatar Sep 01 '19 06:09 Biswa96

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.

therealkenc avatar Sep 01 '19 21:09 therealkenc

  • 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.

skitt avatar Sep 03 '19 08:09 skitt

For what it's worth, file in eoan produces this output for the two versions of gzip. It seems that some comments in the file are moved around:

$ dpkg -x ./gzip_1.9-3_amd64.deb 1.9-good
$ dpkg -x ./gzip_1.10-0ubuntu3_amd64.deb 1.10-bad
$ file */bin/gzip
1.10-bad/bin/gzip: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=bc0f5994544c2a469d04c914bf4bf44b4ded6040, for GNU/Linux 3.2.0, stripped
1.9-good/bin/gzip: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=efa859c26eaf8e035efe9a139361e2a60cd17b3e, stripped
$ ./1.9-good/bin/gzip --version | head -n1
gzip 1.9
$ ./1.10-bad/bin/gzip --version
-bash: ./1.10-bad/bin/gzip: cannot execute binary file: Exec format error
$ uname -r
4.4.0-18362-Microsoft

chutzimir avatar Sep 04 '19 01:09 chutzimir

Does this need to be reported upstream to Ubuntu?

sirredbeard avatar Sep 09 '19 18:09 sirredbeard

Nope. Because WSL2 works.

Biswa96 avatar Sep 09 '19 18:09 Biswa96

Nope. Because WSL2 works.

Some of us luddites still use WSL1 on our production machines. 😉

I was able to reproduce on Ubuntu Eoan with gzip 1.10.

I cannot reproduce on Debian testing (Pengwin) or unstable which are shipping gzip 1.9-3.

I built gzip 1.10 from source tar from FSF on Debian unstable and Ubuntu Eoan and there was no issue.

sirredbeard avatar Sep 09 '19 20:09 sirredbeard

The issue is in LxCore driver which is part of WSL1 not WSL2, see my first comment, KD output. Hence the issue is from WSL side. PIE is a good security feature. See these two wiki:

  • https://wiki.ubuntu.com/Security/Features#pie
  • https://wiki.ubuntu.com/SecurityTeam/PIE

Biswa96 avatar Sep 09 '19 20:09 Biswa96

The problem doesn't appear to be PIC per se, as skitt points out (thanks skitt). Something is weird about the build. It would take a dive to find out what.

WSL1 on our production machines

Production machine with a unreleased Ubuntu build. Okay.

That said, finding problems like this early is a Good Thing, naturally. Just yanking your chain. #3023 is still on the books for what it is worth. Which was also caught "early".

It might be worthwhile for someone motivated to report the problem upstream and see if the Canonical peeps have any idea what changed. Also trying bleeding edge Debian binaries (Bookworm?) might be worthwhile to see if Canonical just inherited the change.

This is a completely legit WSL1 bug, obviously; but in parallel, making gzip play nice like all of (or most of) the other Eoan binaries would also be a Good Thing.

PIE is a good security feature.

It is. On the other hand...

therealkenc avatar Sep 10 '19 01:09 therealkenc

It would take a dive to find out what.

If ntoskrnl allows to patch kernel mode driver then it would be possible to take a dive.

Biswa96 avatar Sep 10 '19 12:09 Biswa96

I meant dive the Ubuntu gzip package. It was working in Disco. Then it wasn't on Eoan. Finding out what changed in the package or the package's dependencies and/or the build.

therealkenc avatar Sep 10 '19 14:09 therealkenc

They updated it from gzip 1.9 to 1.10.

I .diff'd Ubuntu source packages for both and nothing jumped out at me.

I .diff'd the binary packages in a Hex editor and noted some changes in the headers in the gzip binary.

binary_folders_for_diff.zip

source_folders_for_diff.zip

sirredbeard avatar Sep 10 '19 18:09 sirredbeard

Reported to Ubuntu here.

sirredbeard avatar Sep 10 '19 18:09 sirredbeard

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.

sirredbeard avatar Sep 19 '19 16:09 sirredbeard

That section is "new" alright. I blindly stripped the .plt.sec, similar to #3023, but no joy. Not that blindly stripping a section out of ELF binary would have any expectation of working. Now, thing is, all of the new binaries (f.e. /bin/ls) have that .plt.sec section also, and they work just fine. Also compiling a hello.c with -fcf-protection works. Because of course it does.

The only other new section in there (Disco gzip has 27 sections, Eoan has 29) is .note.gnu.property. No joy after stripping that either. Meh. It's not .note.ABI-tag; I stripped that as a WAG right after this issue was posted.

Which is all a long description of things that don't work. Next thing to try would be to grab the apt-source, try to build a broken binary, and then try to guess what makes gzip so special (contrast say /bin/ls). Still an outside chance gzip can be patched, somehow. But we're deep into work-around territory more complicated than just recompiling from source.

therealkenc avatar Sep 19 '19 21:09 therealkenc

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

benhillis avatar Sep 27 '19 17:09 benhillis

I have updated the bug report filed on gzip in Launchpad accordingly.

sirredbeard avatar Sep 30 '19 18:09 sirredbeard

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

rbalint avatar Oct 08 '19 14:10 rbalint

@benhillis we already publish 19.10 tarballs for WSL and with this bug users can't really use them with WSL1 :-(

rbalint avatar Oct 08 '19 14:10 rbalint

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

benhillis avatar Oct 08 '19 19:10 benhillis