fix(libkernel): keep socket descriptors within FD_SETSIZE #8595

Merged
MarcZX10 merged 3 commits from upstream-pr/8595 into main 2026-10-20 20:22:07 +00:00
MarcZX10 commented 2026-10-20 17:46:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T17:46:58Z.


What

Follow-up to merged #4391. Guest socket descriptors are stored in the same descriptor table used by the guest fd_set, which has 1024 entries. ReserveNumber and the duplicate paths currently accept host descriptor numbers at or above 1024 when the table is under pressure. This change caps socket reservation, dup/fcntl duplication (including the minimum-descriptor form from #7437), and dup2 at 1024. Any temporary host descriptor above the limit is closed and the operation returns EMFILE.

The regression fills descriptors up to 1024, then checks that dup, F_DUPFD, F_DUPFD_CLOEXEC, socket creation, and dup2 to descriptor 1024 fail with EMFILE. The fcntl checks cover both minimum descriptor 0 and the 1024 boundary.

Tested

  • Current main 892a4f1328a14a123eca4af8f3c9ea5d176133ab: GCC C++20 syntax checks pass for Udp.cpp and the updated GuestSocketDescriptors.cpp.
  • git diff --check passes.
  • python3 tools/check_conventions.py --base upstream/main --head HEAD passes.
  • The focused guest_socket_descriptors CTest was attempted from the existing Linux build. The executable aborts during the global host CPU check, before entering the test body: this Xeon E5-1620 v2 lacks LZCNT, BMI1/2, MOVBE, AVX2 and FMA. The runtime assertions have not run on this host.

Checklist

  • Based on current main; no other open PR implements the same behavior
  • 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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none (follow-up to #4366 / #4391)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4939955504 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8595). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T17:46:58Z. --- ### What Follow-up to merged #4391. Guest socket descriptors are stored in the same descriptor table used by the guest `fd_set`, which has 1024 entries. `ReserveNumber` and the duplicate paths currently accept host descriptor numbers at or above 1024 when the table is under pressure. This change caps socket reservation, `dup`/`fcntl` duplication (including the minimum-descriptor form from #7437), and `dup2` at 1024. Any temporary host descriptor above the limit is closed and the operation returns `EMFILE`. The regression fills descriptors up to 1024, then checks that `dup`, `F_DUPFD`, `F_DUPFD_CLOEXEC`, socket creation, and `dup2` to descriptor 1024 fail with `EMFILE`. The `fcntl` checks cover both minimum descriptor 0 and the 1024 boundary. ### Tested - Current `main` `892a4f1328a14a123eca4af8f3c9ea5d176133ab`: GCC C++20 syntax checks pass for `Udp.cpp` and the updated `GuestSocketDescriptors.cpp`. - `git diff --check` passes. - `python3 tools/check_conventions.py --base upstream/main --head HEAD` passes. - The focused `guest_socket_descriptors` CTest was attempted from the existing Linux build. The executable aborts during the global host CPU check, before entering the test body: this Xeon E5-1620 v2 lacks LZCNT, BMI1/2, MOVBE, AVX2 and FMA. The runtime assertions have not run on this host. ### Checklist - [x] Based on current `main`; no other open PR implements the same behavior - [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 - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none (follow-up to #4366 / #4391) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-20 18:15:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T18:15:20Z.


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 5021 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 6044 core/libs/tests/GuestSocketDescriptors.cpp
PR 6977 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 7088 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 7201 core/libs/prx/libkernel/Socket/src/Udp.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297903546 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8595#issuecomment-6297903546). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T18:15:20Z. --- <!-- pr-overlap --> 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestSocketDescriptors.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` |
MarcZX10 commented 2026-10-20 18:41:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T18:41:13Z.


Manual overlap check with #6044: that PR moves GuestSocketDescriptors.cpp to core/libs/tests/networking/GuestSocketDescriptors.cpp; it does not change Udp.cpp. There is no implementation dependency, but the test edit needs to be carried to the moved path if #6044 merges first. Since #6044 is currently dirty against main and has requested changes, would you prefer #8595 to land first, or should I rebase the test onto the moved file after your PR? I left Depends on: none because the code does not require #6044.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298436378 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8595#issuecomment-6298436378). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T18:41:13Z. --- Manual overlap check with #6044: that PR moves `GuestSocketDescriptors.cpp` to `core/libs/tests/networking/GuestSocketDescriptors.cpp`; it does not change `Udp.cpp`. There is no implementation dependency, but the test edit needs to be carried to the moved path if #6044 merges first. Since #6044 is currently dirty against `main` and has requested changes, would you prefer #8595 to land first, or should I rebase the test onto the moved file after your PR? I left `Depends on: none` because the code does not require #6044.
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!8595
No description provided.