fix(libkernel): resolve kern.proc.pid, vmmap and env by name, as FreeBSD 11.4 does #23624

Open
brajankw wants to merge 1 commit from upstream-pr/23624 into main
brajankw commented 2026-11-19 10:51:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-19T10:51:59Z.


What

sysctl answers {1, 14, 1} (kern.proc.pid), {1, 14, 32} (kern.proc.vmmap) and {1, 14, 35} (kern.proc.env) with a pid as the fourth element, but sysctlnametomib and sysctlbyname returned -1 with ENOENT for those names. So the usual FreeBSD way to reach these nodes, resolving the name and appending a pid to the MIB, failed. #14591 closed the same gap for kern.proc.proc.

  • sysctlnametomib maps the three names to three-element MIBs, as for kern.proc.pathname and kern.proc.proc. The numbers are the ones FreeBSD 11.4's kern_proc.c registers pid and env under, and vmmap (KERN_PROC_PID 1, KERN_PROC_VMMAP 32 and KERN_PROC_ENV 35 in sys/sysctl.h).

  • On a PS5 (firmware 11.60, payload process), xXPBSXx's probes in #22788 got answers that are not ENOENT from all three MIBs with the own pid: a 1,096-byte record from {1, 14, 1} (second probe, line 4; first probe, line 18 for the size query), 36 records of 144 bytes from {1, 14, 32} (fourth probe, line 8), and a size of 0 from {1, 14, 35} (third probe, line 9). So the nodes exist there under these numbers. The console's names for them were not measured.

  • sysctlbyname goes through sysctl with the three-element MIB, since FreeBSD 11.4's sysctlbyname is sysctlnametomib followed by sysctl. The MIB path is not changed, so through the name:

    • a read fails with EINVAL, as sysctl_kern_proc and sysctl_kern_proc_env do when no pid follows the node;
    • a write fails with EPERM, which sysctl_root gives for these read-only nodes before their handler runs;
    • a length that cannot be read fails with EFAULT.

    kern.proc.pathname already answers this way by name. FreeBSD 11.4's sysctl_kern_proc_vmmap does not check the length and reads a pid past the name. Here kern.proc.vmmap by name gets the EINVAL its three-element MIB already gets.

  • kern.proc.pid_td is not mapped, although FreeBSD registers it at {1, 14, 17}: the same probes got ENOENT for that MIB (third probe, lines 18 to 24), so the console likely has no such node. Its name keeps ENOENT from both calls. The MIB {1, 14, 17} still answers here, as its debt entry says; this does not change it.

  • Tests: GuestSystemConfiguration.cpp.

    • CheckNameToMib lists the three names with their MIBs.
    • CheckProcessNodeNames, for each name:
      • the resolved MIB with the own pid appended gives the same size as the MIB written out;
      • sysctlbyname fails with EINVAL and leaves the buffer and the length alone, also for a size query and with both pointers null;
      • a write fails with EPERM, and an unreadable length with EFAULT.
    • kern.proc.pid_td still gets ENOENT from both calls.
  • Debt: no fragment. No entry records the name gap, and the kern.proc.pid, kern.proc.vmmap and kern.proc.env entries describe the MIBs, which this does not change.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head fb1fcf91ef, the single commit on main 3f4693be43.

  • Negative control: with only the test change, as first written, on main 74f685158e, guest_system_configuration aborts.
  • ctest over the four tests whose sources call sysctl, sysctlbyname or sysctlnametomib, and guest_getrlimit: all pass on fb1fcf91ef. The four are guest_system_configuration, guest_kernel_sysctl_name_bounds, guest_kernel_sysctl_memory_nodes and guest_sce_net.
  • Full ctest (6215 tests, -j 12) on 2b0abd9797: 6200 passed. That is this change before review, which later only removed one block of the test, and before the rebase onto 3f4693be43, which touched none of its files. Of the 15 failures:
    • nine need a .git directory, network access or a passwd entry for the user, and also fail on main in this environment: 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;
    • five agc_driver GPU cases fail the same way on main 3f4693be43: prepared_shaders with its indirect, uncached and debug forms, and storage_file_write;
    • agc_driver_image_table_packed_guards passed 2 of 10 runs on its own both on fb1fcf91ef and on main 3f4693be43, failing with "unrecoverable packed table format was not poisoned".
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch fix/libkernel-sysctl-proc-pid-env-vmmap-names: no overlap with open pull requests. #22788 changes the same two files, in the kinfo_proc record and its tests, and merges with this branch without overlap. The tool could not compare #18190, which conflicts with main. That PR renames sysctl, sysctlbyname and the other exports of this file to _nid_no_patch forms and does not change the name handling.
  • 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:5393470215 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23624). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-19T10:51:59Z. --- ### What `sysctl` answers {1, 14, 1} (`kern.proc.pid`), {1, 14, 32} (`kern.proc.vmmap`) and {1, 14, 35} (`kern.proc.env`) with a pid as the fourth element, but `sysctlnametomib` and `sysctlbyname` returned -1 with `ENOENT` for those names. So the usual FreeBSD way to reach these nodes, resolving the name and appending a pid to the MIB, failed. #14591 closed the same gap for `kern.proc.proc`. - `sysctlnametomib` maps the three names to three-element MIBs, as for `kern.proc.pathname` and `kern.proc.proc`. The numbers are the ones FreeBSD 11.4's [`kern_proc.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_proc.c#L2946-L2957) registers `pid` and `env` under, and [`vmmap`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_proc.c#L3002-L3003) (`KERN_PROC_PID` 1, `KERN_PROC_VMMAP` 32 and `KERN_PROC_ENV` 35 in [`sys/sysctl.h`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/sys/sysctl.h#L883-L906)). - On a PS5 (firmware 11.60, payload process), xXPBSXx's probes in #22788 got answers that are not `ENOENT` from all three MIBs with the own pid: a 1,096-byte record from {1, 14, 1} (second probe, line 4; first probe, line 18 for the size query), 36 records of 144 bytes from {1, 14, 32} (fourth probe, line 8), and a size of 0 from {1, 14, 35} (third probe, line 9). So the nodes exist there under these numbers. The console's names for them were not measured. - `sysctlbyname` goes through `sysctl` with the three-element MIB, since FreeBSD 11.4's [`sysctlbyname`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/gen/sysctlbyname.c#L17-L28) is `sysctlnametomib` followed by `sysctl`. The MIB path is not changed, so through the name: - a read fails with `EINVAL`, as [`sysctl_kern_proc`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_proc.c#L1433-L1435) and [`sysctl_kern_proc_env`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_proc.c#L1983-L1984) do when no pid follows the node; - a write fails with `EPERM`, which [`sysctl_root`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_sysctl.c#L1869-L1873) gives for these read-only nodes before their handler runs; - a length that cannot be read fails with `EFAULT`. `kern.proc.pathname` already answers this way by name. FreeBSD 11.4's [`sysctl_kern_proc_vmmap`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_proc.c#L2547-L2557) does not check the length and reads a pid past the name. Here `kern.proc.vmmap` by name gets the `EINVAL` its three-element MIB already gets. - `kern.proc.pid_td` is not mapped, although FreeBSD registers it at {1, 14, 17}: the same probes got `ENOENT` for that MIB (third probe, lines 18 to 24), so the console likely has no such node. Its name keeps `ENOENT` from both calls. The MIB {1, 14, 17} still answers here, as its debt entry says; this does not change it. - Tests: `GuestSystemConfiguration.cpp`. - `CheckNameToMib` lists the three names with their MIBs. - `CheckProcessNodeNames`, for each name: - the resolved MIB with the own pid appended gives the same size as the MIB written out; - `sysctlbyname` fails with `EINVAL` and leaves the buffer and the length alone, also for a size query and with both pointers null; - a write fails with `EPERM`, and an unreadable length with `EFAULT`. - `kern.proc.pid_td` still gets `ENOENT` from both calls. - Debt: no fragment. No entry records the name gap, and the `kern.proc.pid`, `kern.proc.vmmap` and `kern.proc.env` entries describe the MIBs, which this does not change. ### 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). Head `fb1fcf91ef`, the single commit on `main` `3f4693be43`. - Negative control: with only the test change, as first written, on `main` `74f685158e`, `guest_system_configuration` aborts. - `ctest` over the four tests whose sources call `sysctl`, `sysctlbyname` or `sysctlnametomib`, and `guest_getrlimit`: all pass on `fb1fcf91ef`. The four are `guest_system_configuration`, `guest_kernel_sysctl_name_bounds`, `guest_kernel_sysctl_memory_nodes` and `guest_sce_net`. - Full `ctest` (6215 tests, `-j 12`) on `2b0abd9797`: 6200 passed. That is this change before review, which later only removed one block of the test, and before the rebase onto `3f4693be43`, which touched none of its files. Of the 15 failures: - nine need a `.git` directory, network access or a passwd entry for the user, and also fail on `main` in this environment: `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`; - five `agc_driver` GPU cases fail the same way on `main` `3f4693be43`: `prepared_shaders` with its `indirect`, `uncached` and `debug` forms, and `storage_file_write`; - `agc_driver_image_table_packed_guards` passed 2 of 10 runs on its own both on `fb1fcf91ef` and on `main` `3f4693be43`, failing with "unrecoverable packed table format was not poisoned". - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch fix/libkernel-sysctl-proc-pid-env-vmmap-names`: no overlap with open pull requests. #22788 changes the same two files, in the `kinfo_proc` record and its tests, and merges with this branch without overlap. The tool could not compare #18190, which conflicts with `main`. That PR renames `sysctl`, `sysctlbyname` and the other exports of this file to `_nid_no_patch` forms and does not change the name handling. - 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-19 10:54:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T10:54:21Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_system_configuration_tests built cleanly.
  • CTest (guest_system_configuration):
    1/1 Test #5674: guest_system_configuration .......   Passed    0.05 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/System/src/SystemConfiguration.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5674: guest_system_configuration .......Subprocess aborted***Exception:   0.40 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified core/libs/prx/libkernel/System/src/SystemConfiguration.cpp sysctlnametomib_nid_postfix correctly resolves kern.proc.pid ({1, 14, 1}), kern.proc.vmmap ({1, 14, 32}), and kern.proc.env ({1, 14, 35}) to 3-element MIBs matching FreeBSD 11.4 conventions.
    • Verified sysctlbyname_nid_postfix delegates 3-element MIB queries ({1, 14, 1}, {1, 14, 32}, {1, 14, 35}) directly to sysctl_nid_postfix without a trailing PID argument, which correctly yields EINVAL (22) for missing PID as verified by the unit tests.
    • Verified GuestSystemConfiguration.cpp CheckProcessNodeNames test coverage thoroughly checks name resolution, MIB contents, error behavior with missing PIDs, buffer validation, and invalid names.
    • Checked LP64/LLP64 portability and C++20 type correctness in static constexpr int arrays across GCC and MSVC.
    • Verified AGENTS.md compliance: no comments in code, no fake success stubs, no special-cased title IDs, and no untracked debt/investigation files.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5973642081 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23624#pullrequestreview-5973642081). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T10:54:21Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `fb1fcf91ef`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_system_configuration_tests` built cleanly. - **CTest** (`guest_system_configuration`): ``` 1/1 Test #5674: guest_system_configuration ....... Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/System/src/SystemConfiguration.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5674: guest_system_configuration .......Subprocess aborted***Exception: 0.40 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified core/libs/prx/libkernel/System/src/SystemConfiguration.cpp sysctlnametomib_nid_postfix correctly resolves kern.proc.pid ({1, 14, 1}), kern.proc.vmmap ({1, 14, 32}), and kern.proc.env ({1, 14, 35}) to 3-element MIBs matching FreeBSD 11.4 conventions. - Verified sysctlbyname_nid_postfix delegates 3-element MIB queries ({1, 14, 1}, {1, 14, 32}, {1, 14, 35}) directly to sysctl_nid_postfix without a trailing PID argument, which correctly yields EINVAL (22) for missing PID as verified by the unit tests. - Verified GuestSystemConfiguration.cpp CheckProcessNodeNames test coverage thoroughly checks name resolution, MIB contents, error behavior with missing PIDs, buffer validation, and invalid names. - Checked LP64/LLP64 portability and C++20 type correctness in static constexpr int arrays across GCC and MSVC. - Verified AGENTS.md compliance: no comments in code, no fake success stubs, no special-cased title IDs, and no untracked debt/investigation files. Looks Good To Me
