binfmt-support - not allowing me to echo to register

3

I am using ubuntu linux. Trying to add support of ARM interpreter to binfmt. I am getting permission denied error.

Just added support to binfmt on my machine :---

sudo apt-get install binfmt-support

ls in directory binfmt_misc :--

ignite@ignite:/proc/sys/fs/binfmt_misc$ ls 
python2.7  python3.2  register  status

binfmt_misc Filesystem is correctly mounted :---

ignite@ignite:/proc/sys/fs/binfmt_misc$ mount
/dev/sda8 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfsd-fuse on /run/user/ignite/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=ignite)

module is up & running :---

ignite@ignite:/proc/sys/fs/binfmt_misc$ cat /proc/modules | grep binfmt*
binfmt_misc 17260 1 - Live 0x00000000

Status is showing enabled :-----

ignite@ignite:/proc/sys/fs/binfmt_misc$ cat status 
enabled

Error at the time of echo to register file even using sudo :---

ignite@ignite:/proc/sys/fs/binfmt_misc$ sudo echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/var/local/rpi/qemu/bin/qemu-arm:' > /proc/sys/fs/binfmt_misc/register
bash: /proc/sys/fs/binfmt_misc/register: Permission denied

Why it is not allowing me to echo to register, even as sudo ?

Edit :---
This command is working, arm folder is created :---

ignite@ignite$ echo "echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-arm:' > /proc/sys/fs/binfmt_misc/register" | sudo sh

ignite@ignite:/proc/sys/fs/binfmt_misc$ ls
arm  python2.7  python3.2  register  status


ignite@ignite:/proc/sys/fs/binfmt_misc$ cat arm 
enabled
interpreter /usr/local/bin/qemu-arm
flags: 
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00fffffffffffffffffeffffff

But i am not able to run arm executable. This is an pre compiled program of hello world.

ignite@ignite:~/testing$ file a.out 
a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.6.3, not stripped
ignite@ignite:~/testing$ ./a.out 
/lib/ld-linux-armhf.so.3: No such file or directory

Do i have to perform chroot to execute this arm executable?

linux
linux-kernel
asked on Stack Overflow Jul 23, 2013 by Katoch • edited Jul 23, 2013 by Katoch

3 Answers

2

This command:

sudo echo xyz > /proc/sys/fs/binfmt_misc/register

Executes as you, not the superuser. So, first your shell open()s /proc/sys/fs/binfmt_misc/register, then it fork/execs "sudo echo xyz", ...

To fix it, do this:

sudo sh -c 'echo xyz > /proc/sys/fs/binfmt_misc/register'
answered on Stack Overflow Jul 23, 2013 by Brian Cain
1

Answer to the second part of your question is following.

When running your executable the system gives you error message:

ignite@ignite:~/testing$ ./a.out
/lib/ld-linux-armhf.so.3: No such file or directory

This explains what went wrong. It seems you have compiled your source file with /lib/ld-linux-armhf.so.3 dynamically linked shared library by mean of -L/lib/ld-linux-armhf.so.3. And that library could not be found in runtime.

Either check that ld-linux-armhf.so.3 file can be found on the path mentioned (/lib) or try to explain the system where to find your .so-file with the command:

export LD_LIBRARY_PATH=/path/to/your/lib:$LD_LIBRARY_PATH

answered on Stack Overflow Apr 2, 2014 by zergius
0

Depending on how your file system is setup and where your shared libraries live (especially true with chroots or docker containers)

Ensure that the F flag (fix-binaries) is set.

/proc/sys/fs/binfmt_misc # cat qemu-arm
enabled
interpreter /usr/bin/qemu-arm
flags: OCF
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00fffffffffffffffffeffffff
answered on Stack Overflow Apr 2, 2019 by oliver

User contributions licensed under CC BY-SA 3.0