Skip to content

test(libkernel): audit sysctl security and jail nodes, bounds, and ENOENT rejection - #21026

Open
slopgobblercobbler wants to merge 3 commits into
boykopovar:mainfrom
slopgobblercobbler:slopgobblercobbler/pr-libkernel-sysctl-security-nodes
Open

slopgobblercobbler wants to merge 3 commits into
boykopovar:mainfrom
slopgobblercobbler:slopgobblercobbler/pr-libkernel-sysctl-security-nodes

Conversation

@slopgobblercobbler

Copy link
Copy Markdown
Contributor

What

Add non-GTest standalone test GuestKernelSysctlSecurityNodes.cpp verifying sysctl security and jail nodes, bounds, and ENOENT rejection in accordance with docs/dev/debt/libkernel.md.

Tested

ctest --test-dir build -R guest_kernel_sysctl_security_nodes_tests

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

@github-actions github-actions Bot added libkernel build needs rebase Conflicts with main, rebase needed labels Nov 15, 2026
@slopgobblercobbler
slopgobblercobbler force-pushed the slopgobblercobbler/pr-libkernel-sysctl-security-nodes branch from 9fbf9dd to 9cd3abe Compare November 15, 2026 20:45
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 16, 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 6149 core/libs/prx/libkernel/CMakeLists.txt
PR 9302 core/libs/prx/libkernel/CMakeLists.txt
PR 9566 core/libs/prx/libkernel/CMakeLists.txt
PR 9938 core/libs/prx/libkernel/CMakeLists.txt
PR 12682 core/libs/prx/libkernel/CMakeLists.txt
PR 12688 core/libs/prx/libkernel/CMakeLists.txt
PR 12700 core/libs/prx/libkernel/CMakeLists.txt
PR 12965 core/libs/prx/libkernel/CMakeLists.txt
PR 16372 core/libs/prx/libkernel/CMakeLists.txt
PR 16790 core/libs/prx/libkernel/CMakeLists.txt
PR 18190 core/libs/prx/libkernel/CMakeLists.txt
PR 26206 core/libs/prx/libkernel/CMakeLists.txt
PR 27864 core/libs/prx/libkernel/CMakeLists.txt
PR 28299 core/libs/prx/libkernel/CMakeLists.txt
PR 28808 core/libs/prx/libkernel/CMakeLists.txt

@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows result for head 9cd3abe9f0, merged alone into main cb8ce41f77: guest_kernel_sysctl_security_nodes fails 3 of 3 runs.

[libc] unhandled exception 'St16invalid_argument' thrown from 00007ffd026c469e
terminate called after throwing an instance of 'std::invalid_argument'
  what():  sysctlnametomib_nid_postfix: null name or size
guest_kernel_sysctl_security_nodes (Exit code 0xc0000409)

The test builds cleanly and every sysctlbyname/sysctl check before it passes; it dies at sysctlnametomib_nid_postfix(nullptr, outMib, &size) (core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:191). The Throws helper (line 38) catches only std::runtime_error, but sysctlnametomib throws std::invalid_argument for a null name or size (core/libs/prx/libkernel/System/src/SystemConfiguration.cpp:873), which derives from std::logic_error, so the exception escapes and terminates the process. It throws std::invalid_argument at this PR's own base d2cea620f8 as well, so the failure does not look Windows-specific. Catching std::exception (or std::invalid_argument for the two null-argument cases) in Throws would match it. The test file does not exist on main.

The PR's own windows CI (run 43759853349) fails the same way, with the same null name or size message and exit 0xc0000409; the linux job was skipped.

Host: Windows 11 26300, Intel i7-12700K, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja.
ctest --test-dir build -R "^(guest_kernel_sysctl_security_nodes)$" --output-on-failure

Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the output above are from this machine.

@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

Thanks @maskym! Caught std::exception in Throws helper so std::invalid_argument from sysctlnametomib on null name/size is properly caught. Rebased cleanly onto upstream/main with 0 check_conventions.py errors.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 20, 2026

@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 — comments

Material uncertainty remains because the test’s asserted MIB and exception behavior do not consistently match the implementation at this head.

What I ran

Reviewed head 631e88862bbbedb4d3adab02ec23dcbdae6c4f26. No test commands were run. Read the prepared description, commit list, manifest, diff, review README, both changed files, and targeted sysctl implementation ranges using repo_read.py.

Results

Check Result Note
Changed-file review passed Both changed files read
Runtime test not run No build or test environment available

Findings

Blocking

None verified.

Non-blocking

  • sysctlnametomib_nid_postfix("security", ...) resolves security through TopLevelNode to a valid top-level MIB, while the test expects ENOENT (changed line core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:141). This assertion appears inconsistent with the current implementation.
  • The test expects sysctl_nid_postfix to throw for a write to {10, 1, 1} (changed line core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:165), but writes under absent top-level nodes set EPERM and return -1; the implementation only throws for the name[0] >= 256/other unsupported branch. Align the test’s expected behavior with the implementation or the intended contract.

