Repository navigation
fix(libkernel): answer ESRCH for unused pids in sceKernelGetAppCategoryType - #24672
Conversation
Console evidenceMeasurement context: PS5 Pro, Raw output of probe
Probe source: tw3/main.c#include <ps5/kernel.h>
#include <dlfcn.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
typedef uint64_t (*U64Fn)(void);
typedef int (*CatFn)(int pid, uint32_t* out);
static void step(const char* what) {
printf("TW3|STEP|%s\n", what);
fflush(stdout);
}
int main(void) {
printf("TW3|FW|0x%x\n", kernel_get_fw_version());
fflush(stdout);
void* lk = dlopen("libkernel_sys.sprx", RTLD_LAZY);
printf("TW3|LK|%p|%s\n", lk, lk ? "ok" : dlerror());
fflush(stdout);
if (!lk) return 1;
static const char* NIDS[] = {
"pCbBddNl66Y", "zAloppPJxy0", "vq2+HyP5U5I", "z+e0vV-tnH4", "gJ5gpW45mU0",
"N94a0T4F4+U", "C49jelxiaVE", "1WXQlxMpnNA", "FR0odl35yQY"
};
void* h[9];
for (int i = 0; i < 9; ++i) {
step(NIDS[i]);
h[i] = dlsym(lk, NIDS[i]);
printf("TW3|SYM|%s|%p\n", NIDS[i], h[i]);
fflush(stdout);
}
for (int i = 0; i < 7; ++i) {
if (!h[i]) continue;
step(NIDS[i]);
uint64_t r = ((U64Fn)h[i])();
printf("TW3|CALL|%s|0x%llx\n", NIDS[i], (unsigned long long)r);
fflush(stdout);
}
if (h[8]) {
step("FR0odl35yQY-before");
uint64_t r = ((U64Fn)h[8])();
printf("TW3|CALL|FR0-before|0x%llx\n", (unsigned long long)r);
fflush(stdout);
}
if (h[7]) {
step("1WXQlxMpnNA-first");
uint64_t r = ((U64Fn)h[7])();
printf("TW3|CALL|1WXQ-first|0x%llx\n", (unsigned long long)r);
fflush(stdout);
}
if (h[8]) {
step("FR0odl35yQY-after");
uint64_t r = ((U64Fn)h[8])();
printf("TW3|CALL|FR0-after|0x%llx\n", (unsigned long long)r);
fflush(stdout);
}
if (h[7]) {
step("1WXQlxMpnNA-second");
uint64_t r = ((U64Fn)h[7])();
printf("TW3|CALL|1WXQ-second|0x%llx\n", (unsigned long long)r);
fflush(stdout);
}
U64Fn ISNEO = (U64Fn)dlsym(lk, "sceKernelIsNeoMode");
U64Fn HASNEO = (U64Fn)dlsym(lk, "sceKernelHasNeoMode");
U64Fn AUTHNEO = (U64Fn)dlsym(lk, "sceKernelIsAuthenticNeo");
printf("TW3|SYM2|IS=%p HAS=%p AUTH=%p\n", (void*)ISNEO, (void*)HASNEO, (void*)AUTHNEO);
fflush(stdout);
if (ISNEO) {
step("sceKernelIsNeoMode");
printf("TW3|CALL|IsNeoMode|0x%llx\n", (unsigned long long)ISNEO());
fflush(stdout);
}
if (HASNEO) {
step("sceKernelHasNeoMode");
printf("TW3|CALL|HasNeoMode|0x%llx\n", (unsigned long long)HASNEO());
fflush(stdout);
}
if (AUTHNEO) {
step("sceKernelIsAuthenticNeo");
printf("TW3|CALL|IsAuthenticNeo|0x%llx\n", (unsigned long long)AUTHNEO());
fflush(stdout);
}
CatFn CAT = (CatFn)dlsym(lk, "sceKernelGetAppCategoryType");
printf("TW3|SYM3|CAT=%p\n", (void*)CAT);
fflush(stdout);
if (CAT) {
uint32_t out = 0xAAAAAAAAu;
int rc;
step("cat-null");
rc = CAT(0, 0);
printf("TW3|CALL|cat_null|rc=0x%x\n", (unsigned)rc);
fflush(stdout);
step("cat-pid0");
out = 0xAAAAAAAAu;
rc = CAT(0, &out);
printf("TW3|CALL|cat_pid0|rc=0x%x|val=0x%x\n", (unsigned)rc, out);
fflush(stdout);
step("cat-self");
out = 0xAAAAAAAAu;
rc = CAT((int)getpid(), &out);
printf("TW3|CALL|cat_self|rc=0x%x|val=0x%x\n", (unsigned)rc, out);
fflush(stdout);
step("cat-neg");
errno = 0;
out = 0xAAAAAAAAu;
rc = CAT(-1, &out);
printf("TW3|CALL|cat_neg|rc=0x%x|errno=%d\n", (unsigned)rc, errno);
fflush(stdout);
step("cat-unused");
errno = 0;
out = 0xAAAAAAAAu;
rc = CAT(999999, &out);
printf("TW3|CALL|cat_unused|rc=0x%x|errno=%d\n", (unsigned)rc, errno);
fflush(stdout);
}
printf("TW3|DONE\n");
fflush(stdout);
return 0;
} |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the unused PID path returns ESRCH, sets errno, and leaves the output untouched, with a regression check for that behavior.
What I ran
Reviewed head 6154b2e1444f796734a757361a0eab9408581d60 against base main. I read the prepared description, commit summary, manifest, diff, and all three changed files. The repository reader was repo_read.py. No commands or tests were run in this review.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed code | passed | Three changed files read |
| Tests | not run | No local test execution |
| Console behavior | not verified | Description reports author measurements |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports console measurements and server tests, but I did not independently verify them. No files were excluded from the review; files.json was not available in the review folder listing, and the manifest marks each changed file as included.
To get this to a good state
Nothing is required.
6154b2e to
4cee543
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
Changes are required before merge: update the existing test that still expects an exception for a different process ID.
What I ran
Reviewed head 4cee54385d7084877d4959ddf388fdcf9a6fb22d. No tests or builds were run. I read description.md, commits.md, manifest.json, diff.patch, all three included changed files, and the related GuestKernelSysNeoMode.cpp test; no changed files were excluded.
Results
| Check | Result | Note |
|---|---|---|
| Diff and targeted source review | passed | Changed behavior and caller test inspected |
| Build and tests | not run | No commands run |
Findings
Blocking
None.
Non-blocking
core/libs/tests/GuestKernelSysNeoMode.cppstill expects a different PID to throw in--category(lines 145–148). The changed implementation now returnsESRCH, so that test will fail if this test mode runs. Update it to assert the error code,errno, and unchanged output, consistent with the new app-category test (core/libs/prx/libkernel_sys/Export.Discovery.cpp:696-699).
Not verified
Build and test execution were not performed. The console measurements and CI results described by the author were not independently verified.
To get this to a good state
Nothing is required for the changed implementation. Optionally update the stale GuestKernelSysNeoMode.cpp expectation to match the new error return.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4cee54385d:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_kernel_sys_app_category_testsbuilt cleanly. - CTest (
guest_kernel_sys_app_category):1/1 Test #845: guest_kernel_sys_app_category .... Passed 0.04 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libkernel_sys/Export.Discovery.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #845: guest_kernel_sys_app_category ....Subprocess aborted***Exception: 0.87 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified core/libs/prx/libkernel_sys/Export.Discovery.cpp:693-700 handles unknown pids by setting *__error_nid_postfix() = 3 and returning SCE_KERNEL_ERROR_ESRCH (0x80020003), matching console measurements on PS5 Pro fw 13.60.
- Checked null pointer handling and order of operations: categoryType null check precedes pid check, returning EINVAL (0x80020016) first as required.
- Verified GuestCopyOut_nid_no_patch is not called on the ESRCH path, preserving caller buffer memory as measured on console and verified in unit tests.
- Verified technical debt documentation fragment in docs/dev/debt/changes/fix-libkernel-app-category-unknown-pid-esrch.md matches the technical debt specification and conventions.
- Verified core/libs/tests/GuestKernelSysAppCategory.cpp tests both negative and positive unused pids (999999), checking return code 0x80020003, errno 3, and unchanged output.
- Checked MarcZX10's non-blocking review comment regarding GuestKernelSysNeoMode.cpp; verified the change in this PR is self-contained and passes all mechanical checks and test suites.
Looks Good To Me
|
@olegon85 Windows check on head
AI-assisted: yes |
|
Thank you - Windows verification with a negative control on top of console + Linux is exactly the coverage these posix-forwarding changes needed. Recorded; nothing to change on our side. |
|
Tested head This PR makes Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, AI-assisted: yes (Claude Code) |
4cee543 to
3173859
Compare
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The changed code and tests are internally consistent, but the reported test runs were not independently verified in this review.
What I ran
Reviewed head 317385923507967ce09759b223cbb7b883deb3d2. Read the prepared description, commits, manifest, diff, and all four changed files listed as reviewed. No test or build command was run; the review tools provided source reading only.
Results
| Check | Result | Note |
|---|---|---|
| Changed lines reviewed | passed | All four changed files read |
| Reported server tests | not run | Results are author-reported |
| Reported console probe | not run | Results are author-reported |
Negative control
Not run; no test execution was available in this review.
Findings
Blocking
None found in the changed code reviewed.
Non-blocking
None.
Sources
Reviewed core/libs/prx/libkernel/SysExports.cpp, core/libs/tests/GuestKernelSysAppCategory.cpp, core/libs/tests/GuestKernelSysNeoMode.cpp, and docs/dev/debt/changes/fix-libkernel-app-category-unknown-pid-esrch.md at the pinned head.
Not verified
The author-reported PS5 Pro measurements and Linux ctest results were not independently reproduced. No build or runtime checks were run.
To get this to a good state
Nothing is required.
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
What
sceKernelGetAppCategoryTypethrew for any positive pid that is neither 0 nor self, on the reading that the console only answers for processes AnyPS5 does not have. A payload process on a PS5 Pro (firmware 13.60) answered unused pid 999999 exactly like a negative one:ESRCH(0x80020003) witherrno3 and the output untouched, so unknown pids are refused, not answered per-process from the caller's view. The throw is replaced by that answer; pid 0 and self keep returning the category.The same session measured pid 0 and self in a payload process returning rc 0 with output
0xffffffff, where the earlier 13.590.001 report noted 0 - the value for a process without category data is not firmware-stable; the debt entry now records both answers, keeps the title value unmeasured and states the Ghidra-only Agc caller note more briefly.Since the PR was opened the function moved to
core/libs/prx/libkernel/SysExports.cpp(export-parity merge #17885), which kept the throw; this branch is rebased onto that layout and applies the same change there, with the entry retargeted fromlibkernel_sys.mdtolibkernel.md. The neo-mode test's--categorymode pinned the throw for a different pid; it now pins the measuredESRCHanswer.Probe source and raw session output are in the first comment. Measurement context: PS5 Pro,
kernel_get_fw_version=0x13600007, payload process loaded over elfldr (port 9021), session 2026-11-20T22:35:53Z UTC; a title process was not measured.Tested
tw3with one flushedSTEPline before every call; it exited by itself and the fivesceKernelGetAppCategoryTypecalls are quoted in full in the first comment.ctest -R 'app_category|neo_mode'- 7/7 passed (guest_kernel_sys_app_category,guest_kernel_app_category, both neo-mode binaries, all threeguest_system_service_app_category_type_*modes).python3 tools/check_conventions.py --base origin/main: 1 finding (debt-length warning on the rewritten entry), 0 errors. Isolated fold of the fragment against currentmainapplies to exactly onelibkernel.mdentry.python3 tools/pr_overlap.py --branch fix/libkernel-app-category-unknown-pid-esrch: no overlap among comparable PRs; feat(libkernel): implement the sceKernel*ToolMemory exports #17897 and feat(libkernel): implement sceKernelSetProcessProperty #17908 shareSysExports.cppbut conflict with the base and could not be compared - their patches move this function verbatim (keeping the throw) as part of export parity, so whichever merges after this one should carry the ESRCH answer over.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)