mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #1748 from danielradosa/feat/libkernel-seteuid-setegid
feat(libkernel): implement seteuid and setegid
This commit is contained in:
@@ -463,6 +463,16 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(guest_elf_phdr_match PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_credentials_tests ${LIBS_INCLUDE_DIR}/tests/GuestCredentials.cpp)
|
||||
target_include_directories(guest_credentials_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_credentials_tests PRIVATE libkernel libc)
|
||||
configure_windows_unwind(guest_credentials_tests)
|
||||
add_test(NAME guest_credentials COMMAND guest_credentials_tests)
|
||||
set_tests_properties(guest_credentials PROPERTIES TIMEOUT 20)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_credentials PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_address_tests ${LIBS_INCLUDE_DIR}/tests/GuestAddressConversion.cpp)
|
||||
target_include_directories(guest_address_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_address_tests PRIVATE libkernel libc)
|
||||
|
||||
@@ -313,4 +313,16 @@ int APS5_VABI sceKernelGetOperationMode(int* mode, int* submode) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI seteuid_nid_postfix(std::uint32_t euid) {
|
||||
if (euid != 0)
|
||||
throw std::runtime_error("seteuid: unsupported user id " + std::to_string(euid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int APS5_VABI setegid_nid_postfix(std::uint32_t egid) {
|
||||
if (egid != 0)
|
||||
throw std::runtime_error("setegid: unsupported group id " + std::to_string(egid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "prx/libc/include/general/VabiMacros.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
extern "C" {
|
||||
int APS5_VABI seteuid_nid_postfix(std::uint32_t);
|
||||
int APS5_VABI setegid_nid_postfix(std::uint32_t);
|
||||
int* APS5_VABI __error_nid_postfix();
|
||||
}
|
||||
using SetId = int (APS5_VABI *)(std::uint32_t);
|
||||
static void Require(bool value) { if (!value) std::abort(); }
|
||||
static bool Throws(SetId function, std::uint32_t id) {
|
||||
try {
|
||||
function(id);
|
||||
} catch (const std::runtime_error&) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int main() {
|
||||
*__error_nid_postfix() = 13;
|
||||
Require(seteuid_nid_postfix(0) == 0);
|
||||
Require(setegid_nid_postfix(0) == 0);
|
||||
Require(*__error_nid_postfix() == 13);
|
||||
Require(Throws(seteuid_nid_postfix, 1000));
|
||||
Require(Throws(setegid_nid_postfix, 1000));
|
||||
Require(Throws(seteuid_nid_postfix, 0xFFFFFFFFu));
|
||||
Require(Throws(setegid_nid_postfix, 0xFFFFFFFFu));
|
||||
Require(seteuid_nid_postfix(0) == 0);
|
||||
Require(setegid_nid_postfix(0) == 0);
|
||||
}
|
||||
@@ -139,6 +139,7 @@ Throughout the project, every function at every stage either **does exactly what
|
||||
- [_sceLibcInternalForceTlsDestructor](../../core/libs/prx/libSceLibcInternal/Export.cpp) (libSceLibcInternal) - behaviour follows `sceLibcForceTlsDestructor(int)` in a title's `libc.prx` (disassembly): the calling thread's destructors whose dso belongs to the module run newest first, only if the dso's module is loaded and the dso points to itself, in up to 4 passes. The return type is unknown (that function returns nothing), 0 is returned. The module of each dso is looked up when the destructors are forced, not when they are registered as `libc.prx` does, and the lookup is Linux only, so on Windows the call throws when the thread has destructors
|
||||
- [std_execute_once](../../core/libs/prx/libc/Export.cpp) (libc) - assumed to be the plain-named twin of `std::_Execute_once` (`_ZSt13_Execute_onceRSt9once_flagPFiPvS1_PS1_ES1_`, the callee of Dinkumware `call_once`): it delegates there and gets the [thread.once.callonce] semantics already verified for that symbol (one invocation per flag, concurrent callers block until it completes, and a failing or throwing invocation leaves the flag unready so the next caller runs it). The name equivalence is not confirmed on a title, and the callback convention (called with (null, arg, null), non-zero return meaning success) is the twin's, unverified for this symbol
|
||||
- [__progname](../../core/libs/prx/libkernel/System/src/Process.cpp) (libkernel) - unknown data export
|
||||
- [seteuid, setegid](../../core/libs/prx/libkernel/System/src/Process.cpp) (libkernel) - the guest process is assumed to run as root, with real, effective and saved user and group ids 0. As in FreeBSD's `sys_seteuid` and `sys_setegid`, id 0 is then accepted without a privilege check and changes no credential, so 0 is returned; any other id would change the effective id, which is not modelled, and throws. The ids and privileges a title has on a console are unverified
|
||||
- [pthread_barrierattr_setpshared](../../core/libs/prx/libkernel/Pthread/Posix/Barrier.cpp) (libkernel) - PTHREAD_PROCESS_SHARED is accepted on the assumption that the console follows FreeBSD 11.0 libthr, which accepts it (9.0 rejects it with EINVAL); unverified on hardware. Guest code runs in one process, so a shared barrier behaves as a private one
|
||||
- [sceSslClose](../../core/libs/prx/libSceSsl/Export.cpp) (libSceSsl) - unknown signature
|
||||
- [sceSslGetSerialNumber](../../core/libs/prx/libSceSsl/Export.cpp) (libSceSsl) - unknown signature
|
||||
|
||||
Reference in New Issue
Block a user