feat(libkernel_sys): implement adjtime export #14257

Merged
bipinkrish merged 5 commits from upstream-pr/14257 into main 2026-11-05 14:04:04 +00:00
bipinkrish commented 2026-11-01 04:30:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by bipinkrish on 2026-11-01T04:30:46Z.


What

Implement adjtime under the project's jailed-caller model from #11216.

  • A non-null delta is read with checked guest access. An unreadable input returns -1 with guest EFAULT before any privilege or output check.
  • Every readable non-null adjustment, including zero, returns -1 with guest EPERM. FreeBSD 11.4 kern_adjtime checks PRIV_ADJTIME, which prison_priv_check denies to a jailed caller. oldDelta stays untouched on this failure.
  • A null delta queries the pending correction, which is zero because no adjustment is accepted. An unwritable query output returns EFAULT.

The host clock is never adjusted. Console privileges and clock behavior remain unverified in the debt entry. Privileged unjailed callers are not modelled.

Land before #14299 and #14304. Their overlapping debt-inventory changes must be reconciled when rebased.

Tested

  • Ubuntu 24.04.4 x86-64, GCC 13.3.0, Release: built the production libkernel_sys CMake target and GuestKernelSysAdjtime.cpp in an isolated harness. Existing guest libc/libkernel artifacts were reused. ctest --test-dir /tmp/anyps5-adjtime-jail-build -R '^guest_kernel_sys_adjtime$' --output-on-failure passed outside the syscall-restricted sandbox.
  • Checks cover null-delta queries, guest errno preservation, unreadable input before privilege denial, untouched output on failure, denied adjustments with an invalid output pointer, positive/negative/zero adjustments and extreme integer values, and unchanged pending correction after denial.
  • Regression control: the same new test built against the previous production AdditionalExports.cpp fails at its old NotImplemented throw. The revised production library passes.
  • Changed implementation and test pass g++ -std=c++20 -Wall -Wextra -Werror -Icore/libs -fsyntax-only. Diff and convention/template checks passed.
  • No console or privileged unjailed-caller measurement. The full project build and suite were not rerun for this correction. A fresh hosted Windows run is still needed for the new behavior.

