Skip to content

fix(libkernel): fail an unhandled ioctl on a local or AF_INET6 socket with EOPNOTSUPP, as tcgetattr and FreeBSD 11.4's pru_control do - #28285

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
mnoori11:fix/libkernel-socket-ioctl-eopnotsupp
Dec 5, 2026

Conversation

@mnoori11

@mnoori11 mnoori11 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

What

On a guest socket, ioctl with a request it does not handle and whose group is not i, r or f failed with ENOTTY on a local socket and EADDRNOTAVAIL on an AF_INET6 socket (Udp.cpp:2672-2675). It now fails with EOPNOTSUPP on both, and AF_INET keeps EADDRNOTAVAIL. That is the mapping TerminalError already gives tcgetattr and the other tc* calls. Every result this PR changes becomes what FreeBSD 11.4 gives, and every request FreeBSD answers some other way keeps today's result.

Who can reach it:

  • tcsetsid (Export.cpp:1385-1387) issues TIOCSCTTY through this ioctl, so on a local socket it now gives EOPNOTSUPP like the other tc* calls.

  • sceNetIoctl on a libkernel socket forwards to this ioctl (libSceNet/Export.cpp:3886-3887). Such a call now gets 45 instead of 49 on AF_INET6 and 45 instead of 25 on a local socket, which is what fix(libSceNet): follow FreeBSD 11.4's sys_ioctl for unhandled sceNetIoctl requests #22992 gives on libSceNet's own AF_INET6 sockets. They still differ in SIOCATMARK, SIOCSPGRP and SIOCGPGRP (49 here on AF_INET and AF_INET6, 25 there on every family) and in u 106 to 109 on AF_INET6 (49 here, 25 there).

  • The debt entry records that Stremio Plus (PPSA74126) imports _ioctl for its tc* functions; whether it calls them on a local socket is not known.

  • Tests: guest_kernel_fcntl. On a local pair, TIOCGWINSZ, the void 0x20047801 and u 106 to 109 fail with EOPNOTSUPP, and so does tcgetattr on the same descriptor; FIONREAD still succeeds, SIOCGIFFLAGS still gives ENOTTY, and the three s requests give ENOTTY. On an AF_INET6 socket the first two give EOPNOTSUPP, and the three s requests and u 106 to 109 give EADDRNOTAVAIL. guest_kernel_sys: tcsetsid on a local pair gives EOPNOTSUPP. The AF_INET checks are unchanged.

  • Debt: the libkernel ioctl, _ioctl entry is already changed by the pending fragment fix-libkernel-ioctl-pipe-unknown-request-enotty.md, and only one fragment may change an entry, so this edits its socket sentence in place; the last clause of the libSceNet entry in fix-libSceNet-ioctl-inet-unknown-request.md (fix(libSceNet): follow FreeBSD 11.4's sys_ioctl for unhandled sceNetIoctl requests #22992), "libkernel's ioctl gives EADDRNOTAVAIL there", is no longer true and is removed the same way (what libkernel's ioctl gives is in its own entry). A new fragment corrects the errors the tcsetsid entry in libkernel_sys lists.

  • Neighbours: test(libkernel): audit socket ioctls FIONREAD, FIONBIO, SIOCGIFCONF, and FreeBSD error mapping #21020 (open, test only) expects ENOTTY for SIOCGIFCONF, an i request, on a unix pair, which is unchanged. fix(libkernel): fail sockatmark on a descriptor that is not a socket with ENOTTY, as FreeBSD 11.4 does #28202 changes sockatmark, not this code.

Tested

Linux (WSL2 Ubuntu 24.04, kernel 6.6.87.2), GCC 13.3, x86-64.

  • main d42e183ca3: a probe linked against main's libraries makes every call the new tests make. It gets 25 on the local pair and 49 on AF_INET6 wherever the tests expect a changed result, and the pinned value for every unchanged one. With the first version of the new tests (before the u 106 to 109 cases), guest_kernel_sys fails at line 106 (tcsetsid on the local pair, errno 25), and guest_kernel_fcntl aborts.
  • This PR: guest_kernel_fcntl, guest_kernel_sys, guest_sce_net, guest_socket_pair and guest_terminal pass, and the probe gets the expected value for every call.
  • Full ctest, on this branch before u 106 to 109 were kept: 7117 of 7312 pass. Each of the 195 failures is on this machine's list of tests that also fail on main here (mostly agc_* GPU tests on llvmpipe; the 6.6 WSL kernel has no write watch).
  • python3 tools/check_conventions.py --base origin/main passes with two debt-length warnings: the libkernel ioctl entry (1336 characters, 1221 on main) and the libkernel_sys entry (1033, 1000 on main). python3 tools/debt_fold.py --check passes.
  • Not run 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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected error responses for unsupported socket control requests, with results now varying according to the socket type and request.
    • Improved error handling for control operations on local and IPv6 sockets, including terminal and interface-related requests. This helps applications receive more consistent compatibility behavior when using unsupported or unavailable socket operations.

… with EOPNOTSUPP, as tcgetattr and FreeBSD 11.4's pru_control do

A request that FreeBSD's soo_ioctl hands to pru_control gave ENOTTY on a
local socket and EADDRNOTAVAIL on an AF_INET6 socket. tcgetattr, which is
the same ioctl on the console, was measured to give EOPNOTSUPP on a local
socket pair (firmware 11.60), and the tc* exports already answer that.
AF_INET keeps EADDRNOTAVAIL and groups i, r and f keep ENOTTY. The
requests FreeBSD answers before that point keep their results:
SIOCATMARK, SIOCSPGRP and SIOCGPGRP, and on AF_INET6 group u 106 to 109.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_fcntl_tests, guest_kernel_sys_tests built cleanly.
  • CTest (guest_kernel_sys, guest_kernel_fcntl):
    1/2 Test #6830: guest_kernel_fcntl ...............   Passed    0.01 sec
    2/2 Test #1050: guest_kernel_sys .................   Passed    0.07 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #6830: guest_kernel_fcntl ...............Subprocess aborted***Exception:   0.14 sec
    2/2 Test #1050: guest_kernel_sys .................Subprocess aborted***Exception:   0.20 sec
    0% tests passed, 2 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified ioctl_nid_postfix command variable usage in Udp.cpp:2679: command is in scope from line 2650 (const auto command = static_caststd::uint32_t(request)) and accurately reflects request's lower 32 bits
    • Verified AnsweredBeforeInterfaceCheck covers socket-level ioctls (0x40047307, 0x80047308, 0x40047309: SIOCATMARK, SIOCSPGRP, SIOCGPGRP) and AF_INET6-specific control requests (0xc050756a - 0x8048756d) before rejecting with EADDRNOTAVAIL or ENOTTY
    • Verified error code returns: ENOTTY (25) for groups 'i', 'r', 'f', EADDRNOTAVAIL (49) for AF_INET/handled commands, and EOPNOTSUPP (45) for unhandled protocol requests on local/AF_INET6 sockets per FreeBSD 11.4 behavior
    • Verified AGENTS.md debt fragments: docs/dev/debt/changes/ entries are correctly formatted and accurately record the error code changes without comments in code
    • Verified test coverage in GuestKernelFcntl.cpp and GuestKernelSys.cpp properly verifies tcgetattr, tcsetsid, interface flags, socket state, and protocol control requests across local and IPv6 socket descriptors

Looks Good To Me

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Socket ioctl behavior

Layer / File(s) Summary
Classify ioctl errors
core/libs/prx/libkernel/Socket/src/Udp.cpp, docs/dev/debt/changes/fix-libSceNet-ioctl-inet-unknown-request.md, docs/dev/debt/changes/fix-libkernel-ioctl-pipe-unknown-request-enotty.md
The handler classifies selected requests and returns errors based on request group and socket family. The documentation describes the updated outcomes.
Test socket and terminal ioctl behavior
core/libs/tests/GuestKernelFcntl.cpp, core/libs/tests/GuestKernelSys.cpp, docs/dev/debt/changes/fix-libkernel-socket-ioctl-eopnotsupp.md
Tests check ioctl results for local socket pairs and IPv6 sockets, and check that tcsetsid fails on a local socket. The documentation describes tcsetsid, scePthreadMutexIsowned, and utrace behavior.

Suggested labels: libkernel, docs

Suggested reviewers: orezraey, brajankw, marczx10

Change: Bug fix

Merge Risk: Minimal · up to 8f9c4

This change makes unsupported socket ioctl requests return FreeBSD-like errors on local and IPv6 sockets, with tests and documentation. No actionable merge-blocking risk was found.

Security architecture risk: Minimal · up to 8f9c4

Some unsupported requests now return a different error on local and IPv6 sockets. They still fail, and the change does not grant access to any new operation.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The changed behavior is limited to the failure returned on an existing guest socket descriptor. The changed branch does not reach host socket operations, write output to guest memory, or modify socket state.

Trust Boundaries and Controls

  • observed — Malformed-request handling, guest input copying, and descriptor lookup still precede the fallback. The alternate file and native-socket dispatch for descriptors not open in the guest socket registry is unchanged.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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: a3cd97fa-8a68-409d-958e-f25fc2a5dcbc
Commits

Reviewing files that changed from the base of the PR and between 1f27e2a and 8f9c4ba.

Files selected for processing: 6

  • core/libs/prx/libkernel/Socket/src/Udp.cpp
  • core/libs/tests/GuestKernelFcntl.cpp
  • core/libs/tests/GuestKernelSys.cpp
  • docs/dev/debt/changes/fix-libSceNet-ioctl-inet-unknown-request.md
  • docs/dev/debt/changes/fix-libkernel-ioctl-pipe-unknown-request-enotty.md
  • docs/dev/debt/changes/fix-libkernel-socket-ioctl-eopnotsupp.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The reviewed change at 8f9c4ba64cbb9a45e6f631c9aad0c46f460270e3 has no verified blocking defects; the author-reported checks are not runs performed in this review.

What I ran

No commands or tests were run. I read the prepared diff and manifest, all changed lines in the six changed files, the relevant ioctl validation helper, and the review README. The review bundle excludes no changed files; no full repository files were listed as excluded.

Results

Check Result Note
Diff and changed lines passed All changed lines read
Targeted source context passed Validation and test context read
Tests not run Only author-reported results available
Console behavior not run AF_INET6 behavior is inferred

Findings

Blocking

None.

Non-blocking

None.

Not verified

No build or tests were run. Windows, macOS, and console behavior were not independently verified. The description reports Linux WSL2 checks, including the focused tests and a broader ctest run; those results were not reproduced here. The changed files read were core/libs/prx/libkernel/Socket/src/Udp.cpp, core/libs/tests/GuestKernelFcntl.cpp, core/libs/tests/GuestKernelSys.cpp, docs/dev/debt/changes/fix-libSceNet-ioctl-inet-unknown-request.md, docs/dev/debt/changes/fix-libkernel-ioctl-pipe-unknown-request-enotty.md, and docs/dev/debt/changes/fix-libkernel-socket-ioctl-eopnotsupp.md. No changed file was excluded.

To get this to a good state

Nothing is required.

@ycbuzi

ycbuzi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Tested 8f9c4ba64c merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 6 tests failed out of 7462; 99% tests passed, 2 tests failed out of 7462. 3 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 7462; 100% tests passed, 0 tests failed out of 7462. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 8605 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12682 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12688 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12700 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12965 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 16826 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 18190 core/libs/prx/libkernel/Socket/src/Udp.cpp

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran the focused Linux GuestKernelFcntl ioctl case at 8f9c4ba64c with actual local and IPv6 sockets. The unsupported protocol commands returned EOPNOTSUPP, the existing state and interface command exceptions retained their expected errors, and the readable-byte query still worked. The same fixture failed with the exact pre-change Udp.cpp.

AI-assisted: yes.

@Plyxen Plyxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the diff at 8f9c4ba64c. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at b97867d3ce6 together with other open PRs (so not an isolated build).

  • guest_kernel_sys and guest_kernel_fcntl: pass on both.
  • Control (same tree and tests, the changed files of those PRs put back to main's): both fail on both (guest_kernel_sys at line 106 on Linux with guest errno 25).

Not checked: a title.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit f625093 into boykopovar:main Dec 5, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants