Skip to content

fix(libSceNet): check the descriptor before how in sceNetShutdown, as libkernel's shutdown does - #28635

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Dr-Coconut:fix/libscenet-shutdown-descriptor-first
Dec 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Dr-Coconut:fix/libscenet-shutdown-descriptor-first

Conversation

@Dr-Coconut

@Dr-Coconut Dr-Coconut commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What

sceNetShutdown refused an invalid how with EINVAL before it looked the descriptor up, so a closed or unknown descriptor with a bad how got EINVAL. FreeBSD 11.4's kern_shutdown looks the descriptor up first (EBADF) and soshutdown then checks how; libkernel's shutdown does the same. The check now follows the lookup.

GuestNetSocketState.cpp checks that sceNetShutdown on a closed descriptor with how -1 and 3 fails with EBADF, next to its existing EINVAL checks on an open socket. The debt fragment adds an entry saying the order is not measured on a console.

Tested

Commit 50e5108 on main 4a7fd1c, Release, in a workflow on my fork: https://github.com/Dr-Coconut/AnyPS5/actions/runs/46832781536

  • Windows (GitHub-hosted windows-latest, image windows-2025-vs2026, WinLibs GCC 15.2.0 15.2.0posix-14.0.0-ucrt-r7) and Linux (GitHub-hosted ubuntu-latest, image ubuntu-26.04, GCC 15.2.0), with the change: guest_net_socket_state passes, and so do the eight guest_net_address_fault_* tests.
  • Both, with libSceNet's Export.cpp restored to main and the new case kept: guest_net_socket_state aborts (its Require prints no line); the controls pass.

Not run on macOS. No title tested. tools/check_conventions.py passes and tools/debt_fold.py --check accepts the fragment. tools/pr_overlap.py --branch reported no overlap among the open pull requests it could merge; it could not compare eight that conflict with main. Compared by hand: #12682, #12688, #12700 and #12965 rework blocking transfers and connects on Windows; #5836 adds peer-socket types; #16826 keeps close-on-exec in fcntl; #18108 changes socket options; #23975 adds a DNS override. None of them changes sceNetShutdown.

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
    • Invalid socket descriptors passed to sceNetShutdown now return a bad-descriptor error before invalid shutdown modes are checked.

… libkernel's shutdown does

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: Shutdown Error Precedence

Layer / File(s) Summary
Descriptor-first shutdown validation
core/libs/prx/libSceNet/Export.cpp, core/libs/tests/GuestNetSocketState.cpp, docs/dev/debt/changes/fix-libscenet-shutdown-descriptor-first.md
The implementation checks the descriptor before validating how. Tests assert that invalid how values on a closed socket return error 9. The change note documents this ordering.

Suggested reviewers: themannt, queuse, marczx10

Change: Bug fix

Merge Risk: Minimal · up to 50e51

This change makes sceNetShutdown report a bad descriptor before a bad shutdown mode, and valid descriptors with invalid modes still get the same error as before. Tests cover the closed-socket cases, and no merge-blocking risk was found.

Security architecture risk: Minimal · up to 50e51

sceNetShutdown now returns EBADF when both the descriptor and shutdown mode are invalid. An invalid mode still cannot shut down a socket, and calls with a valid mode behave as before.

Security review details

Security Blast Radius

  • inferred — The new error distinction is limited to membership in the existing libSceNet descriptor map. A valid-mode call already returned EBADF for an absent descriptor, and the PR does not broaden which sockets can reach host shutdown.

Trust Boundaries and Controls

  • observed — Both a matching guest descriptor and a valid mode remain prerequisites for host shutdown. Invalid modes return before the native call and before any shutdown flag or receive-state updates.

Resilience and Maintainability Implications

  • inferred — Under concurrent close, the invalid-mode path returns EBADF if removal wins the lookup, or briefly retains the looked-up native handle and returns EINVAL if lookup wins. It does not act on a replacement descriptor or leave shutdown work to recover.
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: c16b7e1a-4efa-4c37-a180-80426fae796b
Commits

Reviewing files that changed from the base of the PR and between fc294cb and 50e5108.

Files selected for processing: 3

  • core/libs/prx/libSceNet/Export.cpp
  • core/libs/tests/GuestNetSocketState.cpp
  • docs/dev/debt/changes/fix-libscenet-shutdown-descriptor-first.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 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 change checks the socket descriptor before validating how, and the added regression checks cover invalid modes on a closed descriptor.

What I ran

Reviewed head 50e5108ea912e2e7e13bc2836be97c5c83e8ec2c. I inspected the changed shutdown function, the socket state test, and the debt entry through repo_read.py; I did not run a build or tests.

python3 repo_read.py cat core/libs/prx/libSceNet/Export.cpp 2100 2170
env -u ANYPS5_READ_LOG python3 repo_read.py cat core/libs/tests/GuestNetSocketState.cpp 1 112
env -u ANYPS5_READ_LOG python3 repo_read.py search RequireError core/libs/tests/GuestNetSocketState.cpp

Results

Check Result Note
Changed code review passed All three listed files reviewed
Build and tests not run No independent execution
Author-reported checks not run Reported in the PR description

Negative control

The author reports that restoring the prior Export.cpp behavior while keeping the new test makes guest_net_socket_state abort. I did not run this control.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

I did not run tests, builds, or console checks, and did not independently verify the cited FreeBSD or libkernel behavior. The reviewed files were core/libs/prx/libSceNet/Export.cpp, core/libs/tests/GuestNetSocketState.cpp, and docs/dev/debt/changes/fix-libscenet-shutdown-descriptor-first.md; files.json lists no excluded files.

To get this to a good state

No changes are required; no commands need rerunning.

@github-actions

github-actions Bot commented Dec 2, 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 5836 core/libs/prx/libSceNet/Export.cpp
PR 12682 core/libs/prx/libSceNet/Export.cpp
PR 12688 core/libs/prx/libSceNet/Export.cpp
PR 12700 core/libs/prx/libSceNet/Export.cpp
PR 12965 core/libs/prx/libSceNet/Export.cpp
PR 16826 core/libs/prx/libSceNet/Export.cpp
PR 18108 core/libs/prx/libSceNet/Export.cpp
core/libs/tests/GuestNetSocketState.cpp
PR 23975 core/libs/prx/libSceNet/Export.cpp
PR 27131 core/libs/prx/libSceNet/Export.cpp

@ycbuzi

ycbuzi commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Tested 50e5108ea9 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, 3 tests failed out of 7498; 99% tests passed, 2 tests failed out of 7498. 2 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 7498; 100% tests passed, 0 tests failed out of 7498. run

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

@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.

GuestNetSocketState passed on Linux x86_64 at 50e5108ea912. I also checked successful write shutdown over IPv4 and IPv6 loopback. The peer read the queued byte and then EOF, while the reverse direction still delivered bytes. The invalid-descriptor and invalid-direction cases in the supplied test passed with their expected errno precedence.

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 50e5108ea9. 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_net_socket_state: pass on both.
  • Control (same tree and tests, the changed files of those PRs put back to main's): aborts on both.

Not checked: a title.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit 78f9a69 into boykopovar:main Dec 5, 2026
15 of 17 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.

6 participants