Repository navigation
fix(libSceNpCommon): sceNpCmpNpIdInOrder refuses uncanonicalized NpIds with 0x80550605 - #24693
Conversation
…s with 0x80550605
Console evidenceMeasurement context: PS5 Pro, First session note: Raw output of Raw output of Probe sources: tw4b/main.c#include <ps5/kernel.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
typedef struct { char data[20]; uint8_t opt[8]; uint8_t reserved[8]; } NpId;
typedef int (*GetPlatFn)(const NpId*);
typedef int (*SetPlatFn)(NpId*, uint32_t);
typedef int (*CanonFn)(NpId*, int32_t);
typedef int (*OrderFn)(const NpId*, const NpId*, int32_t*);
typedef int (*JidToNpIdFn)(NpId*, const void*);
typedef int (*SwVerFn)(void*);
static void step(const char* what) {
printf("T4B|STEP|%s\n", what);
fflush(stdout);
}
static void dump(const char* id, const void* p, unsigned n) {
const uint8_t* b = (const uint8_t*)p;
printf("T4B|%s|", id);
for (unsigned i = 0; i < n; ++i) printf("%02x", b[i]);
printf("\n");
fflush(stdout);
}
static void put(NpId* np, const char* online, const char* tag4, uint8_t flag) {
memset(np, 0, sizeof(*np));
strcpy(np->data, online);
if (tag4) memcpy(np->opt + 4, tag4, 4);
np->reserved[0] = flag;
}
int main(void) {
printf("T4B|FW|0x%x\n", kernel_get_fw_version());
fflush(stdout);
void* h = dlopen("libSceNpCommon.sprx", RTLD_LAZY);
GetPlatFn GETPLAT = (GetPlatFn)dlsym(h, "sceNpGetPlatformType");
GetPlatFn IGETPLAT = (GetPlatFn)dlsym(h, "sceNpIntGetPlatformType");
SetPlatFn SETPLAT = (SetPlatFn)dlsym(h, "sceNpSetPlatformType");
CanonFn CANPS4 = (CanonFn)dlsym(h, "sceNpUtilCanonicalizeNpIdForPs4");
OrderFn ORDER = (OrderFn)dlsym(h, "sceNpCmpNpIdInOrder");
JidToNpIdFn TOID = (JidToNpIdFn)dlsym(h, "sceNpUtilJidToNpId");
printf("T4B|SYM|%p %p %p %p %p %p\n", (void*)GETPLAT, (void*)IGETPLAT, (void*)SETPLAT,
(void*)CANPS4, (void*)ORDER, (void*)TOID);
fflush(stdout);
NpId np;
if (GETPLAT && IGETPLAT) {
struct { const char* n; const char* tag; } cases[] = {
{"empty", 0}, {"ps3", "ps3"}, {"psp2", "psp2"}, {"ps4", "ps4"},
{"comp", "comp"}, {"junk", "zzzz"}
};
for (unsigned i = 0; i < 6; ++i) {
step(cases[i].n);
put(&np, "TESTID01", cases[i].tag, 1);
printf("T4B|%s|gp=0x%x|igp=0x%x\n", cases[i].n,
(unsigned)GETPLAT(&np), (unsigned)IGETPLAT(&np));
fflush(stdout);
}
}
if (CANPS4) {
struct { const char* n; const char* tag; uint8_t flag; int32_t repl; } cases[] = {
{"c-flag0", 0, 0, 1}, {"c-flag1-repl1-empty", 0, 1, 1}, {"c-flag1-repl0-empty", 0, 1, 0},
{"c-flag1-repl1-ps3", "ps3", 1, 1}, {"c-flag1-repl0-ps3", "ps3", 1, 0},
{"c-flag1-repl1-comp", "comp", 1, 1}
};
for (unsigned i = 0; i < 6; ++i) {
step(cases[i].n);
put(&np, "TESTID01", cases[i].tag, cases[i].flag);
int rc = CANPS4(&np, cases[i].repl);
printf("T4B|%s|rc=0x%x\n", cases[i].n, (unsigned)rc);
dump(cases[i].n, &np.opt[0], 16);
fflush(stdout);
}
}
if (SETPLAT && CANPS4) {
step("c-set-comp-repl1");
put(&np, "TESTID01", 0, 1);
int rc = SETPLAT(&np, 3);
printf("T4B|c-set-pre|rc=0x%x\n", (unsigned)rc);
rc = CANPS4(&np, 1);
printf("T4B|c-set-comp-repl1|rc=0x%x\n", (unsigned)rc);
dump("css", np.opt, 8);
fflush(stdout);
}
if (ORDER) {
NpId a, b;
int32_t o;
struct { const char* n; const char* da; const char* db; const char* ta; const char* tb; uint8_t fa; uint8_t fb; } cases[] = {
{"o-eq", "AAAA", "AAAA", 0, 0, 1, 1},
{"o-lt", "AAAA", "AAAB", 0, 0, 1, 1},
{"o-taglt", "AAAA", "AAAA", "ps3", "ps4", 1, 1},
{"o-flag0a", "AAAA", "AAAA", 0, 0, 0, 1},
{"o-flag0b", "AAAA", "AAAA", 0, 0, 1, 0},
{"o-flag0both", "AAAA", "AAAA", 0, 0, 0, 0}
};
for (unsigned i = 0; i < 6; ++i) {
step(cases[i].n);
put(&a, cases[i].da, cases[i].ta, cases[i].fa);
put(&b, cases[i].db, cases[i].tb, cases[i].fb);
o = 0x5A5A5A5A;
int rc = ORDER(&a, &b, &o);
printf("T4B|%s|rc=0x%x|o=%d\n", cases[i].n, (unsigned)rc, o);
fflush(stdout);
}
}
if (TOID) {
struct { const char* user; const char* domain; const char* resource; } j = {
"AAAAAAAAAAAAAAAA", "aa.bb.cc.playstation.net", "res1"
};
uint64_t jid[4];
NpId out;
step("t-16char");
jid[0] = (uint64_t)(uintptr_t)j.user;
jid[1] = (uint64_t)(uintptr_t)j.domain;
jid[2] = (uint64_t)(uintptr_t)j.resource;
jid[3] = 0;
memset(&out, 0xEE, sizeof(out));
int rc = TOID(&out, jid);
printf("T4B|t-16char|rc=0x%x\n", (unsigned)rc);
dump("t16", &out, 36);
fflush(stdout);
}
void* lk = dlopen("libkernel_sys.sprx", RTLD_LAZY);
SwVerFn SWV = (SwVerFn)dlsym(lk, "sceKernelGetSystemSwVersion");
printf("T4B|SWV|%p\n", (void*)SWV);
fflush(stdout);
if (SWV) {
uint8_t buf[64];
step("swversion");
memset(buf, 0xEE, sizeof(buf));
*(uint64_t*)buf = 40;
int rc = SWV(buf);
printf("T4B|swversion|rc=0x%x\n", (unsigned)rc);
dump("swv", buf, 48);
fflush(stdout);
}
printf("T4B|DONE\n");
fflush(stdout);
return 0;
}tw4/main.c#include <ps5/kernel.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
typedef struct { char data[17]; uint8_t opt[8]; uint8_t reserved[8]; } NpId;
typedef struct { const char* user; const char* domain; const char* resource; uint64_t reserved; } Jid;
typedef void (*VerFn)(char*);
typedef int (*GetPlatFn)(const NpId*);
typedef int (*SetPlatFn)(NpId*, uint32_t);
typedef int (*CanonFn)(NpId*, int32_t);
typedef int (*CmpIdFn)(const char*, const char*);
typedef int (*OrderFn)(const NpId*, const NpId*, int32_t*);
typedef int (*ValidFn)(const char*);
typedef int (*ParseJidFn)(Jid*, const char*, char*, uint64_t, uint64_t*);
typedef int (*JidToNpIdFn)(NpId*, const Jid*);
static void step(const char* what) {
printf("TW4|STEP|%s\n", what);
fflush(stdout);
}
static void dump(const char* id, const void* p, unsigned n) {
const uint8_t* b = (const uint8_t*)p;
printf("TW4|%s|", id);
for (unsigned i = 0; i < n; ++i) printf("%02x", b[i]);
printf("\n");
fflush(stdout);
}
static void fill(NpId* np, const char* online, uint32_t tag, uint8_t res0) {
memset(np, 0, sizeof(*np));
strcpy(np->data, online);
memcpy(np->opt + 4, &tag, 4);
np->reserved[0] = res0;
}
int main(void) {
printf("TW4|FW|0x%x\n", kernel_get_fw_version());
fflush(stdout);
void* h = dlopen("libSceNpCommon.sprx", RTLD_LAZY);
printf("TW4|LIB|%p|%s\n", h, h ? "ok" : dlerror());
fflush(stdout);
if (!h) return 1;
VerFn GETSDK = (VerFn)dlsym(h, "sceNpGetSdkVersion");
VerFn GETNAV = (VerFn)dlsym(h, "sceNpGetNavSdkVersion");
GetPlatFn GETPLAT = (GetPlatFn)dlsym(h, "sceNpGetPlatformType");
GetPlatFn IGETPLAT = (GetPlatFn)dlsym(h, "sceNpIntGetPlatformType");
SetPlatFn SETPLAT = (SetPlatFn)dlsym(h, "sceNpSetPlatformType");
SetPlatFn ISETPLAT = (SetPlatFn)dlsym(h, "sceNpIntSetPlatformType");
CanonFn CANPS4 = (CanonFn)dlsym(h, "sceNpUtilCanonicalizeNpIdForPs4");
CanonFn CANPSP2 = (CanonFn)dlsym(h, "sceNpUtilCanonicalizeNpIdForPsp2");
CmpIdFn CMPID = (CmpIdFn)dlsym(h, "sceNpCmpOnlineId");
OrderFn ORDER = (OrderFn)dlsym(h, "sceNpCmpNpIdInOrder");
ValidFn VALID = (ValidFn)dlsym(h, "sceNpIntIsValidOnlineId");
ParseJidFn PARSE = (ParseJidFn)dlsym(h, "sceNpUtilParseJid");
JidToNpIdFn TOID = (JidToNpIdFn)dlsym(h, "sceNpUtilJidToNpId");
printf("TW4|SYM|%p %p %p %p %p %p %p %p %p %p %p %p %p\n",
(void*)GETSDK, (void*)GETNAV, (void*)GETPLAT, (void*)IGETPLAT,
(void*)SETPLAT, (void*)ISETPLAT, (void*)CANPS4, (void*)CANPSP2,
(void*)CMPID, (void*)ORDER, (void*)VALID, (void*)PARSE, (void*)TOID);
fflush(stdout);
if (GETSDK) {
char buf[8];
memset(buf, 0xAA, sizeof(buf));
step("GetSdkVersion");
GETSDK(buf);
dump("sdkver", buf, 8);
}
if (GETNAV) {
char buf[8];
memset(buf, 0xAA, sizeof(buf));
step("GetNavSdkVersion");
GETNAV(buf);
dump("navver", buf, 8);
}
static const uint32_t TAG_PS3 = 0x00337370u, TAG_PSP2 = 0x32707370u, TAG_PS4 = 0x00347370u, TAG_COMP = 0x706d6f63u;
NpId np;
if (GETPLAT) {
struct { const char* name; uint32_t tag; } cases[] = {
{"empty", 0}, {"ps3", TAG_PS3}, {"psp2", TAG_PSP2}, {"ps4", TAG_PS4}, {"comp", TAG_COMP}
};
for (unsigned i = 0; i < 5; ++i) {
char id[32];
snprintf(id, sizeof(id), "gp-%s", cases[i].name);
step(id);
fill(&np, "TESTID01", cases[i].tag, 1);
printf("TW4|%s|rc=0x%x\n", id, (unsigned)GETPLAT(&np));
fflush(stdout);
}
step("gp-null");
printf("TW4|gp-null|rc=0x%x\n", (unsigned)GETPLAT(0));
fflush(stdout);
}
if (IGETPLAT) {
fill(&np, "TESTID01", TAG_COMP, 1);
step("igp-comp");
printf("TW4|igp-comp|rc=0x%x\n", (unsigned)IGETPLAT(&np));
fflush(stdout);
fill(&np, "TESTID01", 0, 1);
step("igp-empty");
printf("TW4|igp-empty|rc=0x%x\n", (unsigned)IGETPLAT(&np));
fflush(stdout);
}
if (SETPLAT && GETPLAT) {
for (uint32_t t = 0; t <= 4; ++t) {
char id[32];
snprintf(id, sizeof(id), "sp-%u", t);
step(id);
fill(&np, "TESTID01", 0, 1);
int rc = SETPLAT(&np, t);
printf("TW4|%s|rc=0x%x|", id, (unsigned)rc);
dump("", &np, 33);
printf("TW4|%s|get=0x%x\n", id, (unsigned)GETPLAT(&np));
fflush(stdout);
}
}
if (ISETPLAT && IGETPLAT) {
step("isp-4");
fill(&np, "TESTID01", 0, 1);
int rc = ISETPLAT(&np, 4);
printf("TW4|isp-4|rc=0x%x|igp=0x%x\n", (unsigned)rc, (unsigned)IGETPLAT(&np));
fflush(stdout);
}
if (CANPS4) {
struct { const char* name; uint8_t res0; int32_t repl; uint32_t tag; } cases[] = {
{"c-res0", 0, 1, 0}, {"c-repl1-empty", 1, 1, 0}, {"c-repl0-empty", 1, 0, 0},
{"c-repl1-ps3", 1, 1, TAG_PS3}, {"c-repl0-ps3", 1, 0, TAG_PS3}
};
for (unsigned i = 0; i < 5; ++i) {
step(cases[i].name);
fill(&np, "TESTID01", cases[i].tag, cases[i].res0);
int rc = CANPS4(&np, cases[i].repl);
printf("TW4|%s|rc=0x%x\n", cases[i].name, (unsigned)rc);
dump(cases[i].name, &np, 33);
fflush(stdout);
}
}
if (CANPSP2) {
step("c2-repl1-empty");
fill(&np, "TESTID01", 0, 1);
int rc = CANPSP2(&np, 1);
printf("TW4|c2-repl1-empty|rc=0x%x\n", (unsigned)rc);
dump("c2", &np, 33);
fflush(stdout);
}
if (CMPID) {
char a[17], b[17];
step("cmp-eq");
strcpy(a, "SAMEID"); strcpy(b, "SAMEID");
printf("TW4|cmp-eq|rc=0x%x\n", (unsigned)CMPID(a, b));
fflush(stdout);
step("cmp-ne");
strcpy(b, "OTHERID");
printf("TW4|cmp-ne|rc=0x%x\n", (unsigned)CMPID(a, b));
fflush(stdout);
step("cmp-null");
printf("TW4|cmp-null|rc=0x%x\n", (unsigned)CMPID(0, b));
fflush(stdout);
}
if (ORDER) {
NpId x, y;
int32_t order = 0x5A5A5A5A;
step("ord-eq");
fill(&x, "AAAA", 0, 0); fill(&y, "AAAA", 0, 0);
printf("TW4|ord-eq|rc=0x%x|o=%d\n", (unsigned)ORDER(&x, &y, &order), order);
fflush(stdout);
step("ord-lt");
fill(&y, "AAAB", 0, 0);
order = 0x5A5A5A5A;
printf("TW4|ord-lt|rc=0x%x|o=%d\n", (unsigned)ORDER(&x, &y, &order), order);
fflush(stdout);
step("ord-opt");
fill(&y, "AAAA", TAG_PS3, 0);
order = 0x5A5A5A5A;
printf("TW4|ord-opt|rc=0x%x|o=%d\n", (unsigned)ORDER(&x, &y, &order), order);
fflush(stdout);
step("ord-nullout");
printf("TW4|ord-nullout|rc=0x%x\n", (unsigned)ORDER(&x, &y, 0));
fflush(stdout);
}
if (VALID) {
char s[17];
step("val-null");
printf("TW4|val-null|rc=0x%x\n", (unsigned)VALID(0));
fflush(stdout);
step("val-ok8");
memset(s, 0, sizeof(s)); strcpy(s, "ABCDEFGH");
printf("TW4|val-ok8|rc=0x%x\n", (unsigned)VALID(s));
fflush(stdout);
step("val-short2");
memset(s, 0, sizeof(s)); strcpy(s, "AB");
printf("TW4|val-short2|rc=0x%x\n", (unsigned)VALID(s));
fflush(stdout);
step("val-nonul16");
memset(s, 'A', 17);
printf("TW4|val-nonul16|rc=0x%x\n", (unsigned)VALID(s));
fflush(stdout);
}
if (PARSE) {
struct { const char* name; const char* text; uint64_t size; } cases[] = {
{"p-ok", "AB.CD@aa.bb.cc.playstation.net/res1", 256},
{"p-small", "AB.CD@aa.bb.cc.playstation.net/res1", 4},
{"p-noat", "abcdef", 256},
{"p-dots", "u@aa.bb.cc.playstation.net../res", 256}
};
for (unsigned i = 0; i < 4; ++i) {
static Jid jid;
char buf[256];
uint64_t req = 0;
memset(&jid, 0, sizeof(jid));
memset(buf, 0xEE, sizeof(buf));
step(cases[i].name);
int rc = PARSE(&jid, cases[i].text, buf, cases[i].size, &req);
printf("TW4|%s|rc=0x%x|req=%llu\n", cases[i].name, (unsigned)rc, (unsigned long long)req);
printf("TW4|%s|u=%lld d=%lld r=%lld\n", cases[i].name,
jid.user ? (long long)((const char*)jid.user - buf) : -1LL,
jid.domain ? (long long)((const char*)jid.domain - buf) : -1LL,
jid.resource ? (long long)((const char*)jid.resource - buf) : -1LL);
fflush(stdout);
if (rc == 0 && jid.user) dump(cases[i].name, buf, 96);
}
}
if (TOID) {
NpId out;
struct { const char* name; const char* u; const char* d; const char* r; } cases[] = {
{"t-ok", "AB.CD", "aa.bb.cc.playstation.net", "res1"},
{"t-baddom", "AB.CD", "aa.bb.cc.example.com", "res1"},
{"t-longuser", "AAAAAAAAAAAAAAAAAAAAAAAAAA", "aa.bb.cc.playstation.net", "res"},
{"t-res5", "AB.CD", "aa.bb.cc.playstation.net", "res12"},
{"t-nullr", "AB.CD", "aa.bb.cc.playstation.net", 0}
};
for (unsigned i = 0; i < 5; ++i) {
Jid j;
step(cases[i].name);
memset(&j, 0, sizeof(j));
j.user = cases[i].u; j.domain = cases[i].d; j.resource = cases[i].r;
memset(&out, 0, sizeof(out));
int rc = TOID(&out, &j);
printf("TW4|%s|rc=0x%x\n", cases[i].name, (unsigned)rc);
dump(cases[i].name, &out, 33);
fflush(stdout);
}
}
printf("TW4|DONE\n");
fflush(stdout);
return 0;
} |
TechnicalDebt.md asks pull requests to change debt entries through a fragment. The folded file comes out the same.
|
@olegon85 I pushed c933253 on top: as on #24560, I moved the debt entry edit into docs/dev/debt/changes/fix-libscenpcommon-cmpnpidinorder-validates-npid-flag.md and restored docs/dev/debt/libSceNpCommon.md. The folded text is the same as your edit and debt_fold.py --check passes. The code change looks right to me. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The changed implementation and tests are consistent with the stated validation behavior, but execution checks were not available in this review session.
What I ran
Read the prepared diff and all three changed files at head c93325348992db834b84656f072658f8e43d9abf using the review reader. No test or build command was run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed files | passed | All three changed files read |
| Tests and build | not run | Not executable through the available review tools |
Findings
Blocking
None.
Non-blocking
None.
Not verified
- The reported console behavior and environment were not independently verified.
- Tests, build, conventions, and diff checks reported in the PR description were not rerun.
To get this to a good state
Nothing is required.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c933253489:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_np_common_testsbuilt cleanly. - CTest (
guest_np_common_ids,guest_np_common_sync,guest_np_common_clock,guest_np_common_wake):1/4 Test #1010: guest_np_common_ids .............. Passed 0.04 sec 2/4 Test #1011: guest_np_common_sync ............. Passed 0.06 sec 3/4 Test #1012: guest_np_common_clock ............ Passed 0.03 sec 4/4 Test #1013: guest_np_common_wake ............. Passed 0.04 sec 100% tests passed, 0 tests failed out of 4 - Negative control: with
core/libs/prx/libSceNpCommon/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/4 Test #1010: guest_np_common_ids ..............***Failed 0.04 sec 2/4 Test #1011: guest_np_common_sync ............. Passed 0.05 sec 3/4 Test #1012: guest_np_common_clock ............ Passed 0.04 sec 4/4 Test #1013: guest_np_common_wake ............. Passed 0.05 sec 75% tests passed, 1 tests failed out of 4 - Code reading:
- Verified sceNpCmpNpIdInOrder in core/libs/prx/libSceNpCommon/Export.cpp validates null pointers and copy-in failures before checking canonicalized marker reserved[0] == 1, matching the measured console precedence.
- Verified sceNpCmpNpIdInOrder returns NP_UTIL_ERROR_INVALID_NP_ID (0x80550605) when localId1.reserved[0] != 1 or localId2.reserved[0] != 1, leaving the guest order output unmodified.
- Verified comparison logic for handle, opt, and reserved buffers when both NpIdFull structs are valid and canonicalized, preserving lexicographical ordering and copying out the int32_t result.
- Verified docs/dev/debt/changes/fix-libscenpcommon-cmpnpidinorder-validates-npid-flag.md adheres to debt fragment conventions and was confirmed by maintainer oneandonlydean.
- Verified core/libs/tests/GuestNpCommon.cpp tests initialize reserved[0] = 1 for normal ordering comparisons and explicitly test invalid/uncanonicalized NpIds with both first and second argument unflagged.
Looks Good To Me
What
sceNpCmpNpIdInOrdercompared any two NpIds. A payload process on a PS5 Pro (firmware 13.60) refused the call with0x80550605(NP_UTIL_ERROR_INVALID_NP_ID) whenever either operand'sreserved[0]was not the canonicalized marker 1 thatsceNpUtilJidToNpIdwrites, leaving the order output untouched, and accepted pairs where both carried it (order -1/0/1 by handle, then opt, then reserved as before). The check is added after the null-pointer and unmapped-copy errors, matching the measured precedence: a nullorderpointer still gives0x80550003even for uncanonicalized ids.The same session confirmed the rest of this utility family against the implementation - platform tags read and written at npid offset 24 with no tag answering 0, unknown and
companswering0x80550004publicly and 4 throughsceNpIntGetPlatformType, boolean online-ID validity, null-pointer answers - so the debt entry now states measured facts. Those siblings needed no code change.Probe sources and raw session output are in the first comment, including the note that an earlier run of the same session used a three-byte-short struct for manual cases; all claims here rest on the corrected re-run. Measurement context:
kernel_get_fw_version=0x13600007, payload process over elfldr (port 9021), sessions 2026-11-20T23:06Z and 23:18Z UTC; a title process was not measured.Tested
tw4/tw4b, one flushedSTEPline before every call, both exited by themselves; the order matrix (equal, handle-less, tag-less, flag missing on either or both sides) is quoted in full in the first comment.guest_np_common_tests- 7/7 passed with the change on01ac7c81be; the fixture now sets the marker on ids meant to compare and pins the two refusal cases with an untouched order value.python3 tools/check_conventions.py --base origin/main: passed.git diff --check: clean.python3 tools/pr_overlap.py --branch fix/libscenpcommon-cmpnpidinorder-validates-npid-flag: no overlap with open pull requests (all 2297 probed; three base-conflicting shares merged and compared clean). Own sibling docs PR ondocs/npcommon-utils-measured-1360edits four other entries of the same debt file, disjoint from this one.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)