id = 2825 title = "execveat with file descriptor and empty filename returns ENOENT when cross architectures" state = "opened" created_at = "2025-02-21T13:01:36.698Z" closed_at = "n/a" labels = [] url = "https://gitlab.com/qemu-project/qemu/-/issues/2825" host-os = "Debian 12" host-arch = "x86" qemu-version = "9.2.0" guest-os = "n/a" guest-arch = "n/a" description = """On my x86_64 debian host (with binfmt_misc configured), when calling execveat with a fd , and empty pathname "", and flag AT_EMPTY_PATH. Then only x86_64 and x86 can be called normally, while programs of other architectures (arm64, arm, riscv64, etc.) will return ENOENT errors. I first encountered this problem when trying to run lxc-attach with qemu-aarch64. Its reference is [lxc/stable-6.0/src/include/fexecve.c#L30](https://github.com/lxc/lxc/blob/stable-6.0/src/include/fexecve.c#L30), which is the implementation of the fexecve function. So I wrote a simple test and compiled it with `x86_64/aarch64-linux-gnu-gcc -static test.c -o test`. execveat works fine when running natively or using qemu-x86_64/qemu-i386. When running versions for other architectures, using AT_EMPTY_PATH will result in ENOENT (No such file or directory); use /proc/self/fd/%d as the pathname and execve, it will work fine (like the rest part of the fexecve function). If binfmt_misc is turned off and run forign architectures ver, both calls will result in ENOEXEC (Exec format error).""" reproduce = """1. Install qemu-user and binfmt_misc. Install gcc-aarch64-linux-gnu/gcc-riscv64-linux-gnu etc. 2. Compile test.c with host gcc, then compile forign architectures ver with gcc-aarch64-linux-gnu/gcc-riscv64-linux-gnu etc. like `gcc -static test.c -o test` and `aarch64-linux-gnu-gcc -static test.c -o test-aarch64` 3. Run different versions of test 4. To disable/enable binfmt, you can `echo 0 > /proc/sys/fs/binfmt_misc/qemu-aarch64` or `echo 1 > /proc/sys/fs/binfmt_misc/qemu-aarch64` 5. Sample outputs ``` rrex@debian:~/Downloads$ ./test ****Running to prepare execve fd=3 File size: 772296 bytes execveat with AT_EMPTY_PATH: **Running in execve execveat with fd path: /proc/self/fd/3 **Running in execve rrex@debian:~/Downloads$ qemu-aarch64 ./test-aarch64 ****Running to prepare execve fd=3 File size: 706104 bytes execveat with AT_EMPTY_PATH: !!execveat a fd failed with errno: No such file or directory execveat with fd path: /proc/self/fd/3 **Running in execve ```""" additional = """#"""