fix(libSceNet): follow FreeBSD 11.4's sys_ioctl for unhandled sceNetIoctl requests #22992

Merged
brajankw merged 1 commit from upstream-pr/22992 into main 2026-11-18 19:28:12 +00:00
brajankw commented 2026-11-18 16:15:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-18T16:15:02Z.


What

sceNetIoctl on a sceNetSocket socket failed with ENOTTY for every request other than FIONBIO and FIONREAD. This PR assumes, without a console measurement, that a sceNetSocket socket is a kernel socket and that sceNetIoctl is the ioctl system call on it. On that assumption, it now answers those requests the way FreeBSD 11.4's sys_ioctl and soo_ioctl do.

  • A malformed request fails with ENOTTY. That is no direction bit, an input or output request of length 0, or an IOC_VOID request whose length is neither 0 nor 4. libkernel's IoctlRequestMalformed applies the same rule, and the console gave ENOTTY for 0x8000667f. The rule is copied into libSceNet/Export.cpp, since that function is internal to libkernel.
  • An IOC_IN argument, other than an IOC_VOID one, is copied in next, so an unreadable one fails with EFAULT. libkernel's ioctl on a guest socket does not copy one in yet, so there an unreadable non-null argument for an unknown request still gives EADDRNOTAVAIL.
  • These still fail with ENOTTY, though kern_ioctl or soo_ioctl answers them: FIOCLEX, FIONCLEX, FIOASYNC, FIOSETOWN, FIOGETOWN, FIONWRITE, FIONSPACE, SIOCATMARK, SIOCSPGRP and SIOCGPGRP. On AF_INET6, so do the u requests 106 to 109, which in6_control handles before its interface check. They are matched by group and number only, which is broader than FreeBSD's exact match. Nothing shows the console's answer for them, so they keep the error a title already handles; the debt entry lists them.
  • i, r and f requests fail with ENOTTY, as in libkernel. FreeBSD sends i and r to ifioctl and rtioctl_fib. It has no special case for f; ENOTTY there is libkernel's choice in the absence of a measurement.
  • Any other request fails with EADDRNOTAVAIL on AF_INET, as in_control does with no interface. libkernel's ioctl gives the same, measured with TIOCGWINSZ on a libkernel AF_INET socket (#11219). On AF_INET6, it fails with EOPNOTSUPP, as in6_control does and libkernel's tcgetattr path already answers (File/src/Terminal.cpp). libkernel's ioctl still gives EADDRNOTAVAIL on AF_INET6; that is for a separate PR.

FIONBIO and FIONREAD, and libkernel's own sockets reached through sceNetIoctl, are unchanged. A bad socket id still fails with EBADF before the malformed-request check.

  • Tests: GuestSceNet.cpp CheckIoctl.
    • On a UDP AF_INET sceNetSocket socket, TIOCGWINSZ, _IOW('x', 1, int), _IOWR('x', 1, int) and the IOC_VOID 0x20047801 fail with EADDRNOTAVAIL and leave the argument unchanged. TIOCGWINSZ and 0x20047801 also do so with a null argument.
    • An unreadable IOC_IN argument fails with EFAULT, including for SIOCSPGRP.
    • Four malformed requests fail with ENOTTY, one of them with an unreadable argument, which shows that ENOTTY comes before EFAULT.
    • All ten requests that kern_ioctl or soo_ioctl answers fail with ENOTTY without touching the argument.
    • FIODTYPE, an f request, fails with ENOTTY, and SIOCAADDRCTL_POLICY fails with EADDRNOTAVAIL on AF_INET.
    • libkernel's ioctl on the socket gives EADDRNOTAVAIL for TIOCGWINSZ.
    • On an AF_INET6 socket, three requests fail with EOPNOTSUPP, and SIOCAADDRCTL_POLICY fails with ENOTTY.
    • The two existing checks of 123 (ENOTTY) still hold.
  • Debt fragment: the sceNetIoctl entry drops "other requests fail with ENOTTY, as in libkernel's ioctl". A new entry leads with the assumption and lists these rules, including the AF_INET6 difference from libkernel.

Tested

