summary refs log tree commit diff stats
path: root/results/classifier/gemma3:27b/syscall/2825
blob: 283fd4559469b6784e9db748fd16decc2a85fa72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
execveat with file descriptor and empty filename returns ENOENT when cross architectures
Description of problem:
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).
Steps to 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 information:
#