Repository navigation
fix(libkernel): keep stream data queued when recvmsg cannot write its buffer, as FreeBSD 11.4 does - #22048
fix(libkernel): keep stream data queued when recvmsg cannot write its buffer, as FreeBSD 11.4 does#22048brajankw wants to merge 1 commit into
Conversation
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 4b623d7dfc:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_socket_pair_testsbuilt cleanly. - CTest (
guest_socket_pair,guest_recvmsg_memory,guest_sendmsg_memory):1/3 Test #5398: guest_socket_pair ................ Passed 0.04 sec 2/3 Test #5399: guest_recvmsg_memory ............. Passed 0.04 sec 3/3 Test #5400: guest_sendmsg_memory ............. Passed 0.03 sec 100% tests passed, 0 tests failed out of 3 - Negative control: with
core/libs/prx/libkernel/Socket/src/Udp.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/3 Test #5398: guest_socket_pair ................Subprocess aborted***Exception: 0.74 sec 2/3 Test #5400: guest_sendmsg_memory ............. Passed 0.03 sec 3/3 Test #5399: guest_recvmsg_memory .............Subprocess aborted***Exception: 0.87 sec 33% tests passed, 2 tests failed out of 3 - Code reading:
- Validated FirstOutputWritable in core/libs/prx/libkernel/Socket/src/Udp.cpp against null/empty iovecs and tested memory accessibility via ReadGuest and WriteGuest without clobbering data
- Verified recvmsg_nid_postfix pre-flight peek logic for SOCK_STREAM (type == 1) sockets to ensure EFAULT (14) is returned and stream data remains queued when the destination buffer is not writable
- Checked handling of non-blocking and zero-byte pending stream reads (EOF vs error handling) ensuring proper error translation through NativeError() and return of 0 on EOF
- Verified AGENTS.md conventions compliance: no illegal comments, correct technical debt fragment in docs/dev/debt/changes/, and proper test coverage in GuestSocketPair.cpp
Looks Good To Me
|
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.
|
|
#23341 ( |
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: preserve queued stream data when the first output byte is readable but not writable.
What I ran
- Reviewed head
4b623d7dfc4700a49ae26e7dc65e8c87443ea641using the supplied diff andrepo_read.py. - No commands or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed files | passed | All three changed files read |
| Tests | not run | Author reports guest_socket_pair passed |
| Other platforms | not run | Windows and macOS unverified |
Findings
Blocking
-
core/libs/prx/libkernel/Socket/src/Udp.cpp:2539— The probe treats a read-only output byte as writable becauseReadGuestsucceeds on readable memory and writing the same byte throughWriteGuestmay succeed for host pages that are actually writable despite guest read-only protection. In this repository, guest read-only state is enforced byGuestArena::HostWrite; this specific path could not be confirmed from the inspected source, so the precise failure is not established. However, the condition can also alter memory by writing the byte back, and that write may have side effects for special mappings. Evidence is insufficient for a verified blocking defect. -
core/libs/prx/libkernel/Socket/src/Udp.cpp:2582-2586— After detecting a failed first-byte probe, the peek usesNativeReceiveFlagswithMSG_DONTWAITonly when the guest setGuestDontWait. A blocking call can therefore block again afterWaitForTransferif another receiver consumes the queued data between readiness and this peek; this path's concurrent-receiver behavior was not verified.
Non-blocking
core/libs/tests/GuestSocketPair.cpp:170-182— The regression test covers inaccessible and read-only outputs and EOF, but the author-reported negative control and test run were not independently reproduced.
Not verified
- Did not run the reported test suite, negative control, conventions check, or overlap check.
- Did not inspect excluded files listed in
files.json; that listing was unavailable through the review-folder reader. The supplied manifest shows all three changed files included, and all three were read. - Windows and macOS behavior was not tested.
To get this to a good state
Changes are required only for verified blocking findings; none are established from the inspected evidence. The concerns above are not confirmed defects.
4b623d7 to
19b89e9
Compare
|
@MarcZX10 Both points are addressed at the new head
Tests, the negative control and the overlap check are rerun at this head, and the body has the results. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the first-byte stream fault handling and its regression coverage support the stated behavior.
What I ran
Reviewed head 19b89e9aac55720d535b5cd59bc8dfe9cf524da4 from the prepared diff and source files. No commands or tests were run during this review.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed source | passed | Three changed files read |
| Tests | not run | Author-reported results were not rerun |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported test results and negative control were not independently verified. files.json was unavailable; the manifest lists all three changed files as included, and all three were read. No excluded changed files were reported in the manifest.
To get this to a good state
Nothing is required.
|
Works on Windows at head Existing runs. 3 reviews, 4 comments, no inline comments.
What this run adds.
Code. Line numbers are from the head.
Negative control and mutation. Each row is the merge plus the probe, with one change. Tests run:
Probes. One extra test executable,
Tests.
Host.
AI-assisted: yes |
… buffer, as FreeBSD 11.4 does recvmsg received from the host before it copied to the guest buffers, so an output buffer that could not be written lost the stream data that FreeBSD 11.4's soreceive_generic leaves queued when it faults. For a stream socket without MSG_PEEK or descriptor passing, recvmsg now waits for data as before and then checks that the first output byte can be written; if not, it peeks one byte and fails with EFAULT while data is queued, leaving it for the next receive. End of stream still returns 0. A fault later in the buffer, after the receive, still loses the data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
19b89e9 to
0722072
Compare
|
@Helldiverr I took both points and the debt correction at
|
|
Follow-up Windows run at 07220727b8, merged onto main bd9a6c00a6 as 6809922f60. The two mutations that passed every test in my earlier Windows run, m4 and m5, are now caught by the PR's own test on Windows, as the author said they would be. Results Same selection as before:
In the earlier run, both mutations passed all 44 tests and only the probe caught them. The new checks are in Debt The fragment now limits the control-buffer exception to POSIX hosts. This matches the probe's Host
AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
The inspected change and its focused test support the stated stream receive fix; execution checks were not available in this review session, so a formal approval is not justified.
What I ran
Reviewed head 07220727b87b3d0f9a6807dbe44d225f44295fa3. No commands or tests were run. Read the prepared description, commit summary, manifest, diff, and all three changed files listed in the manifest; checked the relevant receive code and helper implementations.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed source review | passed | Three changed files read |
| Test execution | not run | No test execution available |
| Negative control | not run | Not independently reproduced |
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Tests and negative control were not run independently. Windows and macOS behavior was not verified. The prepared bundle’s files.json was not available through the reader; the manifest lists three changed files, and all three were read. No additional excluded files were identified.
To get this to a good state
Nothing is required. The test execution and negative control noted above are optional follow-up checks.
ligmaSec
left a comment
There was a problem hiding this comment.
I ran guest_socket_pair with the patch applied on Linux. It passed the receive-fault regression, including the checks that a rejected receive leaves stream bytes queued for a later read.
AI-assisted: yes.
What
recvmsgreceived from the host before it copied to the guest buffers, so an output buffer that could not be written lost the stream data that FreeBSD 11.4'ssoreceive_genericleaves queued when the copy faults (therecvmsgentry indocs/dev/debt/libkernel.md).MSG_PEEKor descriptor passing,recvmsgstill waits for data as before, then checks that the first output byte can be written, with aGuestArena::HostWriteguard andGuestWritable_nid_no_patchasSubmitCommandsinAio.cppchecks its id array; nothing is written to the buffer. If the byte cannot be written, it peeks one byte: with data queued it fails withEFAULTand leaves the data for the next receive; at end of stream it returns 0 as before.GuestSocketPair.cpp: "abc" on a stream pair survivesrecvmsginto an inaccessible and a read-only buffer, also withMSG_WAITALL(a peek that kept it fails on Windows), and is then read through two vectors, the first of length 0 on the inaccessible page; after the peer closes,recvmsgreturns 0.recvmsgorUdp.cpp; see the overlap line below.Tested
Linux (Debian 13, GCC 14.2.0, Release), on
mainca41dae948. The runs after the first bullet are from the earlier head19b89e9aac.07220727b8, merged with my eight other updated branches ontomainbd9a6c00a6:ctestover the 23 tests these branches touch, includingguest_socket_pair,guest_recvmsg_memory,guest_socket_eventsandguest_kqueue: all pass. With the zero-length skip removed fromFirstOutputWritable,guest_socket_pairaborts.ctest -R '^guest_socket|^guest_kernel_socket|^guest_udp': 27 passed;guest_socket_options_multicastskipped (no network in the sandbox);guest_kernel_socket_broadcast_debug_route_boundsnot built in this run.main'sUdp.cppand this branch's test,guest_socket_pairaborts.4b623d7dfc: fullctest(5896 tests,-j 12) with this branch and my other twelve branches of this round merged ontomain521fb7fec4: 5880 passed. The 16 failures are the set that fails onmainin the same environment: sixagc_drivercases (agc_driver_image_table_packed_guardspasses when run on its own) and ten that need a.gitdirectory, network or a passwd entry for the user.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch(at07220727b8): failed closed on fix(libkernel): clear fstat read bits on a socket after the peer closes #8605, fix(libkernel): wait for the rest of a MSG_WAITALL stream receive in the guest layer #11896, fix(libkernel): preserve blocking sockets over nonblocking native transport #12688, feat(libkernel): cancel blocked POSIX writes with partial progress #12700 and feat(libkernel): support deferred cancellation in POSIX accept #12965, which conflict withmain; feat(libkernel): cancel blocked POSIX reads with owned operations #12682 was listed before. feat(libkernel): cancel blocked POSIX reads with owned operations #12682 to feat(libkernel): support deferred cancellation in POSIX accept #12965 restructurerecvmsgand fix(libkernel): wait for the rest of a MSG_WAITALL stream receive in the guest layer #11896 its wait, so they conflict textually; whichever lands second needs a rebase. It also lists feat(libs): mirror libkernel exports through libkernel_sys #18190, which renamesrecvmsg_nid_postfixtorecvmsg_nid_no_patch, and fix(libkernel): report the host arrival time for SO_TIMESTAMP and SO_BINTIME #18197, which adds code afterWriteGuest;FirstOutputWritablenow sits aboveGuestRange, andgit merge-treemerges this branch with the heads of both without a conflict.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)