Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions core/libs/prx/libkernel/System/src/SystemConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,8 @@ int APS5_VABI sysctl_nid_postfix(const int* name, std::uint32_t nameLength, void
*__error_nid_postfix() = 22;
return -1;
}
const int pid = name[3];
if (pid != -1 && !CallingProcessId(pid)) {
*__error_nid_postfix() = 3;
return -1;
}
static constexpr char path[] = "/app0/eboot.bin";
return CopyOut(path, sizeof(path), oldValue, oldLength);
*__error_nid_postfix() = 2;
return -1;
}
if (nameLength >= 3 && name[0] == 1 && name[1] == 14 && name[2] == 8) {
if (newValue != nullptr) {
Expand Down
48 changes: 17 additions & 31 deletions core/libs/tests/GuestSystemConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,40 +276,26 @@ static void CheckPathnameSysctl() {
Require(sysctl_nid_postfix(mibTooLong, 5, buffer, &length, buffer, sizeof(buffer)) == -1 && *__error_nid_postfix() == 1);
Require(sysctlbyname_nid_postfix("kern.proc.pathname", buffer, &length, buffer, sizeof(buffer)) == -1 && *__error_nid_postfix() == 1);

const int mibSelf[] = {1, 14, 12, -1};
length = 0;
Require(sysctl_nid_postfix(mibSelf, 4, nullptr, &length, nullptr, 0) == 0 && length == sizeof("/app0/eboot.bin"));

std::memset(buffer, 0xaa, sizeof(buffer));
length = sizeof(buffer);
Require(sysctl_nid_postfix(mibSelf, 4, buffer, &length, nullptr, 0) == 0);
Require(length == sizeof("/app0/eboot.bin"));
Require(std::strcmp(buffer, "/app0/eboot.bin") == 0);

const int callerPid = getpid_nid_postfix();
const int mibSelf[] = {1, 14, 12, -1};
const int mibPid[] = {1, 14, 12, callerPid};
std::memset(buffer, 0xaa, sizeof(buffer));
length = sizeof(buffer);
Require(sysctl_nid_postfix(mibPid, 4, buffer, &length, nullptr, 0) == 0);
Require(length == sizeof("/app0/eboot.bin"));
Require(std::strcmp(buffer, "/app0/eboot.bin") == 0);

const int mibThread[] = {1, 14, 12, scePthreadGetthreadid()};
std::memset(buffer, 0xaa, sizeof(buffer));
length = sizeof(buffer);
Require(sysctl_nid_postfix(mibThread, 4, buffer, &length, nullptr, 0) == 0 && length == sizeof("/app0/eboot.bin"));
Require(std::strcmp(buffer, "/app0/eboot.bin") == 0);

const int mibForeign[] = {1, 14, 12, callerPid == 1 ? 2 : 1};
Require(sysctl_nid_postfix(mibForeign, 4, buffer, &length, nullptr, 0) == -1 && *__error_nid_postfix() == 3);

length = 5;
std::memset(buffer, 0xaa, sizeof(buffer));
Require(sysctl_nid_postfix(mibSelf, 4, buffer, &length, nullptr, 0) == -1 && *__error_nid_postfix() == 12);
Require(length == 5 && buffer[4] == '0' && buffer[5] == static_cast<char>(0xaa));

length = sizeof(buffer);
Require(sysctl_nid_postfix(mibSelf, 4, buffer, &length, buffer, sizeof(buffer)) == -1 && *__error_nid_postfix() == 1);
const int mibAbsent[] = {1, 14, 12, 0x7fffffff};
for (const int* mib : {mibSelf, mibPid, mibThread, mibForeign, mibAbsent}) {
length = 0;
*__error_nid_postfix() = 13;
Require(sysctl_nid_postfix(mib, 4, nullptr, &length, nullptr, 0) == -1 && *__error_nid_postfix() == 2 && length == 0);
for (const std::size_t capacity : {sizeof(buffer), std::size_t{1}}) {
std::memset(buffer, 0xaa, sizeof(buffer));
length = capacity;
*__error_nid_postfix() = 13;
Require(sysctl_nid_postfix(mib, 4, buffer, &length, nullptr, 0) == -1 && *__error_nid_postfix() == 2);
Require(length == capacity && Untouched(reinterpret_cast<const unsigned char*>(buffer), sizeof(buffer)));
}
length = sizeof(buffer);
Require(sysctl_nid_postfix(mib, 4, buffer, &length, buffer, 0) == -1 && *__error_nid_postfix() == 1);
}
}
static void CheckProcessSysctl() {
const int callerPid = getpid_nid_postfix();
Expand Down Expand Up @@ -1195,7 +1181,7 @@ static void CheckNameToMib() {
mib[3] = -1;
char path[32] = {};
length = sizeof(path);
Require(sysctl_nid_postfix(mib, 4, path, &length, nullptr, 0) == 0 && std::strcmp(path, "/app0/eboot.bin") == 0);
Require(sysctl_nid_postfix(mib, 4, path, &length, nullptr, 0) == -1 && *__error_nid_postfix() == 2 && length == sizeof(path) && path[0] == 0);

int truncated[3] = {0x5a5a5a5a, 0x5a5a5a5a, 0x5a5a5a5a};
size = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libkernel

## change [kern.proc.pathname]

- [kern.proc.pathname](../../../core/libs/prx/libkernel/System/src/SystemConfiguration.cpp) (libkernel) - `sysctl` {`CTL_KERN`, `KERN_PROC`, `KERN_PROC_PATHNAME`, pid} fails with `ENOENT` and leaves the buffer and the length alone, as a payload process on a PS5 (firmware 11.60) [measured](https://github.com/boykopovar/AnyPS5/pull/22788#issuecomment-6974328583) for pid -1, its own pid, pid 1 and 0x7fffffff, with a 1,024-byte buffer, a 1-byte buffer and a size query; a write fails with `EPERM`, as measured there. Whether a title process gets the same is unverified, and a MIB without exactly one pid keeps `EINVAL`, which was not measured.