Cannot use KERN_PROC_PATHNAME with set-id loader

This commit is contained in:
Jōshin 2023-12-17 15:40:56 +00:00
parent 091e0ab1ca
commit c721e70bb1
No known key found for this signature in database

View file

@ -118,13 +118,18 @@ static inline void InitProgramExecutableNameImpl(void) {
return; return;
} }
if (issetugid() && __program_executable_name && if (issetugid() && __program_executable_name) {
(IsNetbsd() || IsOpenbsd() || IsXnu()) && if ((IsNetbsd() || IsOpenbsd() || IsXnu()) /* any others? */ &&
!strncmp(DEV_FD, __program_executable_name, sizeof(DEV_FD) - 1) && !strncmp(DEV_FD, __program_executable_name, sizeof(DEV_FD) - 1) &&
isdigit(__program_executable_name[sizeof(DEV_FD)]) && isdigit(__program_executable_name[sizeof(DEV_FD)]) &&
!strchr(__program_executable_name + sizeof(DEV_FD) + 1, '/')) { !strchr(__program_executable_name + sizeof(DEV_FD) + 1, '/')) {
/* loader passed us a secure path */ /* loader passed us a secure path */
return; return;
} else {
/* we cannot use KERN_PROC_PATHNAME or its ilk in the loader case. they
will report the path of the loader, not the path of the binary. */
goto UseEmpty;
}
} }
b = g_prog.u.buf; b = g_prog.u.buf;