Repository navigation
fix(libSceAudioOut): check the param pointer first in sceAudioOut2SetSystemDebugState - #17633
Conversation
…t2SetSystemDebugState On a PS5 (firmware 11.60, payload process) the call checks the param pointer inside the struct first and returns 0x8026800c for debug states 1 and 2 with a null pointer, and returns 0x80268000 for state 2 with an 8-byte param. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…SystemDebugState A null param pointer inside the struct returns 0x8026800c for debug states 1 and 2 before the id and size are checked, and state 2 with an 8-byte param returns 0x80268000, as on a PS5. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ate codes Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe source (built with ps5-payload-sdk v0.45; sceAudioOut2SetSystemDebugState probe.c/* Probe E: sceAudioOut2SetSystemDebugState, payload process, firmware 11.60 (debt libSceAudioOut.md:105: the answers
for other ids and sizes, for a null parameter and for a null inner pointer are not measured on a console).
sceAudioOut2Initialize runs first and the probe stops if it fails. The parameter is a 24-byte record (id, reserved,
inner pointer, size). Only combinations that the debt entry says are rejected are called, plus a null inner
pointer last, so no debug state is ever set; the accepted combination (id 1, size 8, valid pointer) is NOT
called because it would change a system debug state. The inner buffer holds zero bytes. No user ID of a person is
used. Nothing is written, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h> /* only for kernel_get_fw_version() */
#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
}
/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
as a second safeguard. */
static void* probe_watchdog(void* arg) {
static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
unsigned left = PROBE_MAX_S;
(void)arg;
while (left) left = sleep(left);
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
return 0;
}
static void probe_watchdog_start(void) {
pthread_t t;
if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}
static int cases = 0;
static void probe_header(void) {
char utc[32];
time_t now = time(0);
probe_watchdog_start();
struct tm tmv;
gmtime_r(&now, &tmv);
strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
getpid(), utc);
fflush(stdout);
}
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
fflush(stdout);
cases++;
}
static void probe_end(void) {
printf("END\t%d\n", cases);
fflush(stdout);
}
typedef int (*fn_v)(void);
struct dbg_param {
unsigned id;
int reserved;
void* param;
unsigned long size;
};
typedef int (*fn_dbg)(const struct dbg_param*);
static void step(const char* id, const char* call, long r, int e) {
char extra[32];
snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
probe_case(id, call, r, e, extra);
}
static void dbg_case(fn_dbg f, const char* id, const char* call, unsigned state_id, void* inner, unsigned long size) {
struct dbg_param p;
p.id = state_id;
p.reserved = 0;
p.param = inner;
p.size = size;
errno = 0;
long r = f(&p);
step(id, call, r, errno);
}
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
char extra[32];
probe_header();
errno = 0;
void* lib = dlopen("libSceAudioOut.sprx", RTLD_LAZY);
probe_case("0", "load libSceAudioOut.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
if (!lib) { probe_end(); return 0; }
fn_v ao2Init = (fn_v)dlsym(lib, "sceAudioOut2Initialize");
fn_dbg dbg = (fn_dbg)dlsym(lib, "sceAudioOut2SetSystemDebugState");
if (!ao2Init || !dbg) {
probe_case("0b", "dlsym of the audio out 2 functions", -1, 0, "missing");
probe_end();
return 0;
}
errno = 0;
long r = ao2Init();
snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
probe_case("1", "sceAudioOut2Initialize()", r, errno, extra);
if (r != 0) { probe_end(); return 0; } /* no further call without a successful init */
static unsigned char inner[64];
memset(inner, 0, sizeof inner);
errno = 0; r = dbg(0); step("2", "sceAudioOut2SetSystemDebugState(NULL)", r, errno);
dbg_case(dbg, "3", "SetSystemDebugState({id 2, size 8, inner buffer})", 2, inner, 8);
dbg_case(dbg, "4", "SetSystemDebugState({id 1, size 4, inner buffer})", 1, inner, 4);
dbg_case(dbg, "5", "SetSystemDebugState({id 1, size 16, inner buffer})", 1, inner, 16);
dbg_case(dbg, "6", "SetSystemDebugState({id 0, size 8, inner buffer})", 0, inner, 8);
dbg_case(dbg, "7", "SetSystemDebugState({id 0xffffffff, size 8, inner buffer})", 0xffffffffu, inner, 8);
dbg_case(dbg, "8", "SetSystemDebugState({id 2, size 8, inner NULL})", 2, 0, 8);
dbg_case(dbg, "9", "SetSystemDebugState({id 1, size 4, inner NULL})", 1, 0, 4);
dbg_case(dbg, "10", "SetSystemDebugState({id 1, size 8, inner NULL})", 1, 0, 8);
probe_end();
return 0;
}raw outputAI-assisted (Claude Code). 🤖 Generated with Claude Code |
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
gabichuuuuu
left a comment
There was a problem hiding this comment.
Read a3b2d8def3 against main.
Correctness. In AudioOut2System.cpp:sceAudioOut2SetSystemDebugState the order is now: not initialized, then null param, then id 0x20 with size 4 (throws), then a null inner pointer for ids 1 and 2 at any size, then id 2 with size 8 (returns 0x80268000), then 0x80268001 for everything except state 1 with size 8. Each measured row in the table comes out as described. State 1 with size 8 and a valid pointer still returns 0. The NotImplemented that followed the size check on main was reachable only with a null inner pointer, so removing it loses no unimplemented path.
Test. On main, set(2, loudness, 8) returns 0x80268001 and set(1, nullptr, 8) throws, so the changed rows in TestSetSystemDebugState fail there. The new rows set(1, nullptr, 4) and set(2, nullptr, 8) pin the pointer-before-id/size order.
Non-blocking. The null-inner-pointer check is limited to ids 1 and 2. If the console checks the pointer before the id, a null inner pointer with id 0 or 0xffffffff would also return 0x8026800C, but those combinations were measured only with a valid pointer. The debt entry is accurate as written ("the same check covers states 1 and 2"); it could add that other ids with a null inner pointer are unmeasured.
Not run here; this is from reading the code.
AI-assisted: yes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the read. You are right that a null inner pointer with id 0 or AI-assisted (Claude Code). |
|
Windows check of head Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release,
AI-assisted: yes. |
What
sceAudioOut2SetSystemDebugStatechecked the id and size of the debug state before the pointer inside the struct, threw for state 1 with a null inner pointer, and returned 0x80268001 for state 2. On a PS5 a null inner pointer returned 0x8026800c for state 2 with size 8 and for state 1 with sizes 4 and 8, so the pointer is checked before the id and the size, and state 2 with an 8-byte param returned 0x80268000. The call now does the same; it applies the same pointer check to states 1 and 2 with any size, which was not measured for the other sizes. Everything else is unchanged: other ids and sizes still return 0x80268001, and state 1 with an 8-byte param and a valid pointer still returns 0. That case and id 0x20 were not measured, because the valid call would change a system debug state; the debt entry says so.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-09 at 03:24 UTC; the console's own clock read about 1 h 41 min more (see the first comment). A title process may differ.sceAudioOut2SetSystemDebugStatewith a param structmainbeforeThe test
audio_out2_latencynow expects these codes. On Ubuntu 24.04 under WSL2 with GCC 13.3.0 and an AddressSanitizer build, onmain8e34d2642dthe test commit alone aborts ("debug state id 2 with an 8-byte param returns 0x80268000"), and with the fix commit on the samemainit passes; all 65audio_out*tests pass with this change.tools/check_conventions.py --base upstream/mainpasses.Overlap: the 15 other open pull requests that change
AudioOut2System.cpp,AudioOut2Latency.cppordocs/dev/debt/libSceAudioOut.mdwere checked on 2026-11-09 between 04:55 UTC and 05:01 UTC againstmain3d61c0b24f(the base of this change is the older8e34d2642d; it still merges without a conflict). Four already conflict withmainwithout this change (#12863, #5021, #12315 and #14212). #17468 (the AudioOut2 mastering entries, lines 103 and 104 of the debt file) conflicts indocs/dev/debt/libSceAudioOut.mdonly with this change, because this change edits the entry on line 105 right below it; it does not edit the same entry, and whichever merges second needs a small rebase. The other ten merge cleanly with and without this change, among them #17546, #16737, #16736, #16641, #16614 and #16597.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code