Previous-head Windows reports apply to 3fcc7f7580: WinLibs GCC 15.2.0, 3/3 runs, and MSYS2 GCC 16.1.0, 5/5 runs. These do not validate the new EPERM behavior.

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
  • 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:5104374897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14257). Originally posted by [bipinkrish](https://github.com/bipinkrish) on 2026-11-01T04:30:46Z. --- ### What Implement `adjtime` under the project's jailed-caller model from [#11216](https://github.com/boykopovar/AnyPS5/pull/11216). - A non-null `delta` is read with checked guest access. An unreadable input returns `-1` with guest `EFAULT` before any privilege or output check. - Every readable non-null adjustment, including zero, returns `-1` with guest `EPERM`. FreeBSD 11.4 [`kern_adjtime`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/kern_ntptime.c#L961-L1010) checks `PRIV_ADJTIME`, which [`prison_priv_check`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/kern_jail.c#L3060-L3385) denies to a jailed caller. `oldDelta` stays untouched on this failure. - A null `delta` queries the pending correction, which is zero because no adjustment is accepted. An unwritable query output returns `EFAULT`. The host clock is never adjusted. Console privileges and clock behavior remain unverified in the debt entry. Privileged unjailed callers are not modelled. Land before #14299 and #14304. Their overlapping debt-inventory changes must be reconciled when rebased. ### Tested - Ubuntu 24.04.4 x86-64, GCC 13.3.0, Release: built the production `libkernel_sys` CMake target and `GuestKernelSysAdjtime.cpp` in an isolated harness. Existing guest libc/libkernel artifacts were reused. `ctest --test-dir /tmp/anyps5-adjtime-jail-build -R '^guest_kernel_sys_adjtime$' --output-on-failure` passed outside the syscall-restricted sandbox. - Checks cover null-delta queries, guest errno preservation, unreadable input before privilege denial, untouched output on failure, denied adjustments with an invalid output pointer, positive/negative/zero adjustments and extreme integer values, and unchanged pending correction after denial. - Regression control: the same new test built against the previous production `AdditionalExports.cpp` fails at its old `NotImplemented` throw. The revised production library passes. - Changed implementation and test pass `g++ -std=c++20 -Wall -Wextra -Werror -Icore/libs -fsyntax-only`. Diff and convention/template checks passed. - No console or privileged unjailed-caller measurement. The full project build and suite were not rerun for this correction. A fresh hosted Windows run is still needed for the new behavior. Previous-head Windows reports apply to `3fcc7f7580`: [WinLibs GCC 15.2.0, 3/3 runs](https://github.com/boykopovar/AnyPS5/pull/14257#issuecomment-6563101197), and [MSYS2 GCC 16.1.0, 5/5 runs](https://github.com/boykopovar/AnyPS5/pull/14257#issuecomment-6565257450). These do not validate the new EPERM behavior. <!-- 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. --> ### 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) - [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
MarcZX10 commented 2026-11-01 05:04:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T05:04:15Z.

Review: APPROVED


Reviewed — looks good

The implementation reports a zero pending adjustment for the supported null-delta query and keeps non-null clock changes explicitly unsupported instead of claiming success.

What I ran

Reviewed head 342117a322fdf8bbfa672050cde378e25965149d, against the PR base 638ebe70f8656b03351ab853f117758a6d84bacb; I also checked a clean merge preview against current main 3ab5a11d665ea59acec36de45c22c5358fea63d7. Environment: Debian 12 x86_64, GCC 12.2.0, Python 3.11.2. I did not build or run C++ tests locally.

git diff --check 638ebe70f8656b03351ab853f117758a6d84bacb...342117a322fdf8bbfa672050cde378e25965149d
python3 tools/check_conventions.py --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --title 'feat(libkernel_sys): implement adjtime export' --body /tmp/anyps5-pr-precheck-14257-session/pr-body.md
python3 tools/pr_abi_audit.py --repo /tmp/anyps5-review-14257-exact-20261101 --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --json | python3 -c 'import json,sys; d=json.load(sys.stdin); print("status=%s symbols=%d findings=%d" % (d["status"],len(d["symbols"]),len(d["findings"])))'
python3 tools/pr_test_quality.py --root /tmp/anyps5-review-14257-exact-20261101 --json core/libs/tests/GuestKernelSysAdjtime.cpp
git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/upstream/pr/14257
gh api repos/boykopovar/AnyPS5/commits/342117a322fdf8bbfa672050cde378e25965149d/check-runs --jq '.check_runs[] | [.name,.status,.conclusion] | @tsv'
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14257 --output-dir /tmp/anyps5-pr-precheck-14257-session

Results

Check Result
Diff check Passed.
Conventions and PR template Passed.
Export audit Passed: 325 symbols, no findings. This does not certify runtime ABI or console behavior.
Test registration Confirmed in core/libs/CMakeLists.txt. The test-quality heuristic's unregistered-test warning is a false positive.
Merge preview Clean against current main.
Author-reported tests Linux build and ctest -R 'guest_kernel_sys' passed 27/27; I did not independently run them.
Hosted CI Labels, conventions, intake, eligibility, library portability, and report passed. Windows was in progress; Linux and specialized product jobs were skipped at the final check.
Integrated precheck Its detached checkout lacked workspace-only ABI/test-quality helper scripts; I ran both manually against the exact head.
Unedited command output
$ git diff --check 638ebe70f8656b03351ab853f117758a6d84bacb...342117a322fdf8bbfa672050cde378e25965149d
[no output; exit status 0]
$ python3 tools/check_conventions.py --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --title 'feat(libkernel_sys): implement adjtime export' --body /tmp/anyps5-pr-precheck-14257-session/pr-body.md
All conventions checks passed.
$ python3 tools/pr_abi_audit.py --repo /tmp/anyps5-review-14257-exact-20261101 --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --json | python3 -c 'import json,sys; d=json.load(sys.stdin); print("status=%s symbols=%d findings=%d" % (d["status"],len(d["symbols"]),len(d["findings"])))'
status=passed symbols=325 findings=0
$ python3 tools/pr_test_quality.py --root /tmp/anyps5-review-14257-exact-20261101 --json core/libs/tests/GuestKernelSysAdjtime.cpp
{
  "findings": [
    {
      "path": "core/libs/tests/GuestKernelSysAdjtime.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}
$ grep -n -A12 -B4 'guest_kernel_sys_adjtime' /tmp/anyps5-review-14257-exact-20261101/core/libs/CMakeLists.txt
505:    add_test_executable(guest_kernel_sys_adjtime_tests tests/GuestKernelSysAdjtime.cpp)
506:    target_include_directories(guest_kernel_sys_adjtime_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
507:    target_link_libraries(guest_kernel_sys_adjtime_tests PRIVATE libkernel_sys libkernel libc)
508:    configure_windows_unwind(guest_kernel_sys_adjtime_tests)
509:    add_test(NAME guest_kernel_sys_adjtime COMMAND guest_kernel_sys_adjtime_tests)
510:    set_tests_properties(guest_kernel_sys_adjtime PROPERTIES TIMEOUT 20)
511:    if(WIN32)
512:        set_tests_properties(guest_kernel_sys_adjtime PROPERTIES ENVIRONMENT_MODIFICATION
513:            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel_sys>")
$ git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/upstream/pr/14257
6f39b13ce6e4da7f6be47155d8d43e24f7f7b8af
$ gh api repos/boykopovar/AnyPS5/commits/342117a322fdf8bbfa672050cde378e25965149d/check-runs --jq '.check_runs[] | [.name,.status,.conclusion] | @tsv'
labels	completed	success
conventions	completed	success
linux	completed	skipped
relinker-asan	completed	skipped
register-context	completed	skipped
write-watch	completed	skipped
relinker	completed	skipped
windows	in_progress	
conventions	completed	success
labels	completed	success
intake	completed	success
eligibility	completed	success
library-portability	completed	success
report	completed	success
$ python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14257 --output-dir /tmp/anyps5-pr-precheck-14257-session
/tmp/anyps5-pr-precheck-14257-session/report.md
/tmp/anyps5-pr-precheck-14257-session/report.json
Conclusion: checks failed
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck-14257-session/head-342117a322fd-34ed80e4/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck-14257-session/head-342117a322fd-34ed80e4/tools/pr_test_quality.py': [Errno 2] No such file or directory

Sources

Not verified

No local build, local CTest, or PS5-console run. The author-reported 27/27 tests were not independently reproduced. Windows CI had not completed; Linux and specialized hosted jobs were skipped when checked.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5726569097 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14257#pullrequestreview-5726569097). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T05:04:15Z. **Review:** APPROVED --- # Reviewed — looks good The implementation reports a zero pending adjustment for the supported null-delta query and keeps non-null clock changes explicitly unsupported instead of claiming success. ## What I ran Reviewed head `342117a322fdf8bbfa672050cde378e25965149d`, against the PR base `638ebe70f8656b03351ab853f117758a6d84bacb`; I also checked a clean merge preview against current `main` `3ab5a11d665ea59acec36de45c22c5358fea63d7`. Environment: Debian 12 x86_64, GCC 12.2.0, Python 3.11.2. I did not build or run C++ tests locally. ```sh git diff --check 638ebe70f8656b03351ab853f117758a6d84bacb...342117a322fdf8bbfa672050cde378e25965149d python3 tools/check_conventions.py --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --title 'feat(libkernel_sys): implement adjtime export' --body /tmp/anyps5-pr-precheck-14257-session/pr-body.md python3 tools/pr_abi_audit.py --repo /tmp/anyps5-review-14257-exact-20261101 --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --json | python3 -c 'import json,sys; d=json.load(sys.stdin); print("status=%s symbols=%d findings=%d" % (d["status"],len(d["symbols"]),len(d["findings"])))' python3 tools/pr_test_quality.py --root /tmp/anyps5-review-14257-exact-20261101 --json core/libs/tests/GuestKernelSysAdjtime.cpp git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/upstream/pr/14257 gh api repos/boykopovar/AnyPS5/commits/342117a322fdf8bbfa672050cde378e25965149d/check-runs --jq '.check_runs[] | [.name,.status,.conclusion] | @tsv' python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14257 --output-dir /tmp/anyps5-pr-precheck-14257-session ``` ## Results | Check | Result | |---|---| | Diff check | Passed. | | Conventions and PR template | Passed. | | Export audit | Passed: 325 symbols, no findings. This does not certify runtime ABI or console behavior. | | Test registration | Confirmed in `core/libs/CMakeLists.txt`. The test-quality heuristic's unregistered-test warning is a false positive. | | Merge preview | Clean against current `main`. | | Author-reported tests | Linux build and `ctest -R 'guest_kernel_sys'` passed 27/27; I did not independently run them. | | Hosted CI | Labels, conventions, intake, eligibility, library portability, and report passed. Windows was in progress; Linux and specialized product jobs were skipped at the final check. | | Integrated precheck | Its detached checkout lacked workspace-only ABI/test-quality helper scripts; I ran both manually against the exact head. | <details><summary>Unedited command output</summary> ```text $ git diff --check 638ebe70f8656b03351ab853f117758a6d84bacb...342117a322fdf8bbfa672050cde378e25965149d [no output; exit status 0] $ python3 tools/check_conventions.py --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --title 'feat(libkernel_sys): implement adjtime export' --body /tmp/anyps5-pr-precheck-14257-session/pr-body.md All conventions checks passed. $ python3 tools/pr_abi_audit.py --repo /tmp/anyps5-review-14257-exact-20261101 --base 638ebe70f8656b03351ab853f117758a6d84bacb --head 342117a322fdf8bbfa672050cde378e25965149d --json | python3 -c 'import json,sys; d=json.load(sys.stdin); print("status=%s symbols=%d findings=%d" % (d["status"],len(d["symbols"]),len(d["findings"])))' status=passed symbols=325 findings=0 $ python3 tools/pr_test_quality.py --root /tmp/anyps5-review-14257-exact-20261101 --json core/libs/tests/GuestKernelSysAdjtime.cpp { "findings": [ { "path": "core/libs/tests/GuestKernelSysAdjtime.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } $ grep -n -A12 -B4 'guest_kernel_sys_adjtime' /tmp/anyps5-review-14257-exact-20261101/core/libs/CMakeLists.txt 505: add_test_executable(guest_kernel_sys_adjtime_tests tests/GuestKernelSysAdjtime.cpp) 506: target_include_directories(guest_kernel_sys_adjtime_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 507: target_link_libraries(guest_kernel_sys_adjtime_tests PRIVATE libkernel_sys libkernel libc) 508: configure_windows_unwind(guest_kernel_sys_adjtime_tests) 509: add_test(NAME guest_kernel_sys_adjtime COMMAND guest_kernel_sys_adjtime_tests) 510: set_tests_properties(guest_kernel_sys_adjtime PROPERTIES TIMEOUT 20) 511: if(WIN32) 512: set_tests_properties(guest_kernel_sys_adjtime PROPERTIES ENVIRONMENT_MODIFICATION 513: "PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel_sys>") $ git merge-tree --write-tree refs/remotes/upstream/main refs/remotes/upstream/pr/14257 6f39b13ce6e4da7f6be47155d8d43e24f7f7b8af $ gh api repos/boykopovar/AnyPS5/commits/342117a322fdf8bbfa672050cde378e25965149d/check-runs --jq '.check_runs[] | [.name,.status,.conclusion] | @tsv' labels completed success conventions completed success linux completed skipped relinker-asan completed skipped register-context completed skipped write-watch completed skipped relinker completed skipped windows in_progress conventions completed success labels completed success intake completed success eligibility completed success library-portability completed success report completed success $ python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14257 --output-dir /tmp/anyps5-pr-precheck-14257-session /tmp/anyps5-pr-precheck-14257-session/report.md /tmp/anyps5-pr-precheck-14257-session/report.json Conclusion: checks failed /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck-14257-session/head-342117a322fd-34ed80e4/tools/pr_abi_audit.py': [Errno 2] No such file or directory /usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck-14257-session/head-342117a322fd-34ed80e4/tools/pr_test_quality.py': [Errno 2] No such file or directory ``` </details> ## Sources - [Implementation and test at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/342117a322fdf8bbfa672050cde378e25965149d/core/libs/prx/libkernel_sys/AdditionalExports.cpp#L207-L230) - [FreeBSD 11.4 reference cited by the PR, pinned to its source commit](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/kern/kern_ntptime.c#L955-L978) ## Not verified No local build, local CTest, or PS5-console run. The author-reported 27/27 tests were not independently reproduced. Windows CI had not completed; Linux and specialized hosted jobs were skipped when checked.
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!14257
No description provided.