cosmopolitan/ape
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
..
public Improve open source compatibility 2022-09-08 03:19:35 -07:00
aarch64.lds Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
ape-m1.c Loader path security (#1012) 2023-12-15 12:23:58 -05:00
ape.h Mint APE Loader v1.9 2023-11-05 13:11:34 -08:00
ape.internal.h Get aarch64 hello world working 2023-05-10 04:20:47 -07:00
ape.lds Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
ape.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
apeinstall.sh Redesign cosmocc toolchain 2023-11-11 14:18:08 -08:00
apeuninstall.sh Redesign cosmocc toolchain 2023-11-11 14:18:08 -08:00
blink-linux-aarch64.gz Make blink support conditionally linkable into APE 2023-06-17 07:55:35 -07:00
blink-xnu-aarch64.gz Make blink support conditionally linkable into APE 2023-06-17 07:55:35 -07:00
BUILD.mk Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
idata.internal.h flip et / noet in modelines 2023-12-07 22:17:11 -05:00
launch.S Loader path security (#1012) 2023-12-15 12:23:58 -05:00
loader-macho.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
loader.c Loader path security (#1012) 2023-12-15 12:23:58 -05:00
loader.lds Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
macros.internal.h flip et / noet in modelines 2023-12-07 22:17:11 -05:00
mz.ansi Initial import 2020-06-15 07:18:57 -07:00
notice.inc Initial import 2020-06-15 07:18:57 -07:00
relocations.h Optimize memory layout 2022-09-12 04:26:52 -07:00
sections.internal.h Add <link.h> for absl 2023-12-08 20:04:10 -08:00
start.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
systemcall.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00