Linux (Debian 13, GCC 14.2.0, Release). This branch was first tested on main 68f3159e41, with the change as the single commit on it. After review, the ten requests and u 106 to 109 went back to ENOTTY, and the branch was rebased onto 6286d36449; the 50 focused tests below pass there.

  • Negative control: without the change, guest_sce_net aborts at the first new check, with ENOTTY. With the version that threw, it aborts on FIOCLEX.
  • ctest over 36 socket, fcntl, poll and libSceNet test executables (50 tests): 49 passed; guest_socket_options_multicast skips without a network.
  • On 6286d36449, guest_sce_net needs a standard input that is not a pipe. Since #19824, its select check on descriptors 0 to 2 fails with EBADF when standard input is a pipe, on main too. These runs use /dev/null.
  • Full ctest (6138 tests, -j 12) on the first version of this branch: 6122 passed. Of the 16 failures:
    • nine need a .git directory, network access or a passwd entry for the user: conventions_git_errors, test_script_registration, web_library_assets, title_run, title_run_identity, guest_kernel_sys_login, guest_net_ctl, guest_getlogin and guest_getlogin_no_session;
    • six are agc_driver GPU cases. These fifteen also fail on main in the same environment;
    • guest_wtf_data_log failed once under -j 12 and passed 5 of 5 runs on its own. Neither it nor the libraries it links (libSceNKWebKit, libSceJsc, libc) calls sceNetIoctl.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch failed closed on #5836, #12682, #12688, #12700 and #12965, which conflict with main. None of their diffs changes sceNetIoctl.
  • The branch merges cleanly with my open #22573, which also changes libSceNet/Export.cpp and GuestSceNet.cpp, and with #22395, which changes libkernel's ioctl.
  • Not tested on Windows or macOS. No title.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5379682128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22992). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-18T16:15:02Z. --- ### What `sceNetIoctl` on a `sceNetSocket` socket failed with `ENOTTY` for every request other than `FIONBIO` and `FIONREAD`. This PR assumes, without a console measurement, that a `sceNetSocket` socket is a kernel socket and that `sceNetIoctl` is the `ioctl` system call on it. On that assumption, it now answers those requests the way FreeBSD 11.4's [`sys_ioctl`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_generic.c#L709-L739) and [`soo_ioctl`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_socket.c#L242-L258) do. - A malformed request fails with `ENOTTY`. That is no direction bit, an input or output request of length 0, or an `IOC_VOID` request whose length is neither 0 nor 4. libkernel's `IoctlRequestMalformed` applies the same rule, and the console gave `ENOTTY` for `0x8000667f`. The rule is copied into `libSceNet/Export.cpp`, since that function is internal to libkernel. - An `IOC_IN` argument, other than an `IOC_VOID` one, is copied in next, so an unreadable one fails with `EFAULT`. libkernel's `ioctl` on a guest socket does not copy one in yet, so there an unreadable non-null argument for an unknown request still gives `EADDRNOTAVAIL`. - These still fail with `ENOTTY`, though `kern_ioctl` or `soo_ioctl` answers them: `FIOCLEX`, `FIONCLEX`, `FIOASYNC`, `FIOSETOWN`, `FIOGETOWN`, `FIONWRITE`, `FIONSPACE`, `SIOCATMARK`, `SIOCSPGRP` and `SIOCGPGRP`. On `AF_INET6`, so do the `u` requests 106 to 109, which [`in6_control`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/netinet6/in6.c#L244-L270) handles before its interface check. They are matched by group and number only, which is broader than FreeBSD's exact match. Nothing shows the console's answer for them, so they keep the error a title already handles; the debt entry lists them. - `i`, `r` and `f` requests fail with `ENOTTY`, as in libkernel. FreeBSD sends `i` and `r` to `ifioctl` and `rtioctl_fib`. It has no special case for `f`; `ENOTTY` there is libkernel's choice in the absence of a measurement. - Any other request fails with `EADDRNOTAVAIL` on `AF_INET`, as [`in_control`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/netinet/in.c#L233-L234) does with no interface. libkernel's `ioctl` gives the same, measured with `TIOCGWINSZ` on a libkernel `AF_INET` socket (#11219). On `AF_INET6`, it fails with `EOPNOTSUPP`, as `in6_control` does and libkernel's `tcgetattr` path already answers (`File/src/Terminal.cpp`). libkernel's `ioctl` still gives `EADDRNOTAVAIL` on `AF_INET6`; that is for a separate PR. `FIONBIO` and `FIONREAD`, and libkernel's own sockets reached through `sceNetIoctl`, are unchanged. A bad socket id still fails with `EBADF` before the malformed-request check. - Tests: `GuestSceNet.cpp` `CheckIoctl`. - On a UDP `AF_INET` `sceNetSocket` socket, `TIOCGWINSZ`, `_IOW('x', 1, int)`, `_IOWR('x', 1, int)` and the `IOC_VOID` `0x20047801` fail with `EADDRNOTAVAIL` and leave the argument unchanged. `TIOCGWINSZ` and `0x20047801` also do so with a null argument. - An unreadable `IOC_IN` argument fails with `EFAULT`, including for `SIOCSPGRP`. - Four malformed requests fail with `ENOTTY`, one of them with an unreadable argument, which shows that `ENOTTY` comes before `EFAULT`. - All ten requests that `kern_ioctl` or `soo_ioctl` answers fail with `ENOTTY` without touching the argument. - `FIODTYPE`, an `f` request, fails with `ENOTTY`, and `SIOCAADDRCTL_POLICY` fails with `EADDRNOTAVAIL` on `AF_INET`. - libkernel's `ioctl` on the socket gives `EADDRNOTAVAIL` for `TIOCGWINSZ`. - On an `AF_INET6` socket, three requests fail with `EOPNOTSUPP`, and `SIOCAADDRCTL_POLICY` fails with `ENOTTY`. - The two existing checks of `123` (`ENOTTY`) still hold. - Debt fragment: the `sceNetIoctl` entry drops "other requests fail with `ENOTTY`, as in libkernel's `ioctl`". A new entry leads with the assumption and lists these rules, including the `AF_INET6` difference from libkernel. ### 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. --> Linux (Debian 13, GCC 14.2.0, Release). This branch was first tested on `main` `68f3159e41`, with the change as the single commit on it. After review, the ten requests and `u` 106 to 109 went back to `ENOTTY`, and the branch was rebased onto `6286d36449`; the 50 focused tests below pass there. - Negative control: without the change, `guest_sce_net` aborts at the first new check, with `ENOTTY`. With the version that threw, it aborts on `FIOCLEX`. - `ctest` over 36 socket, `fcntl`, `poll` and libSceNet test executables (50 tests): 49 passed; `guest_socket_options_multicast` skips without a network. - On `6286d36449`, `guest_sce_net` needs a standard input that is not a pipe. Since #19824, its `select` check on descriptors 0 to 2 fails with `EBADF` when standard input is a pipe, on `main` too. These runs use `/dev/null`. - Full `ctest` (6138 tests, `-j 12`) on the first version of this branch: 6122 passed. Of the 16 failures: - nine need a `.git` directory, network access or a passwd entry for the user: `conventions_git_errors`, `test_script_registration`, `web_library_assets`, `title_run`, `title_run_identity`, `guest_kernel_sys_login`, `guest_net_ctl`, `guest_getlogin` and `guest_getlogin_no_session`; - six are `agc_driver` GPU cases. These fifteen also fail on `main` in the same environment; - `guest_wtf_data_log` failed once under `-j 12` and passed 5 of 5 runs on its own. Neither it nor the libraries it links (libSceNKWebKit, libSceJsc, libc) calls `sceNetIoctl`. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch` failed closed on #5836, #12682, #12688, #12700 and #12965, which conflict with `main`. None of their diffs changes `sceNetIoctl`. - The branch merges cleanly with my open #22573, which also changes `libSceNet/Export.cpp` and `GuestSceNet.cpp`, and with #22395, which changes libkernel's `ioctl`. - Not tested on Windows or macOS. No title. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
