fix(libkernel): refuse closing the standard descriptors with EPERM as measured on a PS5 #10136

Merged
orezraey merged 3 commits from upstream-pr/10136 into main 2026-10-23 14:23:16 +00:00
orezraey commented 2026-10-23 10:35:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-23T10:35:44Z.


What

AnyPS5 does not let a title close descriptors 0 to 2 when they belong to the host process. close returns EBADF and sceKernelClose returns 0x80020009. The debt entry said the console's result was unknown.

I measured it on a retail PS5 (firmware 13.60) with a homebrew probe, from a payload process. The source and console logs are in this gist (pclose, psem).

Call PS5
close(0), close(1), close(2) on open descriptors -1, errno 1 (EPERM); the descriptor stays open (F_GETFD still 0)
close(0) again -1, EPERM
sceKernelClose(0), (1), (2) 0x80020001
close of an already closed descriptor -1, EBADF
sceKernelClose of a closed descriptor, of -1 and of 100000 0x80020009
close(-1), close(100000) -1, EBADF

Both functions now fail with EPERM (0x80020001) on those descriptors. The debt entry records the measurement and says whether a title process can close them is unverified.

Tested

Windows 11, MinGW (winlibs).

  • guest_host_stream now expects EPERM and 0x80020001 for open descriptors 0 to 2. It also checks EBADF and 0x80020009 for a closed pipe descriptor and for -1. It fails on main and passes three runs in a row with the change.
  • tools/check_conventions.py passes.
  • tools/pr_overlap.py lists PRs that touch other lines of Open.cpp, Stdio.cpp and docs/dev/debt/libkernel.md; none change these two checks or this debt entry.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4981445505 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10136). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-23T10:35:44Z. --- ### What AnyPS5 does not let a title close descriptors 0 to 2 when they belong to the host process. `close` returns `EBADF` and `sceKernelClose` returns `0x80020009`. The debt entry said the console's result was unknown. I measured it on a retail PS5 (firmware 13.60) with a homebrew probe, from a payload process. The source and console logs are in [this gist](https://gist.github.com/orezraey/d74bff6afb405789528e9942db11bbe0) (`pclose`, `psem`). | Call | PS5 | |---|---| | `close(0)`, `close(1)`, `close(2)` on open descriptors | -1, `errno` 1 (`EPERM`); the descriptor stays open (`F_GETFD` still 0) | | `close(0)` again | -1, `EPERM` | | `sceKernelClose(0)`, `(1)`, `(2)` | `0x80020001` | | `close` of an already closed descriptor | -1, `EBADF` | | `sceKernelClose` of a closed descriptor, of -1 and of 100000 | `0x80020009` | | `close(-1)`, `close(100000)` | -1, `EBADF` | Both functions now fail with `EPERM` (`0x80020001`) on those descriptors. The debt entry records the measurement and says whether a title process can close them is unverified. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, MinGW (winlibs). - `guest_host_stream` now expects `EPERM` and `0x80020001` for open descriptors 0 to 2. It also checks `EBADF` and `0x80020009` for a closed pipe descriptor and for -1. It fails on `main` and passes three runs in a row with the change. - `tools/check_conventions.py` passes. - `tools/pr_overlap.py` lists PRs that touch other lines of `Open.cpp`, `Stdio.cpp` and `docs/dev/debt/libkernel.md`; none change these two checks or this debt entry. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-23 10:44:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:44:07Z.

Review: APPROVED


The firmware 13.60 probe in the linked gist supports the changed behavior: open descriptors 0–2 return EPERM from close, 0x80020001 from sceKernelClose, and remain open; a closed descriptor still yields EBADF/0x80020009. The implementation applies that distinction only to the host standard streams captured at library load, while the expanded test checks that they remain open and preserves closed/invalid-descriptor behavior. GCC 12.2 syntax-checked both changed implementation files and GuestHostStreams.cpp locally; the full CTest target was not runnable in this checkout. The author reports Windows focused tests passing three consecutive runs, including open, closed-pipe and invalid descriptors. Conventions, diff-check, and current-main sync pass (3 ahead/29 behind; merge clean); hosted eligibility/intake/conventions/labels pass, while product jobs are skipped by the workflow.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627151193 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10136#pullrequestreview-5627151193). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T10:44:07Z. **Review:** APPROVED --- The firmware 13.60 probe in the linked gist supports the changed behavior: open descriptors 0–2 return `EPERM` from `close`, `0x80020001` from `sceKernelClose`, and remain open; a closed descriptor still yields `EBADF`/`0x80020009`. The implementation applies that distinction only to the host standard streams captured at library load, while the expanded test checks that they remain open and preserves closed/invalid-descriptor behavior. GCC 12.2 syntax-checked both changed implementation files and `GuestHostStreams.cpp` locally; the full CTest target was not runnable in this checkout. The author reports Windows focused tests passing three consecutive runs, including open, closed-pipe and invalid descriptors. Conventions, diff-check, and current-main sync pass (3 ahead/29 behind; merge clean); hosted eligibility/intake/conventions/labels pass, while product jobs are skipped by the workflow.
MarcZX10 commented 2026-10-23 11:12:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:12:12Z.

Review: APPROVED


Reviewed the exact head 5c7cdfda26ef48ea255fcdd60c33fb143845596f. The two wrappers now return EPERM for host-owned descriptors 0–2, preserving the descriptors; the regression separately checks EBADF for closed and invalid descriptors and checks both POSIX and sceKernel error mappings. The debt entry distinguishes the retail PS5 measurement from unverified title-process behavior. Hosted conventions, eligibility, intake, labels and report checks pass; all product jobs were skipped by path policy. The author reports Windows focused tests failing on main and passing three times with the change. I did not independently run the guest test. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627432314 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10136#pullrequestreview-5627432314). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T11:12:12Z. **Review:** APPROVED --- Reviewed the exact head `5c7cdfda26ef48ea255fcdd60c33fb143845596f`. The two wrappers now return EPERM for host-owned descriptors 0–2, preserving the descriptors; the regression separately checks EBADF for closed and invalid descriptors and checks both POSIX and sceKernel error mappings. The debt entry distinguishes the retail PS5 measurement from unverified title-process behavior. Hosted conventions, eligibility, intake, labels and report checks pass; all product jobs were skipped by path policy. The author reports Windows focused tests failing on main and passing three times with the change. I did not independently run the guest test. No blocking issue found.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10136
No description provided.