Files
Gavin Hayes fdea2482dd Rewrite fexecve for better zipos & APE handling (#888)
This is essentially a rewrite of the entire `fexecve` implementation. We
no longer attempt to attempt to assimilate APEs in mem -- if the syscall
fails we fallback to sys_execve(/dev/fd/X so the APE loader can be used.
When a zipos file descriptor is passed, the new memfd is now only leaked
if the file has zipos (is a ZIP file) or is an APE, otherwise FD_CLOEXEC
is set on it (so non-zip ELFs do not leak). Previously FD_CLOEXEC on APE
binaries was not set when copying to a `memfd`, due to the security risk
of still leaking a fd, we no longer do so. FD_CLOEXEC does not work with
the APE loader (we may be able to later add support using AT_EXECFD). On
Linux, non-zip ELF files with only execute permissions may be opened and
run with _OPATH. The new version is vforksafe+asyncsignalsafe. To ensure
even on failure, the `memfd` will be cleaned up, pthread_cleanup_push is
used. zipos fexecve fails with `ENOTSUP` when `__vforked` so it does not
leak a `memfd` into the parent process if there is pthread cancellation.

The tests were revamped to more completely cover the various branches of
ELF or APE, zip file or not, `FD_CLOEXEC`, `O_PATH`, zipos fd or not, or
vforked. Additionally, there are checks for fd leaks. Feature testing is
done on Linux for the tests that rely on kernels newer than 2.6.18 so in
theory they should still pass on old Linux. For now, the zipos (f)execve
tests are only enabled on Linux as they have not been tested on FreeBSD.
The test files pass on Linux, Qemu user aarch64/x86_64, and Windows Ten.
2026-10-07 01:54:35 -04:00
..
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2023-12-07 22:17:11 -05:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2023-12-07 22:17:11 -05:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2024-02-12 10:23:00 -08:00
2024-02-12 10:23:00 -08:00
2024-02-12 10:23:00 -08:00
2025-11-16 21:15:26 -08:00
2024-07-27 09:16:54 -07:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2023-12-07 22:17:11 -05:00
2023-12-07 22:17:11 -05:00
2025-11-16 21:15:26 -08:00
2024-06-01 16:30:43 -04:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2023-10-11 21:45:32 -07:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00
2025-11-16 21:15:26 -08:00