jart / blink

tiniest x86-64-linux emulator
ISC License
7k stars 224 forks source link

fstatat broken with AT_EMPTY_PATH #98

Closed Vogtinator closed 1 year ago

Vogtinator commented 1 year ago

After 1a88cd3c3bdf2b501bb3d09987b4438c0daf12c3, I can no longer run dynamically linked binaries due to

I2023-04-07T21:23:06.503983:blink/strace.c:776:7430 (sys) openat(AT_FDCWD, "/lib64/libcrypt.so.1", O_RDONLY|O_CLOEXEC) -> 1
I2023-04-07T21:23:06.503999:blink/strace.c:776:7430 (sys) read(1 "/lib64/libcrypt.so.1", ["⌂ELF☻☺☺         ♥ > ☺           "..., 832]) -> 832
I2023-04-07T21:23:06.504055:blink/strace.c:776:7430 (sys) fstatat(1 "/lib64/libcrypt.so.1", "", [0x4fffffffda90], AT_EMPTY_PATH) -> -ENOENT
I2023-04-07T21:23:06.504062:blink/strace.c:776:7430 (sys) close(1) -> 0
/usr/bin/busybox: error while loading shared libraries: libcrypt.so.1: cannot stat shared object: No such file or directory

The issue is that AT_EMPTY_PATH is not handled properly by SysFstatat. OverlaysGeneric just returns -ENOENT if the path is empty.

Also, there appears to be some unreachable code:

https://github.com/jart/blink/blob/f49c38dcf42816ae3e8cceca68b9d9cae6f8ed82/blink/syscall.c#L2846-L2853

Line 2847 should probably be flags &= ~AT_EMPTY_PATH_LINUX; instead?

jart commented 1 year ago

Thanks for the report. Working on this now.