Skip to content

test(libkernel): audit getpeername unconnected and listening socket bounds - #17437

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
slopgobblercobbler:slopgobblercobbler/pr-libkernel-getpeername-flags
Nov 20, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
slopgobblercobbler:slopgobblercobbler/pr-libkernel-getpeername-flags

Conversation

@slopgobblercobbler

@slopgobblercobbler slopgobblercobbler commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Audit getpeername behavior on unconnected and listening TCP sockets in core/libs/tests/GuestTcp.cpp. Verifies returning ENOTCONN (57) for size = 0 on unconnected sockets and for listening sockets. Standalone test executable removed per maintainer review.

Tested

  • ctest --test-dir build -R guest_kernel_tcp_tests
  • python tools/check_conventions.py --base upstream/main --head HEAD (0 findings)

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

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

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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_kernel_getpeername_flags_tests built cleanly.
  • CTest (guest_kernel_getpeername_flags):
    1/1 Test #4175: guest_kernel_getpeername_flags ...Subprocess aborted***Exception:   0.46 sec
    0% tests passed, 1 tests failed out of 1
    
    The following tests FAILED:
    
  • Note: the AI-assisted checkbox can stay.

Requesting changes for the points above.

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head a3db4aaea3, merged onto main 0bae53facd (3650599b04, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release, Vulkan hidden for this CPU-only run. The linux check is skipped on this PR.

Tests run (from the log): guest_kernel_getpeername_flags

Fails in 3 of 3 runs:

1/1 Test #4268: guest_kernel_getpeername_flags ...Exit code 0xc0000409***Exception:   0.09 sec
getpeername check failed at line 39, errno 14

I've only quoted the output here and haven't traced the cause.

AI-assisted: yes.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@slopgobblercobbler, the test fails as written. Line 39 expects EINVAL (22) when the length pointer is null, but getpeername_nid_postfix in Udp.cpp copies the length in first and returns EFAULT (14), which matches FreeBSD, and JJenkx's Windows run shows the same failure ("line 39, errno 14", 3 of 3). The hosted windows check is red on this head too. Beyond that, most of the file repeats main: a fresh socket returning 57 is in GuestTcp.cpp, GuestSocketPortZero.cpp, GuestUdp.cpp and GuestSocketPair.cpp, and the truncation, oversized length and null address cases are in GuestTcp.cpp and GuestSocketPortZero.cpp. The test never exercises those cases, so the title overstates it, and nullSize is declared and never used. Could you drop the new file and its CMake entry, and if you want to keep the length 0 and bound plus listening socket returning 57 checks, add them to GuestTcp.cpp next to the existing 57 check?

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head a3db4aaea3, merged onto main 28237a8567 (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: guest_kernel_getpeername_flags.
  • guest_kernel_getpeername_flags fails in 3 of 3 runs.
  • No negative control: the PR changes only test files.
  • guest_kernel_getpeername_flags is added by this PR and aborts on Windows: getpeername check failed at line 39, errno 14 (EFAULT).

AI-assisted: yes.

@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 — no blocking findings

The reviewed change adds a focused getpeername guest test; I found no verified blocking defect, but did not run the test suite.

What I ran

Reviewed head a3db4aaea3e96cfa2808df285309981878af5bc7 using repo_read.py tools to read the prepared review documents and changed source. No build or tests were run.

Results

Check Result Note
Changed source review passed Both changed files read
Build and tests not run No test execution available

Findings

Blocking

None.

Non-blocking

  • core/libs/tests/GuestKernelGetpeernameFlags.cpp:35 passes a zero address length to getpeername on an unconnected socket and expects NotConnected. Since that error can occur before address-length handling, this case does not establish the claimed address-length-bound behavior. Exercise an appropriate connected socket case to verify the length handling directly.

Not verified

No build or CTest run was performed. Both changed files listed in the manifest were read; no changed files were excluded. Runtime behavior on Windows was not verified.

To get this to a good state

Nothing is required. The address-length test improvement is optional.

@slopgobblercobbler
slopgobblercobbler force-pushed the slopgobblercobbler/pr-libkernel-getpeername-flags branch from a3db4aa to 6691f2b Compare November 20, 2026 17:44
@slopgobblercobbler slopgobblercobbler changed the title test(libkernel): audit getpeername socket state and address length bounds test(libkernel): audit getpeername unconnected and listening socket bounds Nov 20, 2026
@slopgobblercobbler

Copy link
Copy Markdown
Contributor Author

@oneandonlydean @PrivacyOnion @JJenkx @gabichuuuuu
Addressed maintainer feedback:

  1. Removed standalone GuestKernelGetpeernameFlags.cpp and its CMakeLists.txt registration.
  2. Folded the size = 0 and listening socket ENOTCONN (57) bounds into core/libs/tests/GuestTcp.cpp adjacent to existing socket name tests.
  3. Rebased cleanly onto latest upstream/main with 0 conventions findings (check_conventions.py passed).
  4. Retitled PR to match remaining focused test scope.

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

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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_tcp_tests built cleanly.
  • CTest (guest_tcp):
    1/1 Test #5860: guest_tcp ........................   Passed    0.61 sec
    100% tests passed, 0 tests failed out of 1
    
  • Code reading:
    • Verified that getpeername on unconnected socket with size = 0 returns -1 and sets errno to ENOTCONN (57), as FreeBSD/PS5 checks connection state before copying out the address in core/libs/tests/GuestTcp.cpp:275-276.
    • Verified that getpeername on listening socket (listener) with size = address.size() returns -1 and sets errno to ENOTCONN (57) in core/libs/tests/GuestTcp.cpp:277-278.
    • Verified that the added test assertions properly clean up file descriptors ({unconnected, accepted, client, listener}) via close_nid_postfix at line 280.
    • Verified that no comments were added to code, adhering to AGENTS.md conventions, and check_conventions.py passed mechanically.
    • Confirmed maintainer oneandonlydean's explicit request to drop the standalone test file and fold the size = 0 and listening socket ENOTCONN checks into GuestTcp.cpp was accurately and cleanly followed.

Looks Good To Me

@oneandonlydean
oneandonlydean merged commit 5aaef8c into boykopovar:main Nov 20, 2026
13 of 15 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