PrivacyOnion commented 2026-11-18 16:17:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T16:17:34Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against a5d48dbc39:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_sce_net_tests built cleanly.
  • CTest (guest_sce_net, guest_net_inet_pton_source_faults):
    1/2 Test #4701: guest_net_inet_pton_source_faults ...   Passed    0.01 sec
    2/2 Test #4700: guest_sce_net .......................   Passed    1.68 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceNet/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #4701: guest_net_inet_pton_source_faults ...   Passed    0.01 sec
    2/2 Test #4700: guest_sce_net .......................Subprocess aborted***Exception:   1.10 sec
    50% tests passed, 1 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Validated sceNetIoctl command decoding: IOC_IN/OUT/VOID direction bit masks, parameter length decoding ((cmd >> 16) & 0x1fff), and malformed command handling matching FreeBSD 11.4 sys_ioctl
    • Verified guest memory safety: checked GuestCopyIn_nid_no_patch call for IOC_IN requests correctly returning NET_EFAULT (14) on invalid/unmapped guest buffer pointers
    • Checked concurrency and thread-safety: g_mutex locking correctly retrieves native handle and socket family before releasing lock, avoiding data races
    • Verified FreeBSD 11.4 socket ioctl behavior across AF_INET (EADDRNOTAVAIL) and AF_INET6 (EOPNOTSUPP, unhandled in6_control range 106-109 throwing runtime_error) and answeredRequests throwing runtime_error
    • Confirmed test suite coverage in GuestSceNet.cpp for malformed commands, null/faulting buffers, unimplemented FreeBSD socket ioctl throws, and IPv4 vs IPv6 error codes
    • Verified strict AGENTS.md compliance: no forbidden comments, debt fragment added under docs/dev/debt/changes/, and Conventional Commit / PR format followed

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5960597373 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22992#pullrequestreview-5960597373). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-18T16:17:34Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `a5d48dbc39`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_sce_net_tests` built cleanly. - **CTest** (`guest_sce_net`, `guest_net_inet_pton_source_faults`): ``` 1/2 Test #4701: guest_net_inet_pton_source_faults ... Passed 0.01 sec 2/2 Test #4700: guest_sce_net ....................... Passed 1.68 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceNet/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #4701: guest_net_inet_pton_source_faults ... Passed 0.01 sec 2/2 Test #4700: guest_sce_net .......................Subprocess aborted***Exception: 1.10 sec 50% tests passed, 1 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - Validated sceNetIoctl command decoding: IOC_IN/OUT/VOID direction bit masks, parameter length decoding ((cmd >> 16) & 0x1fff), and malformed command handling matching FreeBSD 11.4 sys_ioctl - Verified guest memory safety: checked GuestCopyIn_nid_no_patch call for IOC_IN requests correctly returning NET_EFAULT (14) on invalid/unmapped guest buffer pointers - Checked concurrency and thread-safety: g_mutex locking correctly retrieves native handle and socket family before releasing lock, avoiding data races - Verified FreeBSD 11.4 socket ioctl behavior across AF_INET (EADDRNOTAVAIL) and AF_INET6 (EOPNOTSUPP, unhandled in6_control range 106-109 throwing runtime_error) and answeredRequests throwing runtime_error - Confirmed test suite coverage in GuestSceNet.cpp for malformed commands, null/faulting buffers, unimplemented FreeBSD socket ioctl throws, and IPv4 vs IPv6 error codes - Verified strict AGENTS.md compliance: no forbidden comments, debt fragment added under docs/dev/debt/changes/, and Conventional Commit / PR format followed Looks Good To Me
MarcZX10 commented 2026-11-18 16:34:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T16:34:37Z.

