WSL: binfmt_misc flags: 'OC' not working

  • Your Windows build number: (Type ver at a Windows Command Prompt) OS Name: Microsoft Windows 10 Pro OS Version: 10.0.16299 N/A Build 16299

  • What you’re doing and what’s happening: (Copy&paste specific commands and their output, or include screen shots)

“~/wheezy/” is arm rootfs. I have installed qemu-user-static.

For a simple test qemu-arm-static executable, ~/wheezy/bin/ls, expected results would be: $ ~/wheezy/bin/ls /lib/ld-linux.so.3: No such file or directory

While actual results are: $ ~/wheezy/bin/ls prepare_binprm: Bad file descriptor

Explicit invocation of qemu-arm-static, however, works: $ qemu-arm-static ~/wheezy/bin/ls /lib/ld-linux.so.3: No such file or directory

Show the binfmts list, it is OK: `update-binfmts --display qemu-arm

qemu-arm (enabled): package = qemu-user-static type = magic offset = 0 magic = \x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00 mask = \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff interpreter = /usr/bin/qemu-arm-static detector = `

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 10
  • Comments: 15

Most upvoted comments

WSL’s builtin binfmt support doesn’t seem to like the fancy flags: OC. Or that’s how it looks. So from the top with repetition from Froosh:

$ sudo apt install debootstrap qemu-user-static
$ sudo service binfmt-support start
$ sudo debootstrap --verbose --arch=armel --variant=minbase --foreign stretch debian-armel/
$ sudo cp /usr/bin/qemu-arm-static debian-armel/usr/bin/
$ # pop the interpreter as registered by qemu-user-static package
$ sudo update-binfmts --package qemu-user-static --remove qemu-arm /usr/bin/qemu-arm-static
$ # add it back without any special options
$ sudo update-binfmts --install qemu-arm /usr/bin/qemu-arm-static --magic '\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
$ sudo mount --bind /dev debian-armel/dev
$ sudo mount --bind /dev/pts debian-armel/dev/pts
$ sudo mount --bind /proc debian-armel/proc
$ sudo mount --bind /sys debian-armel/sys
$ # don't forget WSL's binfmt_misc filesystem
$ sudo mount --bind /proc/sys/fs/binfmt_misc debian-armel/proc/sys/fs/binfmt_misc
$ sudo cp -afL /etc/resolv.conf debian-armel/etc  # we'll want this for apt
$ sudo chroot debian-armel/ /bin/bash

And, after doing the second stage and installing a few packages with the armel apt binary, would you look at that:

wsl-armel

I’m getting Unsupported syscall: 384 (notably on lsb_release, shrug) but otherwise it is working surprisingly well. Performance seems alright to the naked eye.

Okay – @benhillis, here is a repro that is a little easier to eat than a full blown debootstrap:

$ sudo apt install qemu-user-static
$ # make the binfmt-support postinstall script happy just to be safe, but I doubt it matters
$ sudo bash -c "echo '[1] [00049] [~~  ] [runlevel] [~           ] [4.4.0-17115-Micoroso] [0.0.0.0        ] [Wed Feb 28 13:27:14 2018 STD]' | utmpdump -r > /var/run/utmp"
$ sudo apt install --reinstall binfmt-support
$ sudo service binfmt-support start # registers qemu-arm binfmt
 * Enabling additional executable binary formats binfmt-support                                       [ OK ]
$ cat /proc/sys/fs/binfmt_misc/qemu-arm
enabled
interpreter /usr/bin/qemu-arm-static
flags: OC
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00fffffffffffffffffeffffff
$ wget https://github.com/andrew-d/static-binaries/raw/master/binaries/linux/arm/file
$ hexdump ./file | head -n 2
0000000 457f 464c 0101 0001 0000 0000 0000 0000
0000010 0002 0028 0001 0000 340c 0001 0034 0000
$ chmod 755 ./file
$ ./file ./file
prepare_binprm: Bad file descriptor

The strace -f -o file.strace ./file ./file looks the same as reported, including the absent open() [edit: wait, maybe it’s not an open()].

mmap(NULL, 151552, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2b1e090000
gettid()                                = 890
[edit: something happens here]
fstat(3, {st_mode=S_IFREG|0755, st_size=194976, ...}) = 0
geteuid()                               = 1000
getegid()                               = 1000
read(3, 0x7ffffa628160, 1024)           = -1 EBADF (Bad file descriptor)

I don’t think the fact that qemu-arm-static is the registered interpreter matters here. That much appears to be working fine.

Windows version: Microsoft Windows [Version 10.0.17120.1]

WSL App ‘Ubuntu’ version: 1604.2017.922.0

Steps to reproduce on a fresh WSL Ubuntu instance:

sudo apt install debootstrap qemu-user-static
sudo service binfmt-support start
sudo debootstrap --verbose --arch=armel --variant=minbase --foreign stretch debian-armel/
sudo cp /usr/bin/qemu-arm-static debian-armel/usr/bin/
sudo mount --bind /dev debian-armel/dev
sudo mount --bind /dev/pts debian-armel/dev/pts
sudo mount --bind /proc debian-armel/proc
sudo mount --bind /sys debian-armel/sys
sudo strace -vff -o implicit.strace chroot debian-armel/ /bin/bash

Result (doesn’t work): prepare_binprm: Bad file descriptor

Strace log: https://gist.github.com/Froosh/dc472dc953dd534806d68a1040e4c10e

Alternate explicit qemu-arm-static invocation: sudo strace -vff -o explicit.strace chroot debian-armel/ /usr/bin/qemu-arm-static /bin/bash

Result (works): I have no name!@Froosh-Book:/#

Strace log: https://gist.github.com/Froosh/267e1c2db65e0359e56034610cf328f0

The main difference (apart from memory addresses/times/etc) is a missing call to open() which returns FD 3.

Implict invocation:

gettid()                                = 169
fstat(3, {st_dev=makedev(0, 2), st_ino=1407374884004467, st_mode=S_IFREG|0755, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=2000, st_size=1021372, st_atime=2018/03/16-12:47:13.221254200, st_mtime=2017/05/16-05:45:32, st_ctime=2018/03/16-12:47:13.268238900}) = 0
geteuid()                               = 0
getegid()                               = 0
read(3, 0x7fffc8464780, 1024)           = -1 EBADF (Bad file descriptor)

Explicit invocation:

gettid()                                = 175
open("/bin/bash", O_RDONLY)             = 3
fstat(3, {st_dev=makedev(0, 2), st_ino=1407374884004467, st_mode=S_IFREG|0755, st_nlink=1, st_uid=0, st_gid=0, st_blksize=4096, st_blocks=2000, st_size=1021372, st_atime=2018/03/16-12:47:13.221254200, st_mtime=2017/05/16-05:45:32, st_ctime=2018/03/16-12:47:13.268238900}) = 0
geteuid()                               = 0
getegid()                               = 0
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\2\0(\0\1\0\0\0\300\327\2\0004\0\0\0"..., 1024) = 1024