cosmopolitan/libc/nexgen32e
Jōshin f94c11d978
Loader path security (#1012)
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.
2023-12-15 12:23:58 -05:00
..
argc.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
argc2.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
argv.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
argv2.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
auxv.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
auxv2.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
bench.h Reduce header complexity 2023-11-28 14:39:42 -08:00
blink_linux_aarch64.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
blink_xnu_aarch64.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
BUILD.mk Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
cachesize.h Reduce header complexity 2023-11-28 14:39:42 -08:00
checkstackalign.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
cpuid4.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
crc32.h Reduce header complexity 2023-11-28 14:39:42 -08:00
crc32init.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
djbsort-avx2.S Clean old .source directive out of asm code 2022-03-18 12:43:21 -07:00
environ.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
environ2.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
envp.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ffs.h Reduce header complexity 2023-11-28 14:39:42 -08:00
gc.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
gc.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
gclongjmp.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
hascharacter.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
identity.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
kbase36.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
kcp437.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
kcpuids.h Auto-generate some documentation 2020-12-26 02:09:07 -08:00
kcpuids.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
khalfcache3.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
kompressor.h Reduce header complexity 2023-11-28 14:39:42 -08:00
ksha256.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
ksha512.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
ktens.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ktensindex.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
ktolower.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
ktoupper.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
longjmp.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
lz4.h Reduce header complexity 2023-11-28 14:39:42 -08:00
macros.h Make improvements 2020-12-01 03:43:40 -08:00
macros.internal.inc flip et / noet in modelines 2023-12-07 22:17:11 -05:00
mcount.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
msr.internal.h Run clang-format on most sources 2023-04-27 05:44:32 -07:00
mul4x4adx.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
mul6x6adx.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
mul8x8adx.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
nexgen32e.h Reduce header complexity 2023-11-28 14:39:42 -08:00
nt2sysv.h Reduce header complexity 2023-11-28 14:39:42 -08:00
nt2sysv.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
pcmpstr.inc flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pid.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
program_executable_name.c Loader path security (#1012) 2023-12-15 12:23:58 -05:00
program_invocation_name.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
program_invocation_name2.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
rdtsc.h Reduce header complexity 2023-11-28 14:39:42 -08:00
rdtscp.h Reduce header complexity 2023-11-28 14:39:42 -08:00
rldecode.S flip et / noet in modelines 2023-12-07 22:17:11 -05:00
runlevel.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
setjmp.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
sha.h Reduce header complexity 2023-11-28 14:39:42 -08:00
sha1.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
sha1ni.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
sha256.S Get --ftrace working on aarch64 2023-06-05 23:35:31 -07:00
sha256ni.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
sha512.S Get --ftrace working on aarch64 2023-06-05 23:35:31 -07:00
stackframe.h Reduce header complexity 2023-11-28 14:39:42 -08:00
threaded.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
tinydivsi.greg.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
tinywcslen.greg.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
tinywcsnlen.greg.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
trampoline.h Reduce header complexity 2023-11-28 14:39:42 -08:00
uart.internal.h Add epoll and do more release readiness changes 2020-11-28 12:01:51 -08:00
vendor.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
vidya.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
x86compiler.h Iterate more on recent changes 2023-11-11 00:28:22 -08:00
x86feature.h Iterate more on recent changes 2023-11-11 00:28:22 -08:00
x86info.h Add SSL to redbean 2021-06-24 13:20:50 -07:00
x87conf.inc flip et / noet in modelines 2023-12-07 22:17:11 -05:00
xmm.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
zip.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00