Review: APPROVED


Reviewed — looks good

Nothing in the inspected changes shows a concrete defect; the review is limited to the three changed files listed below, and no checks were run.

What I ran

Exact head: a5d48dbc3951933fb37505603b12845d65bec0d9. No commands or tests were run. Read the prepared description, commits, manifest, and diff, then read all three changed files through repo_read.py at the pinned head. The author reports test runs in the PR description; they were not run by this review.

Results

Check Result Note
Changed files read passed 3 of 3 reviewed
Tests and build not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests or builds were run. Windows, macOS, and console behavior were not verified. No changed files were excluded; all three changed files were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5960888387 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22992#pullrequestreview-5960888387). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T16:34:37Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the inspected changes shows a concrete defect; the review is limited to the three changed files listed below, and no checks were run. ## What I ran Exact head: `a5d48dbc3951933fb37505603b12845d65bec0d9`. No commands or tests were run. Read the prepared description, commits, manifest, and diff, then read all three changed files through `repo_read.py` at the pinned head. The author reports test runs in the PR description; they were not run by this review. ## Results | Check | Result | Note | |---|---|---| | Changed files read | passed | 3 of 3 reviewed | | Tests and build | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests or builds were run. Windows, macOS, and console behavior were not verified. No changed files were excluded; all three changed files were read. ## To get this to a good state Nothing is required.
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!22992
No description provided.