MarcZX10 commented 2026-11-23 05:08:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T05:08:28Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed code and reported checks support merging.

What I ran

Reviewed head fb1fcf91ef178257ab1519fbefc5f8629c74d6ef using the prepared diff and repo_read.py source reads. I did not run tests; the Linux test results in the PR description are author-reported.

Results

Check Result Note
Diff and targeted source review passed Both changed files read
Tests in this review not run Reported results not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run during this review. The description reports Linux checks and says Windows, macOS, and title execution were not tested. The change is limited to two files; both files listed as reviewed in the manifest were read. files.json was unavailable in the prepared bundle.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016822871 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23624#pullrequestreview-6016822871). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T05:08:28Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed code and reported checks support merging. ## What I ran Reviewed head `fb1fcf91ef178257ab1519fbefc5f8629c74d6ef` using the prepared diff and `repo_read.py` source reads. I did not run tests; the Linux test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted source review | passed | Both changed files read | | Tests in this review | not run | Reported results not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run during this review. The description reports Linux checks and says Windows, macOS, and title execution were not tested. The change is limited to two files; both files listed as reviewed in the manifest were read. `files.json` was unavailable in the prepared bundle. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 12:52:12 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Built the branch’s changed sources and ran GuestSystemConfiguration on Linux against the existing runtime libraries. The test run passed and covered the kernel sysctl name lookup cases.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170168784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23624#pullrequestreview-6170168784). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T12:52:12Z. **Review:** COMMENTED --- Built the branch’s changed sources and ran GuestSystemConfiguration on Linux against the existing runtime libraries. The test run passed and covered the kernel sysctl name lookup cases. AI-assisted: yes.
Plyxen commented 2026-12-03 14:08:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T14:08:43Z.

Review: APPROVED


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

  • guest_system_configuration: pass on both.
  • Control (the same tree with only this PR's source change taken out): on Windows it aborts. On Linux, with the changed sources of the tested CPU PRs put back to main's, the same test fails too.

Not checked: a console.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6171386026 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23624#pullrequestreview-6171386026). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T14:08:43Z. **Review:** APPROVED --- I read the diff at `fb1fcf91ef`. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into `main` at `6c6b29320fe` together with other open PRs (so not an isolated build). - `guest_system_configuration`: pass on both. - Control (the same tree with only this PR's source change taken out): on Windows it aborts. On Linux, with the changed sources of the tested CPU PRs put back to `main`'s, the same test fails too. Not checked: a console. AI-assisted: yes (Claude Code)
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/23624:upstream-pr/23624'
git switch 'upstream-pr/23624'

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