fix(libSceNet): socket option calls report unknown options, levels and short buffers like a PS5 #18108

Open
kali113 wants to merge 10 commits from upstream-pr/18108 into main
kali113 commented 2026-11-10 13:02:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kali113 on 2026-11-10T13:02:33Z.


What

sceNetGetsockopt and sceNetSetsockopt answered argument errors differently from a PS5. Measured on a PS5 (firmware 13.590.001, payload process) by running one case list on the console and against this library, then diffing; about 400 of the differing cases come down to the rules below.

Case PS5 Before
get, buffer shorter than the option copies that many bytes, returns the count (0 to 3 too) EINVAL
get, null value success, length set to 0 EINVAL
get, null or unreadable length EFAULT, before the descriptor is checked EINVAL
get, unwritable value EFAULT, length untouched host crash
get or set, length 0x80000000 or more EINVAL accepted
set, null value with a non-zero length EFAULT, before the descriptor is checked EINVAL
set, unreadable value on an integer option EFAULT host crash
socket-level option the console does not have ENOPROTOOPT, whatever the length EOPNOTSUPP (EINVAL when short)
unknown TCP option with a short buffer ENOPROTOOPT EINVAL
level the socket's protocol does not have (1, 17 on TCP, 0x7fff, IPPROTO_IP on an IPv6 socket) EINVAL EOPNOTSUPP
IPPROTO_UDP on a datagram socket ENOPROTOOPT EOPNOTSUPP

Per-option results that do not follow the general rule are encoded as measured: 0x1000 is EINVAL both ways, 0x1009 EOPNOTSUPP both ways, 0x1010 EOPNOTSUPP on get and ENOPROTOOPT on set, 0x1014 ENOPROTOOPT on get and EINVAL on set; 0x2, 0x1007, 0x1008, 0x1016, 0x1011 to 0x1013 and 0x1107 can be read but not set; 0x4000, 0x8000 and 0x1202 can be set but not read.

Not changed, and recorded in the debt entry:

  • Options the console accepts but this library does not model still fail with EOPNOTSUPP, as do all IPPROTO_IP options on an IPv4 socket.
  • ENOPROTOOPT for option numbers outside the scanned ranges (single bits up to 0x20000, 0x1001-0x1020, 0x1100-0x1110, 0x1200-0x1210) is extrapolated from those ranges.
  • Readback values of SO_NBIO and 0x10000 (the console returns flag bits).
  • A non-null unreadable SO_RCVTIMEO/SO_SNDTIMEO structure passed to set is still read without a checked copy.
  • libkernel's getsockopt still accepts a length of 0x80000000 or more; the console returns EINVAL there too (measured). Ipv6Only.cpp keeps asserting the old result for the libkernel half.

Existing tests that asserted the old codes are updated to the measured ones. #5836 adds support for setting 0x20000 in the same function; the two changes do not contradict each other, and whichever lands second needs a small rebase.

Tested

Linux x86-64 container on an Apple Silicon host: the new guest_net_sockopt_errors plus every guest_net*, guest_sce_net*, net_*, guest_inet*, guest_socket* and guest_http2* test, 90 of 90 pass. No other targets were run locally. Windows and macOS not run.

Console side: PS5, firmware 13.590.001, payload process (ps5-payload-sdk v0.45), loopback sockets only. A payload may have privileges a title does not; nothing here depends on that. Probe sources and raw output are in the first comment.

