Skip to content

fix(libkernel): answer sysarch XFPUSTATE's measured errors and empty copy, as a PS5 does - #742

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/22046
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/22046

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#22046, originally opened by brajankw.

Source commit: 3d354f3678db0debd914f58cedd2a24828e1eb27. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

sysarch threw for any non-null XFPUSTATE argument (operations 11 and 132). On a PS5 (firmware 12.70) operation 132 rejected lengths 1024 to 8192 with EINVAL and null arguments and addresses with EFAULT, and accepted lengths 0, 64, 128, 256 and 512 (the sysarch entry in docs/dev/debt/libkernel.md).

Following FreeBSD 11.4's order (copy the arguments in, compare the length unsigned, copy the state out):

  • an unreadable argument gives EFAULT, including one whose last bytes are unreadable: operation 11 copies in 8 bytes and 132 copies in 16;
  • a length from 1024 gives EINVAL;
  • length 0 returns 0 without copying;
  • a null address with a length up to 512 gives EFAULT.

Lengths 513 to 1023, whose limit was not measured, and copying out the live state still throw. GuestSysarch.cpp covers both operations; the pending sysarch debt fragment from boykopovar#22039 is updated here, as both change the same entry. It keeps the 13.60 LDT wording that 1364845 added.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head 3d354f3678, rebased onto main 11c9e7764e without conflicts. The runs after the first two bullets are from earlier heads.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of XFPU state requests, including validation of buffer lengths and clearer errors for invalid or inaccessible buffers.
    • Zero-length requests are accepted, while unsupported state-copy requests continue to report that the operation is unavailable.

…copy, as a PS5 does

sysarch threw for any non-null XFPUSTATE argument (operations 11 and
132). On a PS5 (firmware 12.70) operation 132 rejected lengths 1024 to
8192 with EINVAL and null arguments and addresses with EFAULT, and
accepted 0 to 512. Following FreeBSD 11.4's order (copy the arguments
in, compare the length unsigned, copy the state out), an unreadable
argument now gives EFAULT, a length from 1024 EINVAL, length 0 returns
0 without copying, and a null address with a length up to 512 gives
EFAULT. Lengths 513 to 1023, whose limit was not measured, and copying
out the live state still throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: XFPUSTATE sysarch handling

Layer / File(s) Summary
Argument handling, dispatch, and validation
core/libs/prx/libkernel/System/src/Process.cpp, core/libs/tests/GuestSysarch.cpp, docs/dev/debt/changes/fix-libkernel-sysarch-ldt-ioperm-gsbase.md
sysarch routes operations 11 and 132 to ExtendedFpuState. The handler checks lengths and addresses, accepts zero-length inputs, and leaves nonzero state copying unimplemented. Tests cover invalid lengths, null and inaccessible buffers, and zero-length inputs. The documentation describes the operation lengths and errors.

Suggested reviewers: fogydes, boykopovar, felipebmaitan

Change: Bug fix

Merge Risk: Minimal · up to 3d354

This change makes the XFPUSTATE sysarch operations return proper errors for invalid inputs and succeed for empty requests. Copying the live state remains unimplemented and is documented as such. No merge-blocking risk was found.

Security architecture risk: Minimal · up to 3d354

libkernel now returns errors for some XFPUSTATE requests that previously threw, and accepts zero-length requests without copying any state. The new code reads a fixed-size argument block but does not write to the supplied destination or expose live FPU state.

Security review details

Security Blast Radius

  • observed — The changed production dispatch is limited to guest calls to sysarch operations 11 and 132. It adds a bounded read in the emulator process, not an FPU-state read, a destination write, or new caller privileges.

Trust Boundaries and Controls

  • observed — The new read uses the existing GuestArena host-read preparation hook before the copy. On Windows the helper can fall back to a current-process read even when the guest-owned fast path does not succeed, so successful copy-in alone does not establish guest ownership.

Rollout and rollback

  • inferred — The reviewed code makes the decision inside sysarch without a new operator control. Reverting the change restores the merge-base dispatch; the new handler creates no XFPUSTATE output or persistent state that an operator must remove.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 3
  • Waived: $0.75 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68c8f5a0-4b10-431a-8fb6-fd6373f0ed73
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 3d354f3.

Files selected for processing: 3

  • core/libs/prx/libkernel/System/src/Process.cpp
  • core/libs/tests/GuestSysarch.cpp
  • docs/dev/debt/changes/fix-libkernel-sysarch-ldt-ioperm-gsbase.md

Limit details: You’ve used all 10 included reviews currently available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants