Repository navigation
docs(debt): record the openat, mkdirat, unlinkat and renameat results on firmware 11.60 - #22638
Conversation
… on firmware 11.60 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe source (built with ps5-payload-sdk v0.45; probe.c/* openat, mkdirat, unlinkat, renameat and readlinkat with a directory descriptor, payload process, firmware 11.60 (debt
libkernel_sys.md entries for these five: AnyPS5 passes AT_FDCWD (-100) and absolute paths to the plain call; any other relative
path is joined to the descriptor's host directory, found the same way as for fchdir, so guest path aliases and case-insensitive
name matching do not apply to it and a ".." component is not kept inside the guest root; EBADF for a descriptor that is not
open and ENOTDIR for one that is not a directory; unlinkat without AT_REMOVEDIR on a directory fails with EPERM, "." or ".."
with AT_REMOVEDIR fails with EINVAL, other flags fail with EINVAL; console behaviour unverified). Prototypes: int openat(int,
const char*, int, mode_t), int mkdirat(int, const char*, mode_t), int unlinkat(int, const char*, int), int renameat(int,
const char*, int, const char*), ssize_t readlinkat(int, const char*, char*, size_t). All five are looked up with dlsym in
libkernel.sprx. Everything happens below the probe directory's own subdirectory /data/anyps5_probe/n2_12_bo3 (created and removed
by the probe). Only return codes, errno and equalities of inode numbers are printed. Cases: open the directory with
O_DIRECTORY; openat creating a file with O_EXCL twice (EEXIST), the same file through the absolute path with AT_FDCWD (same
inode), an absolute path with an invalid descriptor, relative paths with descriptors -1 and 999 and with a file descriptor;
mkdirat twice and with a missing parent, a name in different letter case; ".." and "../.." through a descriptor against the
absolute path of the same directory; renameat inside the directory, with a missing source, into a second directory descriptor and
with an invalid descriptor; unlinkat of a directory without AT_REMOVEDIR, of a non-empty directory with AT_REMOVEDIR, "." and
".." with AT_REMOVEDIR (the directory is not empty, nothing can be removed) and an invalid flag; readlinkat on a regular
file and with an invalid descriptor. No symbolic link is created, nothing outside the probe directory is touched, no chdir.
Cleanup is mandatory: every file and directory made is removed with unlinkat and the directory with rmdir; the
return codes are logged. 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 <fcntl.h>
#include <sys/stat.h>
#define ATFD (-100)
#define ATRM 0x800
typedef int (*fn_openat)(int, const char*, int, mode_t);
typedef int (*fn_mkdirat)(int, const char*, mode_t);
typedef int (*fn_unlinkat)(int, const char*, int);
typedef int (*fn_renameat)(int, const char*, int, const char*);
typedef long (*fn_readlinkat)(int, const char*, char*, size_t);
static fn_openat f_open;
static fn_mkdirat f_mkdir;
static fn_unlinkat f_unlink;
static fn_renameat f_rename;
static fn_readlinkat f_readlink;
static void fault(int sig) {
static const char msg[] = "FAULT\tsignal in the call\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(125);
}
static void res(const char* id, const char* label, long r, int e, const char* more) {
char extra[200];
snprintf(extra, sizeof extra, "rc=%ld errno=%d%s%s", r, e, more[0] ? " " : "", more);
probe_case(id, label, r, e, extra);
}
static long ino_of(int fd) {
struct stat st;
if (fstat(fd, &st) != 0) return -1;
return (long)st.st_ino;
}
int main(void) {
signal(SIGALRM, probe_alarm);
signal(SIGSEGV, fault);
signal(SIGBUS, fault);
alarm(PROBE_MAX_S);
probe_header();
char extra[200];
errno = 0;
void* lk = dlopen("libkernel.sprx", RTLD_LAZY);
probe_case("0", "load libkernel.sprx", lk ? 0 : -1, errno, lk ? "loaded" : dlerror());
if (!lk) { probe_end(); return 0; }
f_open = (fn_openat)dlsym(lk, "openat");
f_mkdir = (fn_mkdirat)dlsym(lk, "mkdirat");
f_unlink = (fn_unlinkat)dlsym(lk, "unlinkat");
f_rename = (fn_renameat)dlsym(lk, "renameat");
f_readlink = (fn_readlinkat)dlsym(lk, "readlinkat"); /* optional: the first run found it not exported in libkernel.sprx */
snprintf(extra, sizeof extra, "openat=%d mkdirat=%d unlinkat=%d renameat=%d readlinkat=%d", f_open != 0, f_mkdir != 0, f_unlink != 0,
f_rename != 0, f_readlink != 0);
probe_case("0b", "dlsym of the functions", 0, 0, extra);
if (!f_open || !f_mkdir || !f_unlink || !f_rename) { probe_end(); return 0; }
errno = 0;
int mk = mkdir("/data/anyps5_probe/n2_12_bo3", 0700);
int mke = errno;
res("1", "mkdir(probe subdirectory)", mk, mke, "");
int dirfd = open("/data/anyps5_probe/n2_12_bo3", O_RDONLY | O_DIRECTORY);
int fd1 = -1, dirfd2 = -1;
if (dirfd < 0) {
res("1b", "open the probe subdirectory with O_DIRECTORY", dirfd, errno, "");
goto cleanup;
}
/* a) openat */
errno = 0;
fd1 = f_open(dirfd, "f1", O_CREAT | O_RDWR | O_EXCL, 0600);
res("2.1", "openat(dirfd, \"f1\", O_CREAT|O_RDWR|O_EXCL)", fd1, errno, fd1 >= 0 ? "created=1" : "created=0");
errno = 0;
int x = f_open(dirfd, "f1", O_CREAT | O_RDWR | O_EXCL, 0600);
res("2.2", "openat(dirfd, \"f1\", O_CREAT|O_EXCL) again", x, errno, "");
if (x >= 0) close(x);
errno = 0;
int xa = f_open(ATFD, "/data/anyps5_probe/n2_12_bo3/f1", O_RDONLY, 0);
snprintf(extra, sizeof extra, "same_inode_as_f1=%d", xa >= 0 && fd1 >= 0 && ino_of(xa) == ino_of(fd1));
res("2.3", "openat(AT_FDCWD, absolute path of f1, O_RDONLY)", xa, errno, extra);
if (xa >= 0) close(xa);
errno = 0;
x = f_open(999, "/data/anyps5_probe/n2_12_bo3/f1", O_RDONLY, 0);
res("2.4", "openat(999, absolute path of f1) invalid descriptor, absolute path", x, errno, "");
if (x >= 0) close(x);
errno = 0;
x = f_open(-1, "f1", O_RDONLY, 0);
res("2.5", "openat(-1, \"f1\") relative", x, errno, "");
if (x >= 0) close(x);
errno = 0;
x = f_open(999, "f1", O_RDONLY, 0);
res("2.6", "openat(999, \"f1\") relative", x, errno, "");
if (x >= 0) close(x);
if (fd1 >= 0) {
errno = 0;
x = f_open(fd1, "x", O_RDONLY, 0);
res("2.7", "openat(fd of f1, \"x\") descriptor is a file", x, errno, "");
if (x >= 0) close(x);
}
/* b) mkdirat */
errno = 0;
int r = f_mkdir(dirfd, "sub", 0700);
res("3.1", "mkdirat(dirfd, \"sub\")", r, errno, "");
errno = 0;
r = f_mkdir(dirfd, "sub", 0700);
res("3.2", "mkdirat(dirfd, \"sub\") again", r, errno, "");
errno = 0;
r = f_mkdir(dirfd, "sub/a/b", 0700);
res("3.3", "mkdirat(dirfd, \"sub/a/b\") missing parent", r, errno, "");
errno = 0;
x = f_open(dirfd, "SUB", O_RDONLY | O_DIRECTORY, 0);
res("3.4", "openat(dirfd, \"SUB\", O_DIRECTORY) other letter case", x, errno, "");
if (x >= 0) close(x);
/* c) dot-dot */
struct stat s1, s2;
int sr = stat("/data/anyps5_probe", &s1), sp = stat("/data/anyps5_probe/..", &s2);
errno = 0;
x = f_open(dirfd, "..", O_RDONLY | O_DIRECTORY, 0);
snprintf(extra, sizeof extra, "same_inode_as_probe_root=%d", x >= 0 && sr == 0 && ino_of(x) == (long)s1.st_ino);
res("4.1", "openat(dirfd, \"..\", O_DIRECTORY)", x, errno, extra);
if (x >= 0) close(x);
errno = 0;
x = f_open(dirfd, "../..", O_RDONLY | O_DIRECTORY, 0);
snprintf(extra, sizeof extra, "same_inode_as_parent_of_probe_root=%d", x >= 0 && sp == 0 && ino_of(x) == (long)s2.st_ino);
res("4.2", "openat(dirfd, \"../..\", O_DIRECTORY)", x, errno, extra);
if (x >= 0) close(x);
/* d) renameat */
if (fd1 >= 0) { close(fd1); fd1 = -1; }
errno = 0;
r = f_rename(dirfd, "f1", dirfd, "f2");
res("5.1", "renameat(dirfd, \"f1\", dirfd, \"f2\")", r, errno, "");
errno = 0;
r = f_rename(dirfd, "f1", dirfd, "f9");
res("5.2", "renameat(dirfd, \"f1\" missing, dirfd, \"f9\")", r, errno, "");
dirfd2 = open("/data/anyps5_probe/n2_12_bo3/sub", O_RDONLY | O_DIRECTORY);
if (dirfd2 >= 0) {
errno = 0;
r = f_rename(dirfd, "f2", dirfd2, "f3");
res("5.3", "renameat(dirfd, \"f2\", dirfd of sub, \"f3\")", r, errno, "");
errno = 0;
x = f_open(dirfd2, "f3", O_RDONLY, 0);
res("5.4", "openat(dirfd of sub, \"f3\") after the move", x, errno, "");
if (x >= 0) close(x);
} else {
res("5.3", "open the subdirectory with O_DIRECTORY", dirfd2, errno, "");
}
errno = 0;
r = f_rename(999, "f2", dirfd, "f8");
res("5.5", "renameat(999, \"f2\", dirfd, \"f8\") invalid descriptor", r, errno, "");
/* e) unlinkat */
errno = 0;
r = f_unlink(dirfd, "sub", 0);
res("6.1", "unlinkat(dirfd, \"sub\", 0) directory without AT_REMOVEDIR", r, errno, "");
errno = 0;
r = f_unlink(dirfd, "sub", ATRM);
res("6.2", "unlinkat(dirfd, \"sub\", AT_REMOVEDIR) not empty", r, errno, "");
errno = 0;
r = f_unlink(dirfd, ".", ATRM);
res("6.3", "unlinkat(dirfd, \".\", AT_REMOVEDIR)", r, errno, "");
errno = 0;
r = f_unlink(dirfd, "..", ATRM);
res("6.4", "unlinkat(dirfd, \"..\", AT_REMOVEDIR)", r, errno, "");
errno = 0;
r = f_unlink(dirfd, "zzz_not_here", 1);
res("6.5", "unlinkat(dirfd, \"zzz_not_here\", flag 0x1) invalid flag", r, errno, "");
/* f) readlinkat */
errno = 0;
int f4 = f_open(dirfd, "f4", O_CREAT | O_RDWR | O_EXCL, 0600);
if (f4 >= 0) close(f4);
char buf[64];
if (f_readlink) {
errno = 0;
long rl = f_readlink(dirfd, "f4", buf, sizeof buf);
res("7.1", "readlinkat(dirfd, \"f4\") regular file", rl, errno, "");
errno = 0;
rl = f_readlink(999, "f4", buf, sizeof buf);
res("7.2", "readlinkat(999, \"f4\") invalid descriptor", rl, errno, "");
} else {
probe_case("7", "readlinkat", 0, 0, "not exported in libkernel.sprx: cases skipped");
}
cleanup:
if (fd1 >= 0) close(fd1);
{
int c1 = -99, c2 = -99, c3 = -99, c4 = -99, c5 = -99, c6 = -99, c7 = -99, c8 = -99;
if (dirfd2 >= 0) { c1 = f_unlink(dirfd2, "f3", 0); close(dirfd2); }
if (dirfd >= 0) {
c2 = f_unlink(dirfd, "f1", 0);
c3 = f_unlink(dirfd, "f2", 0);
c4 = f_unlink(dirfd, "f4", 0);
c5 = f_unlink(dirfd, "f8", 0);
c6 = f_unlink(dirfd, "f9", 0);
c7 = f_unlink(dirfd, "sub", ATRM);
close(dirfd);
}
c8 = rmdir("/data/anyps5_probe/n2_12_bo3");
snprintf(extra, sizeof extra, "f3=%d f1=%d f2=%d f4=%d f8=%d f9=%d sub=%d rmdir=%d (-99 = not tried, -1 = nothing to remove)", c1, c2, c3, c4, c5,
c6, c7, c8);
probe_case("9", "cleanup: unlinkat of every name made, rmdir of the probe subdirectory", c8, 0, extra);
}
probe_end();
return 0;
}stdoutAI-assisted (Claude Code). |
What
The entries for
openat/_openat,mkdirat,readlinkat,unlinkatandrenameatindocs/dev/debt/libkernel_sys.mddescribe how AnyPS5 passesAT_FDCWDand absolute paths to the plain calls, joins other relative paths to the descriptor's host directory and returnsEBADFandENOTDIR, and each ends with "Console behaviour is unverified". A probe has now called the four calls thatlibkernel.sprxexports on firmware 11.60, from a payload process, inside a directory it created. The pull request replaces that last sentence in each entry through one debt fragment, as the contribution rules ask; no code changes.openatwithO_CREAT|O_EXCLcreated a file (case 2.1, line 5) and returnedEEXISTfor the same name again (2.2, line 6); an absolute path withAT_FDCWDopened the same file (2.3, line 7), and an absolute path with the descriptor 999, which is not open, also succeeded (2.4, line 8). A relative path with the descriptor -1 or 999 returnedEBADF(2.5 and 2.6, lines 9 and 10) and one with the descriptor of a file returnedENOTDIR(2.7, line 11).mkdiratcreated a directory (3.1, line 12), returnedEEXISTfor an existing name (3.2, line 13) andENOENTfor a missing parent (3.3, line 14).openatofSUBreturnedENOENTwhere the directory had been created assub(3.4, line 15), and..and../..opened the parent folders (4.1 and 4.2, lines 16 and 17).renameatrenamed a file within a directory descriptor (5.1, line 18), returnedENOENTfor a missing source (5.2, line 19), moved a file into a second directory descriptor, whereopenatthen found it (5.3 and 5.4, lines 20 and 21), and returnedEBADFfor the descriptor 999 (5.5, line 22).unlinkatof a directory withoutAT_REMOVEDIRreturnedEPERM(6.1, line 23), of a directory that is not emptyENOTEMPTY(6.2, line 24), of.and..withAT_REMOVEDIREINVAL(6.3 and 6.4, lines 25 and 26) and with the flag 0x1EINVAL(6.5, line 27).readlinkatis not exported bylibkernel.sprxon this firmware (line 3), so it could not be measured; AnyPS5 exports it.When the code is read, AnyPS5 answers the same for these cases:
openat_nid_postfix(libkernel_sys/Export.cpp, lines 968 to 990) sends absolute paths andAT_FDCWDtoopenwithout looking at the descriptor (line 986) and other paths toOpenInDirectory_nid_no_patch;mkdirat(lines 1011 to 1045) givesEEXISTandENOENTfor the Windows cases at lines 1025 to 1031;unlinkat(lines 1151 to 1238) givesEINVALfor the flag (line 1152) and for.and..(line 1166),ENOTEMPTYfor a directory that is not empty (line 1181) andEPERMfor a directory withoutAT_REMOVEDIR(line 1216);renameat(lines 1250 to 1300) returnsEBADFfor a descriptor that is not open (lines 1264 and 1265) andENOENTfor a missing source (lines 1276 and 1277). The descriptor lookup givesEBADFandENOTDIR(libkernel/File/src/DirectoryDescriptor.cpp, lines 487 to 501). The rename itself after line 1300 and the tests were not read or compared, and the emulator was not run for this pull request.Two results are not compared. The console treated
SUBandsubas different names; here a relative path is joined to the descriptor's host directory, so the answer follows the host's name matching, which was not checked. And..led to the parent folders on the console, which has no guest root in a payload process, so the entry's remark that..is not kept inside the guest root cannot be checked against it.Not measured:
_openat, invalid descriptors formkdiratandunlinkat, symbolic links,readlinkat(not exported), and a title process.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr) that loadslibkernel.sprxand takes the five functions withdlsym(line 3 showsreadlinkatwas not found), on 2026-11-17 at 22:05 UTC. A title process may differ. The cases are 0 to 9, lines 2 to 29 of the raw output in the first comment.main(code read, not run)openatO_CREAT|O_EXCL, againEEXIST(lines 5, 6)openopenatabsolute path, descriptor 999 not openopenatrelative, descriptor -1 or 999;renameatdescriptor 999EBADF(lines 9, 10, 22)EBADFopenatrelative, descriptor of a fileENOTDIR(line 11)ENOTDIRopenatSUBforsub;..,../..ENOENT; parent folders (lines 15 to 17)mkdiratnew, existing, missing parentEEXIST,ENOENT(lines 12 to 14)renameatwithin, into a second descriptor; missing sourceENOENT(lines 18 to 21)ENOENT; the rename not readunlinkatdirectory withoutAT_REMOVEDIR; not emptyEPERM;ENOTEMPTY(lines 23, 24)EPERM;ENOTEMPTYunlinkat.,..withAT_REMOVEDIR; flag 0x1EINVAL(lines 25 to 27)EINVALreadlinkattools/check_conventions.py --base upstream/mainpasses with no error and no warning (the five entries are now 941, 737, 624, 956 and 738 characters, up from 600, 532, 507, 725 and 521). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against these calls, a title process, other firmware, and the cases listed above as not measured.Overlap: the other open pull requests that change the file of this branch (the fragment
docs/dev/debt/changes/docs-libkernel-sys-at-family-console-1160.md, a new file),core/libs/prx/libkernel_sys/Export.cpporcore/libs/prx/libkernel/File/src/DirectoryDescriptor.cpp, which the entries and the text name, or the five debt entries they change, found by reading the changed files of all 1779 open pull requests at about 23:11 to 23:28 UTC, by reading what they change indocs/dev/debt/libkernel_sys.mdand the fragments underdocs/dev/debt/changes/foropenat,mkdirat,readlinkat,unlinkatandrenameat, and by searching their titles and branch names for the same names (no hit), were test-merged on 2026-11-17 at about 23:34 UTC againstmain21f76fe3981together with this head; the branch is based on68071834eeb, an ancestor of it, merges intomainwithout a conflict, andtools/debt_fold.py --checkapplies the fragment to thelibkernel_sysdebt file ofmainwithout an error (checked without the fragmentslibressl3-20171-inventory.md,fix-libc-hypotl-msun-ld80.md,fix-libc-ld80-inverse-hyperbolic.mdandfix-libc-jnf-ynf-msun.md, which already conflict with other fragments or with thelibcdebt file onmainand are not part of this change), each of the five texts the change names occurs in exactly one entry, and no other fragment changes those entries. Twenty-two pull requests list one of the three files, most of them for other functions; as this branch adds only a fragment, none of them conflicts only with this change. #18190 changes calls inExport.cppto their_nid_no_patchforms, among them lines insideopenat,_openatandunlinkat, and does not change the entries of this branch; #21464, #12642, #12315 and #12130 carry thereadlinkatentry, #9302 and #9297 therenameatentry and #17936 the entries around them as unchanged context lines of their own hunks; none of them changes a line of the five entries of this branch or any line that namesopenat,mkdirat,readlinkat,unlinkatorrenameatin them. The merged result was not built or run; this is a documentation change.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)