Repository navigation
fix(libSceFiber): write the option block magic and reject a misaligned block as the console does - #23393
Conversation
…nitialize and its alignment error Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d block as the console does Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… and alignment Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe sources (built with ps5-payload-sdk v0.45; 1st probe (16:37 UTC): probe.c (build 6791671682e7)/* Probe: sceFiberOptParamInitialize, payload process, firmware 11.60 (debt libSceFiber.md:6: it returns SCE_FIBER_ERROR_INVALID when the destination pointer is unwritable; this is a
defensive host-protection fallback, whether the console raises a signal or faults on unmapped or read-only memory is not measured). Prototype from the repo: int32_t
sceFiberOptParamInitialize(SceFiberOptParam* optParam), the structure being 0x80 bytes in the repo (FIBER_OPT_PARAM_SIZE); the repo's error values are SCE_FIBER_ERROR_NULL 0x80590001,
ALIGNMENT 0x80590002 and INVALID 0x80590004. The module is opened with dlopen("libSceFiber.sprx") and sceFiberOptParamInitialize is looked up with dlsym first (sceFiberInitialize and
sceFiberGetInfo only as existence flags, they are not called). Cases: a 0xAA-filled 128-byte buffer that is 8-byte aligned, followed by a 64-byte canary, in a static array: the return value, how many
bytes changed from 0xAA, the offsets of the first and the last changed byte, whether the canary is intact, a second call giving the same result; the same buffer at the offsets +1, +2 and +4 (the
return value; single calls under a guard); then the pointer cases, last, each one single call and only while the previous one did not fault: NULL, 0x1, 0x1000, a pointer to a read-only page, a pointer
to a page without access, and a pointer 120 bytes before the end of a writable page that is followed by a page without access (two 16 KiB aligned static arrays, set with mprotect and back at once, no mmap):
the return value in hex, the fault signal and, for the last case, how many of the first 120 bytes were written. A fault is caught by a guard (one hit per case, more than eight end the probe
with _exit(125)); a fault is a result. Nothing is written to a file, 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 volatile int g_handle = -1;
static int (*volatile g_setmargins)(int, int, int) = 0; /* unused here */
static void reset_rate(void) {
if (g_setmargins && g_handle >= 0) g_setmargins(g_handle, 0, 0);
}
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
reset_rate();
_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);
reset_rate();
_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);
}
#include <setjmp.h>
#include <sys/mman.h>
typedef int (*fn_opt)(void*);
typedef int (*fn_mprot)(void*, size_t, int);
static sigjmp_buf guard_env;
static volatile int guard_sig = 0, guard_active = 0, guard_hits = 0;
static void guard_handler(int s) {
static const char msg[] = "FAULT" "\t" "guard" "\n";
guard_sig = s;
if (!guard_active || ++guard_hits > 8) { (void)!write(1, msg, sizeof msg - 1); _exit(125); }
guard_active = 0;
siglongjmp(guard_env, 1);
}
static unsigned char pages[32768] __attribute__((aligned(16384)));
static unsigned char buf[256] __attribute__((aligned(16)));
int main(void) {
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = guard_handler;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
char extra[300], id[16], label[100];
errno = 0;
void* fb = dlopen("libSceFiber.sprx", RTLD_LAZY);
void* lk = dlopen("libkernel.sprx", RTLD_LAZY);
snprintf(extra, sizeof extra, "libSceFiber=%d libkernel=%d", fb != 0, lk != 0);
probe_case("0", "load libSceFiber.sprx and libkernel.sprx", fb && lk ? 0 : -1, errno, extra);
if (!fb) { probe_end(); return 0; }
fn_opt f_opt = (fn_opt)dlsym(fb, "sceFiberOptParamInitialize");
void* f_init = dlsym(fb, "sceFiberInitialize");
void* f_info = dlsym(fb, "sceFiberGetInfo");
fn_mprot prot = lk ? (fn_mprot)dlsym(lk, "mprotect") : 0;
snprintf(extra, sizeof extra, "sceFiberOptParamInitialize=%d sceFiberInitialize=%d sceFiberGetInfo=%d mprotect=%d", f_opt != 0, f_init != 0, f_info != 0, prot != 0);
probe_case("0b", "dlsym of the functions (nothing but the first is called)", f_opt ? 0 : -1, 0, extra);
if (!f_opt) { probe_end(); return 0; }
/* b) normal call */
for (int round = 0; round < 2; ++round) {
memset(buf, 0xAA, sizeof buf);
errno = 0;
int r = f_opt(buf);
int e = errno;
int changed = 0, first = -1, last = -1;
for (int i = 0; i < 128; ++i) if (buf[i] != 0xAA) { changed++; if (first < 0) first = i; last = i; }
int canary = 1;
for (int i = 128; i < 192; ++i) if (buf[i] != 0xAA) canary = 0;
snprintf(id, sizeof id, "1.%d", round + 1);
snprintf(label, sizeof label, "sceFiberOptParamInitialize(aligned 0xAA buffer), call %d", round + 1);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d bytes_changed=%d first_changed=%d last_changed=%d canary_intact=%d first_16_bytes=%02x%02x%02x%02x%02x%02x%02x%02x", (unsigned)r, e, changed, first, last, canary,
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
probe_case(id, label, r, e, extra);
}
/* c) alignment */
int offs[3] = {1, 2, 4};
for (int i = 0; i < 3; ++i) {
memset(buf, 0xAA, sizeof buf);
guard_sig = 0;
int r = -1;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = f_opt(buf + offs[i]);
guard_active = 0;
}
int changed = 0;
for (int k = 0; k < 160; ++k) if (buf[k] != 0xAA) changed++;
snprintf(id, sizeof id, "2.%d", i + 1);
snprintf(label, sizeof label, "sceFiberOptParamInitialize(buffer + %d)", offs[i]);
snprintf(extra, sizeof extra, "rc=0x%08x fault_signal=%d bytes_changed_in_first_160=%d", (unsigned)r, (int)guard_sig, changed);
probe_case(id, label, r, 0, extra);
}
/* d) pointer cases */
struct { const char* tag; int kind; } pc[6] = {{"NULL", 0}, {"0x1", 1}, {"0x1000", 2}, {"read-only page", 3}, {"page without access", 4}, {"120 bytes before the end of a writable page", 5}};
int stopped = 0;
for (int i = 0; i < 6 && !stopped; ++i) {
void* target = 0;
unsigned char* tail = pages + 16384 - 120;
switch (pc[i].kind) {
case 0: target = 0; break;
case 1: target = (void*)0x1; break;
case 2: target = (void*)0x1000; break;
case 3:
if (!prot) continue;
prot(pages, 16384, PROT_READ);
target = pages;
break;
case 4:
if (!prot) continue;
prot(pages, 16384, PROT_NONE);
target = pages;
break;
default:
if (!prot) continue;
memset(pages, 0xAA, sizeof pages);
prot(pages + 16384, 16384, PROT_NONE);
target = tail;
break;
}
guard_sig = 0;
int r = -1;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = f_opt(target);
guard_active = 0;
} else {
stopped = 1;
}
if (pc[i].kind == 3 || pc[i].kind == 4) prot(pages, 16384, PROT_READ | PROT_WRITE);
int written = 0;
if (pc[i].kind == 5) {
prot(pages + 16384, 16384, PROT_READ | PROT_WRITE);
for (int k = 0; k < 120; ++k) if (tail[k] != 0xAA) written++;
}
snprintf(id, sizeof id, "3.%d", i + 1);
snprintf(label, sizeof label, "sceFiberOptParamInitialize(%s)", pc[i].tag);
snprintf(extra, sizeof extra, "rc=0x%08x fault_signal=%d bytes_written_of_the_first_120=%d", (unsigned)r, (int)guard_sig, written);
probe_case(id, label, r, 0, extra);
}
if (stopped) probe_case("4", "pointer cases stopped after the first fault", 0, 0, "remaining pointer cases skipped by design");
probe_end();
return 0;
}1st probe (16:37 UTC): stdout2nd probe (20:03 UTC): probe.c (build b6ab01f816ac)/* Probe: sceFiberOptParamInitialize, follow-up to libSceFiber_optparam_init, payload process, firmware 11.60 (debt libSceFiber.md:6: it returns SCE_FIBER_ERROR_INVALID when the destination pointer is
unwritable, a defensive host-protection fallback, whether the console raises a signal or faults on unmapped or read-only memory is not measured). The first run measured: all 128 bytes written, the first
8 bytes 4d e6 40 bb 00 00 00 00, the alignment error 0x80590002 for the offsets +1, +2 and +4, NULL 0x80590001, 0x1 0x80590002 and the aligned unmapped address 0x1000 SIGSEGV, which ended the
pointer cases. This run (dlopen("libSceFiber.sprx"), sceFiberOptParamInitialize looked up with dlsym first and the only function called) prints the 128 bytes written into a 0xAA-filled aligned buffer as eight
lines of 16 bytes in hex (the content of the structure is a constant of the library, no identifier), twice (are both calls equal), and the buffer at the offsets +8, +16 and +32 (return value, how many bytes changed, where the first one is), and then the pointer cases the first run did not reach, each one single call and only while
the previous one did not fault: a pointer to a read-only page, a pointer to a page without access, and a pointer 120 bytes before the end of a writable page followed by a page without access (two 16 KiB aligned
static arrays, mprotect and back at once, no mmap; the return value in hex, the fault signal and how many of the first 120 bytes were written). A fault is caught by a guard (one hit per case, more than eight
end the probe with _exit(125)); a fault is a result. Nothing is written to a file, 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 volatile int g_handle = -1;
static int (*volatile g_setmargins)(int, int, int) = 0; /* unused here */
static void reset_rate(void) {
if (g_setmargins && g_handle >= 0) g_setmargins(g_handle, 0, 0);
}
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
reset_rate();
_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);
reset_rate();
_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);
}
#include <setjmp.h>
#include <sys/mman.h>
typedef int (*fn_opt)(void*);
typedef int (*fn_mprot)(void*, size_t, int);
static sigjmp_buf guard_env;
static volatile int guard_sig = 0, guard_active = 0, guard_hits = 0;
static void guard_handler(int s) {
static const char msg[] = "FAULT" "\t" "guard" "\n";
guard_sig = s;
if (!guard_active || ++guard_hits > 8) { (void)!write(1, msg, sizeof msg - 1); _exit(125); }
guard_active = 0;
siglongjmp(guard_env, 1);
}
static unsigned char pages[32768] __attribute__((aligned(16384)));
static unsigned char buf[256] __attribute__((aligned(16)));
int main(void) {
struct sigaction sa;
memset(&sa, 0, sizeof sa);
sa.sa_handler = guard_handler;
sigaction(SIGSEGV, &sa, 0);
sigaction(SIGBUS, &sa, 0);
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
probe_header();
char extra[300], id[16], label[100];
errno = 0;
void* fb = dlopen("libSceFiber.sprx", RTLD_LAZY);
void* lk = dlopen("libkernel.sprx", RTLD_LAZY);
snprintf(extra, sizeof extra, "libSceFiber=%d libkernel=%d", fb != 0, lk != 0);
probe_case("0", "load libSceFiber.sprx and libkernel.sprx", fb && lk ? 0 : -1, errno, extra);
if (!fb) { probe_end(); return 0; }
fn_opt f_opt = (fn_opt)dlsym(fb, "sceFiberOptParamInitialize");
void* f_init = dlsym(fb, "sceFiberInitialize");
void* f_info = dlsym(fb, "sceFiberGetInfo");
fn_mprot prot = lk ? (fn_mprot)dlsym(lk, "mprotect") : 0;
snprintf(extra, sizeof extra, "sceFiberOptParamInitialize=%d sceFiberInitialize=%d sceFiberGetInfo=%d mprotect=%d", f_opt != 0, f_init != 0, f_info != 0, prot != 0);
probe_case("0b", "dlsym of the functions (nothing but the first is called)", f_opt ? 0 : -1, 0, extra);
if (!f_opt) { probe_end(); return 0; }
/* b) normal call */
for (int round = 0; round < 2; ++round) {
memset(buf, 0xAA, sizeof buf);
errno = 0;
int r = f_opt(buf);
int e = errno;
int changed = 0, first = -1, last = -1;
for (int i = 0; i < 128; ++i) if (buf[i] != 0xAA) { changed++; if (first < 0) first = i; last = i; }
int canary = 1;
for (int i = 128; i < 192; ++i) if (buf[i] != 0xAA) canary = 0;
snprintf(id, sizeof id, "1.%d", round + 1);
snprintf(label, sizeof label, "sceFiberOptParamInitialize(aligned 0xAA buffer), call %d", round + 1);
snprintf(extra, sizeof extra, "rc=0x%08x errno=%d bytes_changed=%d first_changed=%d last_changed=%d canary_intact=%d first_16_bytes=%02x%02x%02x%02x%02x%02x%02x%02x", (unsigned)r, e, changed, first, last, canary,
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
probe_case(id, label, r, e, extra);
for (int row = 0; row < 8; ++row) {
char hx[48] = "";
for (int k = 0; k < 16; ++k) { char b[4]; snprintf(b, sizeof b, "%02x", buf[row * 16 + k]); strncat(hx, b, sizeof hx - strlen(hx) - 1); }
snprintf(id, sizeof id, "1.%d.r%d", round + 1, row);
snprintf(label, sizeof label, "bytes %d..%d of call %d", row * 16, row * 16 + 15, round + 1);
probe_case(id, label, 0, 0, hx);
}
}
/* c) alignment, offsets 8, 16 and 32 inside the own buffer (the offsets 1, 2 and 4 were measured, ALIGNMENT) */
int offs[3] = {8, 16, 32};
for (int i = 0; i < 3; ++i) {
memset(buf, 0xAA, sizeof buf);
guard_sig = 0;
int r = -1;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = f_opt(buf + offs[i]);
guard_active = 0;
}
int changed = 0, first = -1;
for (int k = 0; k < 256; ++k) if (buf[k] != 0xAA) { changed++; if (first < 0) first = k; }
snprintf(id, sizeof id, "2.%d", i + 1);
snprintf(label, sizeof label, "sceFiberOptParamInitialize(buffer + %d)", offs[i]);
snprintf(extra, sizeof extra, "rc=0x%08x fault_signal=%d bytes_changed_in_256=%d first_changed=%d magic_at_offset=%02x%02x%02x%02x", (unsigned)r, (int)guard_sig, changed, first, buf[offs[i]], buf[offs[i]+1], buf[offs[i]+2], buf[offs[i]+3]);
probe_case(id, label, r, 0, extra);
}
/* d) pointer cases */
struct { const char* tag; int kind; } pc[3] = {{"read-only page", 3}, {"page without access", 4}, {"120 bytes before the end of a writable page", 5}};
int stopped = 0;
for (int i = 0; i < 3 && !stopped; ++i) {
void* target = 0;
unsigned char* tail = pages + 16384 - 120;
switch (pc[i].kind) {
case 0: target = 0; break;
case 1: target = (void*)0x1; break;
case 2: target = (void*)0x1000; break;
case 3:
if (!prot) continue;
prot(pages, 16384, PROT_READ);
target = pages;
break;
case 4:
if (!prot) continue;
prot(pages, 16384, PROT_NONE);
target = pages;
break;
default:
if (!prot) continue;
memset(pages, 0xAA, sizeof pages);
prot(pages + 16384, 16384, PROT_NONE);
target = tail;
break;
}
guard_sig = 0;
int r = -1;
if (sigsetjmp(guard_env, 1) == 0) {
guard_active = 1;
errno = 0;
r = f_opt(target);
guard_active = 0;
} else {
stopped = 1;
}
if (pc[i].kind == 3 || pc[i].kind == 4) prot(pages, 16384, PROT_READ | PROT_WRITE);
int written = 0;
if (pc[i].kind == 5) {
prot(pages + 16384, 16384, PROT_READ | PROT_WRITE);
for (int k = 0; k < 120; ++k) if (tail[k] != 0xAA) written++;
}
snprintf(id, sizeof id, "3.%d", i + 1);
snprintf(label, sizeof label, "sceFiberOptParamInitialize(%s)", pc[i].tag);
snprintf(extra, sizeof extra, "rc=0x%08x fault_signal=%d bytes_written_of_the_first_120=%d", (unsigned)r, (int)guard_sig, written);
probe_case(id, label, r, 0, extra);
}
if (stopped) probe_case("4", "pointer cases stopped after the first fault", 0, 0, "remaining pointer cases skipped by design");
probe_end();
return 0;
}2nd probe (20:03 UTC): stdoutAI-assisted (Claude Code). |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against b1637fec88:
- Conventions:
tools/check_conventions.pypassed. - Build:
fiber_testsbuilt cleanly. - CTest (
fiber,fiber_contextless):1/2 Test #3634: fiber ............................ Passed 0.02 sec 2/2 Test #3635: fiber_contextless ................ Passed 0.02 sec 100% tests passed, 0 tests failed out of 2 - Negative control: with
core/libs/prx/libSceFiber/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/2 Test #3635: fiber_contextless ................ Passed 0.03 sec 2/2 Test #3634: fiber ............................Subprocess aborted***Exception: 0.36 sec 50% tests passed, 1 tests failed out of 2 - Code reading:
- Verified core/libs/prx/libSceFiber/Export.cpp: sceFiberOptParamInitialize performs null pointer validation returning SCE_FIBER_ERROR_NULL (0x80590001) before alignment check.
- Verified 8-byte alignment check ((reinterpret_caststd::uintptr_t(opt_param) & 7) != 0) returns SCE_FIBER_ERROR_ALIGNMENT (0x80590002) matching probe measurements on FW 11.60.
- Verified buffer zeroing and little-endian 32-bit magic 0xBB40E64D placement via GuestCopyOut_nid_no_patch to prevent host faults and retain preserved errno on failure returning SCE_FIBER_ERROR_INVALID.
- Verified technical debt fragment in docs/dev/debt/changes/fix-fiber-optparam-initialize-magic.md correctly documents defensive unwritable host handling and alignment behavior according to AGENTS.md.
- Verified unit test core/libs/tests/Fiber.cpp rigorously covers alignment offsets (0, 8, 16, 32 vs 1, 2, 4), sentinel integrity, magic match, and zeroes in trailing bytes.
Looks Good To Me
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
What
sceFiberOptParamInitializeincore/libs/prx/libSceFiber/Export.cppwrote 128 zero bytes and had no alignment check; a pointer such as 0x1 reached the guest copy, which failed, and the call returnedSCE_FIBER_ERROR_INVALID(0x80590004). A PS5 payload process on firmware 11.60 called the console's function and read the block back. The console writes 128 bytes: the bytes 0 to 3 are4d e6 40 bb, the 32-bit value 0xBB40E64D in little-endian order, and the bytes 4 to 127 are zero (second probe, case 1.1, lines 4 to 12, with the call repeated in 1.2, lines 13 to 21; the first probe shows 128 bytes changed and the canary behind the block intact, lines 4 and 5). Buffers at +8, +16 and +32 returned 0, wrote 128 bytes from the offset and had the same magic there (2.1 to 2.3, lines 22 to 24). The offsets +1, +2 and +4 returnedSCE_FIBER_ERROR_ALIGNMENT(0x80590002) and wrote nothing (first probe, 2.1 to 2.3, lines 6 to 8), the pointer 0x1 returned 0x80590002 as well (3.2, line 10), and NULL returnedSCE_FIBER_ERROR_NULL(0x80590001, 3.1, line 9). The pointer 0x1000 faulted with SIGSEGV and wrote none of the first 120 bytes (3.3, line 11), and so did a block on a read-only page (second probe, 3.1, line 25).The fix changes
sceFiberOptParamInitializeto follow that: NULL still returns 0x80590001, a pointer that is not 8-byte aligned now returns 0x80590002 before anything is written, and the block written is the magic 0xBB40E64D at the bytes 0 to 3 and zero for the rest; a block the host cannot write still returnsSCE_FIBER_ERROR_INVALID, where the console faults, which the debt entry ofsceFiberOptParamInitializenow says. The 8-byte rule is the oneExport.cppalready applies to the fiber object (object & 7); on the console +1, +2, +4 (fail) and +8, +16, +32 (succeed) were measured, +3 and +5 to +7 were not, so the rule for those offsets is an extension, and the test pins only the measured offsets.The test commit changes
core/libs/tests/Fiber.cpp: the old check that the block is all zero becomes a check of the magic and of the zero bytes 4 to 127 at the offsets 0, +8, +16 and +32, with the bytes around the block and a sentinel behind it intact; the offsets +1, +2, +4 and the pointer 0x1 must returnSCE_FIBER_ERROR_ALIGNMENTand write nothing. The documentation commit adds a debt fragment (docs/dev/debt/changes/fix-fiber-optparam-initialize-magic.md) that replaces the one debt sentence ofsceFiberOptParamInitializeto state the fault at 0x1000 and on a read-only page and the unmeasured offsets.The effect on titles is small:
_sceFiberInitializeImpland_sceFiberInitializeWithInternalOptionImpldo not read the option block here ((void)opt_param), so the magic and the alignment error matter only to a title that reads the block back or checks the result; no such title is known. The block's meaning beyond the magic is not known.Not measured: the offsets +3 and +5 to +7, a block in a title process, and other firmware.
Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from homebrew payload processes (ps5-payload-sdk v0.45, elfldr) that loadlibSceFiber.sprxand takesceFiberOptParamInitializewithdlsym, on 2026-11-18 at 16:37 UTC and 20:03 UTC. A title process may differ. The probe sources and the complete output of both runs are in the first comment.mainbefore (code read; the test commit fails on it)4d e6 40 bb, rest zeroRed and green, on one base: Windows 10 Pro (MinGW GCC, Release, ninja -j4), base
upstream/maina1dc368acc8, one build per phase (checkout, cmake, ninja, thenctest -R ^fiber, which runsfiberandfiber_contextless): on the base both tests pass; with the test commit78145dc01e8(treeade7e9dddead)fiberfails (exit code 0xc0000409, "Fiber check failed: misaligned opt param") andfiber_contextlesspasses; with the fix commita0cf746f1be(tree15300a111f58) both pass; with the documentation commitb1637fec884(tree497bc243f301) both pass.tools/debt_fold.py --checkand the convention check pass on the head. A merge intoupstream/main9a50e1014eewas checked withgit merge-treeand is clean. Linux was not run here; CI will.tools/check_conventions.py --base upstream/mainpasses with no error. The change is 3 files, +37/-12, with no new comments in code.Overlap: the other open pull requests that change the files of this branch (
core/libs/prx/libSceFiber/Export.cpp,core/libs/tests/Fiber.cppand the fragmentdocs/dev/debt/changes/fix-fiber-optparam-initialize-magic.md, a new file, for the entrysceFiberOptParamInitializeindocs/dev/debt/libSceFiber.md), found by reading the changed files of all 2014 open pull requests at about 22:59 to 23:16 UTC, by reading what they change in those files and in the debt files forsceFiberOptParamInitializeandFiberOptParam, and by searching their titles and branch names for the same names (no hit), were checked on 2026-11-18 at about 23:02 UTC againstmain9a50e1014eetogether with this head: the branch is based ona1dc368acc8, an ancestor of it, merges intomainwithout a conflict, andtools/debt_fold.py --checkapplies the fragment together with every other fragment onmainwithout an error (mainitself reports an error for the fragmentfeat-tools-windows-response-files.md, "no debt file for TechnicalDebt", with or without this branch; with that one fragment left out, the check passes with this fragment). Four pull requests list one of these files, and one of them conflicts with this change: #18918 (test(libSceFiber): audit fiber optional parameter buffer zeroing and invalid pointer rejection, approved) changes the same lines ofcore/libs/tests/Fiber.cpp. It keeps the check that the block is all zero aftersceFiberOptParamInitializeand adds the same check after a second call (opt param cleared,opt param cleared again), which the console measurement here contradicts, because the bytes 0 to 3 are the magic. It merges intomainwithout a conflict and conflicts with this branch inFiber.cpp. Its checks that the pointers 0x1000 and 0x7FFFFFFFFFFF0000 returnSCE_FIBER_ERROR_INVALIDand that the sentinels stay intact hold with this change; its two zero checks do not. Whichever of the two lands second has to bring the test of the other along, and in #18918 the zero checks have to become checks of the magic and the zero bytes 4 to 127. #20050 (fix(build): spell the ASan opt-out so Clang honours it) changesFiber.cppin lines that do not namesceFiberOptParamInitialize, and #22414 (fix(libSceFiber): reject unreadable fiber objects instead of faulting) changes other functions ofExport.cpp; both merge with this branch without a conflict. #7149 (fix(threads): run Windows pthread and small fiber stacks in guest VA range) listsExport.cppandlibSceFiber.mdand none of its changed lines namessceFiberOptParamInitialize; it conflicts withmainin six other files already. #21056 (test(libSceFiber): audit sceFiberGetInfo parameter validation, structure size, and field bounds) changes onlylibSceFiber/CMakeLists.txtand a new test file, and conflicts withmainin theCMakeLists.txtalready. Unpublished local branches that touch these files were compared as well, and none changes these functions. The merged result was not built or run beyond the red and green runs above.Added after a wider search: four more open pull requests test this call with the same all-zero expectation, each in a new test file of its own, and require that all 0x80 bytes are zero after
sceFiberOptParamInitialize: #18568 (test(libSceFiber): audit fiber optional parameter size validation and limits,GuestFiberOptParamSize.cpp, "opt param bytes must be cleared"), #20851 (test(libSceFiber): audit optional parameter zeroing, guard page size validation, and run error bounds,GuestFiberOptParamGuardBounds.cpp), #21031 (test(libSceFiber): audit optional parameter zeroing, stack range bounds, context alignment, and guard page margins,GuestFiberOptStackGuardBounds.cpp) and #21126 (test(libSceFiber): audit internal options, attached stack boundaries, and guard page margins,GuestFiberInternalOptStackBounds.cpp). They register their test files incore/libs/prx/libSceFiber/CMakeLists.txt, which this branch does not change, so there is no textual conflict with it, but with this change their zero checks fail, like the two zero checks of #18918; #20851, #21031 and #21126 already conflict withmain. #20947 (test(libSceFiber): audit green threading, context parameters, stack guard pages, and run error bounds) only checks that the call returns 0 on an 8-byte aligned buffer and is not affected. This search read the changed files of all 2005 open pull requests at about 00:27 to 00:29 UTC on 2026-11-19, for paths containingFiberand forOptParamin their patches. Onmainthe call is made only incore/libs/tests/Fiber.cpp, which this branch updates.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)