Follow-up: 0258d2cfe2 makes GuestWritable keep the caller's errno, because its Linux mapping lookup could leave a host error in the guest's errno. 5846fad360 removes debt sentences about null pointers that the measured rules replace. Syntax-checked only; not run.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5241733641 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18108). Originally posted by [kali113](https://github.com/kali113) on 2026-11-10T13:02:33Z. --- ### What `sceNetGetsockopt` and `sceNetSetsockopt` answered argument errors differently from a PS5. Measured on a PS5 (firmware 13.590.001, payload process) by running one case list on the console and against this library, then diffing; about 400 of the differing cases come down to the rules below. | Case | PS5 | Before | | --- | --- | --- | | get, buffer shorter than the option | copies that many bytes, returns the count (0 to 3 too) | `EINVAL` | | get, null value | success, length set to 0 | `EINVAL` | | get, null or unreadable length | `EFAULT`, before the descriptor is checked | `EINVAL` | | get, unwritable value | `EFAULT`, length untouched | host crash | | get or set, length `0x80000000` or more | `EINVAL` | accepted | | set, null value with a non-zero length | `EFAULT`, before the descriptor is checked | `EINVAL` | | set, unreadable value on an integer option | `EFAULT` | host crash | | socket-level option the console does not have | `ENOPROTOOPT`, whatever the length | `EOPNOTSUPP` (`EINVAL` when short) | | unknown TCP option with a short buffer | `ENOPROTOOPT` | `EINVAL` | | level the socket's protocol does not have (1, 17 on TCP, `0x7fff`, `IPPROTO_IP` on an IPv6 socket) | `EINVAL` | `EOPNOTSUPP` | | `IPPROTO_UDP` on a datagram socket | `ENOPROTOOPT` | `EOPNOTSUPP` | Per-option results that do not follow the general rule are encoded as measured: `0x1000` is `EINVAL` both ways, `0x1009` `EOPNOTSUPP` both ways, `0x1010` `EOPNOTSUPP` on get and `ENOPROTOOPT` on set, `0x1014` `ENOPROTOOPT` on get and `EINVAL` on set; `0x2`, `0x1007`, `0x1008`, `0x1016`, `0x1011` to `0x1013` and `0x1107` can be read but not set; `0x4000`, `0x8000` and `0x1202` can be set but not read. Not changed, and recorded in the debt entry: - Options the console accepts but this library does not model still fail with `EOPNOTSUPP`, as do all `IPPROTO_IP` options on an IPv4 socket. - `ENOPROTOOPT` for option numbers outside the scanned ranges (single bits up to `0x20000`, `0x1001`-`0x1020`, `0x1100`-`0x1110`, `0x1200`-`0x1210`) is extrapolated from those ranges. - Readback values of `SO_NBIO` and `0x10000` (the console returns flag bits). - A non-null unreadable `SO_RCVTIMEO`/`SO_SNDTIMEO` structure passed to set is still read without a checked copy. - libkernel's `getsockopt` still accepts a length of `0x80000000` or more; the console returns `EINVAL` there too (measured). `Ipv6Only.cpp` keeps asserting the old result for the libkernel half. Existing tests that asserted the old codes are updated to the measured ones. #5836 adds support for setting `0x20000` in the same function; the two changes do not contradict each other, and whichever lands second needs a small rebase. ### Tested Linux x86-64 container on an Apple Silicon host: the new `guest_net_sockopt_errors` plus every `guest_net*`, `guest_sce_net*`, `net_*`, `guest_inet*`, `guest_socket*` and `guest_http2*` test, 90 of 90 pass. No other targets were run locally. Windows and macOS not run. Console side: PS5, firmware 13.590.001, payload process (ps5-payload-sdk v0.45), loopback sockets only. A payload may have privileges a title does not; nothing here depends on that. Probe sources and raw output are in the first comment. Follow-up: 0258d2cfe2 makes `GuestWritable` keep the caller's errno, because its Linux mapping lookup could leave a host error in the guest's errno. 5846fad360 removes debt sentences about null pointers that the measured rules replace. Syntax-checked only; not run. ### Checklist - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
copilot-pull-request-reviewer[bot] commented 2026-11-10 13:02:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-10T13:02:44Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5842245203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18108#pullrequestreview-5842245203). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-10T13:02:44Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MarcZX10 commented 2026-11-21 04:46:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:46:19Z.

Review: COMMENTED


Reviewed — no blocking findings

The changed code and tests support the reported socket option behavior; I could not run checks in this review environment, so a formal approval is not justified.

What I ran

Reviewed head 2355a297891cb8ac3af0ffe9cfe3a75bae51780d. No commands or tests were run; the available tools provided read-only review access.

Results

Check Result Note
Diff and changed code passed Reviewed all 17 changed files
Tests not run No command execution available

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests were not run. Windows, macOS, and physical-console behavior were not independently verified; the platform and console results in the description are author-reported. The new sockopt error test was reviewed in the diff.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002905020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18108#pullrequestreview-6002905020). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T04:46:19Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The changed code and tests support the reported socket option behavior; I could not run checks in this review environment, so a formal approval is not justified. ## What I ran Reviewed head `2355a297891cb8ac3af0ffe9cfe3a75bae51780d`. No commands or tests were run; the available tools provided read-only review access. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Reviewed all 17 changed files | | Tests | not run | No command execution available | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Tests were not run. Windows, macOS, and physical-console behavior were not independently verified; the platform and console results in the description are author-reported. The new sockopt error test was reviewed in the diff. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 17:03:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:03:17Z.

Review: COMMENTED


NET_SO_ERROR reads and clears the host socket's pending error before store checks whether it can write the guest outputs. If the output buffer is unwritable, the guest gets EFAULT and a subsequent valid call can lose the pending error. Please check the output ranges before consuming the host error, or document and test the behavior if the console deliberately consumes it on failure.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6174524973 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18108#pullrequestreview-6174524973). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T17:03:17Z. **Review:** COMMENTED --- `NET_SO_ERROR` reads and clears the host socket's pending error before `store` checks whether it can write the guest outputs. If the output buffer is unwritable, the guest gets `EFAULT` and a subsequent valid call can lose the pending error. Please check the output ranges before consuming the host error, or document and test the behavior if the console deliberately consumes it on failure. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/18108:upstream-pr/18108'
git switch 'upstream-pr/18108'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/18108'
git switch 'upstream-pr/18108'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/18108'
git switch 'upstream-pr/18108'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/18108'
git switch 'main'
git merge --squash 'upstream-pr/18108'
git switch 'main'
git merge --ff-only 'upstream-pr/18108'
git switch 'main'
git merge 'upstream-pr/18108'
git push origin 'main'
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!18108
No description provided.