Not verified

The described ctest --test-dir build -R guest_kernel_sysctl_security_nodes_tests was not run. No build configuration or platform-specific behavior was verified. files.json was not present in the prepared review folder; the manifest lists both changed files as included, and both were read. No files were excluded according to the available manifest.

To get this to a good state

Nothing is required. Optional: correct the two assertions above and run the described CTest target.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 20, 2026
@slopgobblercobbler
slopgobblercobbler force-pushed the slopgobblercobbler/pr-libkernel-sysctl-security-nodes branch from 631e888 to baaff39 Compare November 21, 2026 16:05

@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 — changes requested

Changes are required before merge: correct the top-level security error expectations so the new test matches the current API behavior.

What I ran

Reviewed head baaff3958114378bec2f4be6694048daeabc5d73 using repo_read.py against the prepared diff and pinned repository files. No commands or tests were run.

Results

Check Result Note
Diff and changed files passed Both changed files read
Targeted behavior audit passed Compared test expectations with implementation
CTest not run No test execution available

Findings

Blocking

  • The new test expects ENOENT for sysctlbyname("security") and sysctlbyname("security.") at core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:146 and core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:150. The implementation trims a trailing dot and returns EINVAL for a top-level sysctl name, so these assertions fail. Update the expectations to match the established behavior, or change the implementation if ENOENT is the intended contract.

Non-blocking

None.

Not verified

  • The submitted CTest command was not run.
  • No excluded files were listed. Read both files marked changed in the manifest: core/libs/prx/libkernel/CMakeLists.txt and core/libs/tests/GuestKernelSysctlSecurityNodes.cpp.
  • No other files were read.

To get this to a good state

Correct the two top-level security error expectations and run ctest --test-dir build -R guest_kernel_sysctl_security_nodes_tests on the updated head.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Replying to MarcZX10's change request: the two top-level "security" assertions (ENOENT for "security" and "security.") are not failing. On this head the Windows job ran guest_kernel_sysctl_security_nodes and it passed (Test #6230, 0.04 s), so the implementation returns ENOENT there, not EINVAL. Linux CI was skipped on this head; PrivacyOnion's run is the Linux evidence. Passing on this head. Nit for the author: add the missing include for std::string.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 24, 2026
# Conflicts:
#	core/libs/prx/libkernel/CMakeLists.txt

@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

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 8fcde7650130f006cb334101c0fa76e16bdd986e. No test commands were run.

Results

Check Result Note
Changed code review passed Both changed files read
Reported CTest not run Description reports it; not independently verified

Findings

Blocking

None.

Non-blocking

  • The new test defines several errno constants and includes <algorithm> without using them. Consider removing the unused declarations and include to keep the test focused.

Not verified

The reported CTest result, build behavior, and runtime behavior were not independently verified. Both changed files listed in the manifest were read; no files were excluded by the manifest.

To get this to a good state

Nothing is required.

Optional: remove the unused declarations and include.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 25, 2026
# Conflicts:
#	core/libs/prx/libkernel/CMakeLists.txt

@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 — comments

Changes are required before merge: address the optional test quality points below before treating this audit as complete.

What I ran

Reviewed head be3b652d64ba9ad6f2dba901d2f7c466ed5d92bb against base main. No build or test command was run; the test result in the PR description is author-reported. I read all changed lines in core/libs/prx/libkernel/CMakeLists.txt and core/libs/tests/GuestKernelSysctlSecurityNodes.cpp, plus the targeted SystemConfiguration.cpp implementations and the existing sysctl memory-node test for context.

Results

Check Result Note
Changed-line review passed Both changed files read
Test execution not run Reported by author only
Runtime behavior not verified No build or execution performed

Findings

Blocking

None.

Non-blocking

  • core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:12-17: PosixEperm, PosixEnomem, and PosixEnotdir are unused. Remove them so the test does not carry stale errno expectations.
  • core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:190-200: Throws accepts any std::exception, making the assertions pass for unrelated exception types. Check the expected exception type or otherwise assert its diagnostic so these cases verify the intended unsupported-write and unsupported-MIB paths.
  • core/libs/tests/GuestKernelSysctlSecurityNodes.cpp:216-225: null-pointer cases also only check that some standard exception was thrown. Assert the expected std::invalid_argument to ensure the API's documented null-argument path is what the test covers.

Not verified

The CTest run, build configuration, and runtime behavior were not verified. files.json was not provided as a readable artifact; the review manifest lists two changed files, and both were read in full. No excluded files were listed in the artifacts available to this review.

To get this to a good state

Nothing is required. The three points above are optional test-quality feedback.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Nov 26, 2026

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

Built the exact branch test source and ran GuestKernelSysctlSecurityNodes on Linux against the existing runtime libraries. The test run passed and covered the security and jail nodes, bounds, and missing-name checks.

AI-assisted: yes.

This branch has not been deployed

No deployments
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.

5 participants