mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
f94c11d978
The ape loader now passes the program executable name directly as a register. `x2` is used on aarch64, `%rdx` on x86_64. This is passed as the third argument to `cosmo()` (M1) or `Launch` (non-M1) and is assigned to the global `__program_executable_name`. `GetProgramExecutableName` now returns this global's value, setting it if it is initially null. `InitProgramExecutableName` first tries exotic, secure methods: `KERN_PROC_PATHNAME` on FreeBSD/NetBSD, and `/proc` on Linux. If those produce a reasonable response (i.e., not `"/usr/bin/ape"`, which happens with the loader before this change), that is used. Otherwise, if `issetugid()`, the empty string is used. Otherwise, the old argv/envp parsing code is run. The value returned from the loader is always the full absolute path of the binary to be executed, having passed through `realpath`. For the non-M1 loader, this necessitated writing `RealPath`, which uses `readlinkat` of `"/proc/self/fd/[progfd]"` on Linux, `F_GETPATH` on Xnu, and the `__realpath` syscall on OpenBSD. On FreeBSD/NetBSD, it punts to `GetProgramExecutableName`, which is secure on those OSes. With the loader, all platforms now have a secure program executable name. With no loader or an old loader, everything still works as it did, but setuid/setgid is not supported if the insecure pathfinding code would have been needed. Fixes #991. |
||
---|---|---|
.. | ||
access_test.c | ||
BUILD.mk | ||
cachestat_test.c | ||
chdir_test.c | ||
clock_getres_test.c | ||
clock_gettime_test.c | ||
clock_nanosleep_test.c | ||
closefrom_test.c | ||
commandv_test.c | ||
copy_file_range_test.c | ||
dup_test.c | ||
fchdir_test.c | ||
fchmod_test.c | ||
fchmodat_test.c | ||
fcntl_test.c | ||
fileexists_test.c | ||
ftruncate_test.c | ||
getcontext_test.c | ||
getcwd_test.c | ||
getgroups_test.c | ||
getitimer_test.c | ||
getprogramexecutablename_test.c | ||
getrandom_test.c | ||
ioctl_test.c | ||
life.c | ||
lock2_test.c | ||
lock_ofd_test.c | ||
lock_test.c | ||
lseek_test.c | ||
makedirs_test.c | ||
mkdir_test.c | ||
mkntcmdline_test.c | ||
mkntenvblock_test.c | ||
mkntpath_test.c | ||
open_test.c | ||
openatemp_test.c | ||
openbsd_test.c | ||
pipe_test.c | ||
pledge2_test.c | ||
pledge_test.c | ||
poll_test.c | ||
posix_fadvise_test.c | ||
pread_test.c | ||
preadv_test.c | ||
raise_test.c | ||
read_test.c | ||
readansi_test.c | ||
readlinkat_test.c | ||
readwrite_test.c | ||
renameat_test.c | ||
reservefd_test.c | ||
sched_setscheduler_test.c | ||
seccomp_test.c | ||
setrlimit_test.c | ||
shm_open_test.c | ||
sig_test.c | ||
sigaction_test.c | ||
sigbus_test.c | ||
signal_test.c | ||
sigpending_test.c | ||
sigprocmask_test.c | ||
sigsuspend_test.c | ||
sigtimedwait_test.c | ||
specialfile_test.c | ||
splice_test.c | ||
stackoverflow1_test.c | ||
stackoverflow2_test.c | ||
stackoverflow3_test.c | ||
stackoverflow4_test.c | ||
stat_test.c | ||
statfs_test.c | ||
symlinkat_test.c | ||
timespec_test.c | ||
tiny64.elf | ||
unlinkat_test.c | ||
unveil_test.c | ||
utimensat_test.c | ||
vfork_test.c | ||
write_test.c | ||
writev_test.c | ||
zipread.c |