Skip to content

fix(libkernel): protect standard descriptors from close - #10

Closed
JJenkx wants to merge 2 commits into
mainfrom
fix/kernel-standard-descriptors
Closed

JJenkx wants to merge 2 commits into
mainfrom
fix/kernel-standard-descriptors

Conversation

@JJenkx

@JJenkx JJenkx commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Superseded by merged upstream #3295, now included in main 6bb4fdc4f35. Main protects host streams while allowing descriptors that were initially closed to be used by the guest; this draft’s unconditional guard is no longer needed. Closing the review PR and preserving its branch/history.

What

Integration follow-up: our game-testing branch now adopts upstream boykopovar#3295 (9c30f0e), committed locally as 15357c6. The full Linux build, fourteen targeted tests and seventeen closed-standard-descriptor fixture cases pass. An isolated guest open/close of descriptor 0 fails under the old unconditional guard and passes with the replacement. The fixture disables write-watch because its userfaultfd would otherwise occupy descriptor 0 before main. All eight descriptor masks also pass with normal write-watch enabled. This draft retains the original implementation for historical comparison; it is no longer the policy used in the current game-testing integration. No fresh game runtime or standalone PR3295 full build is claimed.

A guest repeatedly closing descriptor 0 can close host stdin and then close an unrelated host file that reuses that number. This patch rejects guest closes of descriptors 0, 1 and 2 through sceKernelClose, close and _close. Kernel close returns EPERM without changing guest errno; the POSIX aliases return -1 with errno EPERM. Normal descriptors and socket dispatch retain their existing paths.

Regression coverage checks repeated calls through all three APIs, unchanged stream identity, normal descriptor closure and invalid-descriptor handling. The before-change regression failed; the candidate passed.

Validation: rebased topic commit 3df3b56 on upstream main 2a5eca1; conventions pass. The full Linux integration build b34fa2c passed, and thirteen related tests passed: patched_libraries, file_position, file_streams, guest_standard_streams, guest_filesystem, guest_posix_filesystem, guest_terminal, guest_kernel_errors, both named-shared-memory descriptor reuse tests, guest_socket_read_write, guest_file_vector and guest_kernel_fcntl. The two affected close functions and regression function are identical between this branch and the tested integration. No independent standalone full build, Windows run or PS5 hardware validation is claimed.

Historical RollerCoaster Tycoon Adventures Deluxe PPSA17330 evidence tied repeated sceKernelClose(0) calls to resources.assets descriptor reuse and stale asset data. The integration reached its title screen after the fix. Later integration gameplay/normal closure also required separate fixes and must not be attributed to this patch alone. No new title run was performed for this rebase.

Known limitation: this patch protects descriptor numbers 0-2 unconditionally. A host launched with a standard descriptor already closed may legitimately open a file at that number, which this patch would prevent the guest from closing. Guest standard streams are not modeled as a separate descriptor namespace. The PS5 error result remains unverified and documented in TechnicalDebt.

Upstream #3295 addresses the same host-stream problem, records which standard descriptors were open at library load, and chooses EBADF rather than EPERM. Its policy handles the initially-closed case more broadly. This draft publishes our existing work and Linux regression evidence for comparison; it is not proposed as a second upstream implementation. Upstream boykopovar#4474 occupies our contributor allowance.

AI-assisted: yes. No proprietary assets, binaries or investigation artifacts are committed.

Tested

Full Linux integration build b34fa2c and thirteen targeted library/file checks passed. Affected close functions and regression exactly match the topic branch. No independent standalone full build, Windows or fresh title run.

Checklist

  • One topic; generic behavior.
  • Base commits, overlap and validation limitations disclosed above. This is a fork review PR.
  • No proprietary assets, investigation artifacts or new third-party code committed.
  • No silent-success fallback added.
  • Known gaps recorded in technical debt.
  • Depends on: none
  • Unblocks: none (no complete title compatibility claim)
  • AI-assisted: yes

October 13 upstream update

Merged upstream 9d0a41d5a10 into this branch and resolved its conflicts while preserving this PR's scope. The published head is 9f33f553ae. It also merges cleanly with newer upstream 0214069e33c (the intervening change only updates the build workflow). Local conventions pass. The validation reported above applies to its original tested revision; validation of the updated head is running in the full build.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 12, 2026
@github-actions github-actions Bot added libkernel libkernel docs Documentation needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 13, 2026
@JJenkx JJenkx closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation libkernel libkernel needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant