Repository navigation
fix(libkernel): fail poll with EINVAL when nfds exceeds the descriptor limit - #13738
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Tests run and reviewed — Linux path remains unverified
I found no confirmed code defect in head 757c08436833a189e22c7510f536c19591b91ac9, but the Linux product job was skipped, so I am withholding approval pending Linux-specific validation.
What I ran
Reviewed head 757c08436833a189e22c7510f536c19591b91ac9 against PR base 6475267b456de6a0a23b230aa751f0b917d12688; no local build or C++ test was run. Environment: Linux x86_64, GCC 12.2.0, Python 3.11.2.
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13738
python3 tools/check_conventions.py --base 6475267b456de6a0a23b230aa751f0b917d12688 --head 757c08436833a189e22c7510f536c19591b91ac9 --title "fix(libkernel): fail poll with EINVAL when nfds exceeds the descriptor limit" --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13738-757c08436833/pr-body.mdResults
| Check | Result |
|---|---|
| Exact-head diff and source review | Passed; limit check precedes guest-array access and vector allocation. |
git diff --check |
Passed in precheck. |
| Conventions and PR template | Passed. |
| Dependency/mergeability preview | Passed; clean against current main de824c2919ca65086c6324a1e0388866a7327eea. |
| Hosted Windows product job | Passed on this head. |
| Hosted Linux product job | Skipped. |
| Precheck ABI/test-quality helpers | Not executed: isolated checkout did not contain the helper scripts; these are harness errors, not PR failures. |
Raw output for locally run convention check and precheck helper errors
All conventions checks passed.
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13738-757c08436833/head-757c08436833-96200527/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13738-757c08436833/head-757c08436833-96200527/tools/pr_test_quality.py': [Errno 2] No such file or directory
Findings
Blocking: None confirmed.
Non-blocking: The changed path relies on the guest RLIMIT_NOFILE hard limit on non-Windows hosts; the PR notes this is a substitute for unmodelled kern.maxfilesperproc. Windows CI passed, but the Linux product job was skipped, so the primary non-Windows path has not been independently exercised here. The PR's Windows test results are author-reported, not locally reproduced.
Sources
- Changed
poll_nid_postfixand boundary tests at the reviewed head - Guest
RLIMIT_NOFILEimplementation at the reviewed head
Not verified
- Linux or macOS build/runtime behavior; the Linux hosted product job was skipped.
- C++
GuestPolltest locally; it requires an exact-head build, which was not run. - Console/title behavior.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
|
@Gruzzberry Reviewed at Please also update the existing |
jotitadev
left a comment
There was a problem hiding this comment.
Linux run of this head (757c084368), merged onto main 6475267b45 (local only). Ubuntu 26.04 LTS (kernel 7.0), Intel Core i7-8700, GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON.
guest_pollpasses 3 of 3;public_headerspasses;ctest -R "poll|socket|epoll|fcntl"28/28.- Negative control: same tree with
Udp.cppback tomain(test kept):guest_pollaborts 3 of 3 (~19 s, the0xffffffffallocation).
The at-limit block does not run on Linux with the default limits. The guest RLIMIT_NOFILE hard limit is the host one, 524288 here (systemd's default nofile hard limit on current distros), so fileLimit.rlim_max < 100000 is false and the three boundary checks are skipped. I confirmed it with a temporary fprintf inside the block:
| Host hard limit | rlim_max seen by the test |
Block runs | guest_poll |
|---|---|---|---|
| default (524288) | 524288 | no | passes |
ulimit -n 4096 |
4096 | yes | passes 3 of 3 |
So the fix itself is fine on Linux, but only the 0xffffffff checks cover it in CI-like setups. On macOS the hard limit is usually unlimited, so the block is skipped there too.
Two ways to make it always run:
- The upper bound looks unnecessary: with the fix,
nullptrat the limit returnsEFAULTand limit + 1 returnsEINVALbefore any allocation, so the block only needsrlim_maxto fit inuint32_t(e.g.rlim_max >= 1024 && rlim_max < 0xffffffff). That covers Linux's 524288. - For an unlimited hard limit (macOS), the test could lower the host limit first on non-Windows hosts, e.g.
rlimit r{}; getrlimit(RLIMIT_NOFILE, &r); r.rlim_max = 4096; r.rlim_cur = std::min<rlim_t>(r.rlim_cur, 4096); setrlimit(RLIMIT_NOFILE, &r);before readingfileLimit(lowering the hard limit needs no privileges).
Also checked together with #13695 (both touch Udp.cpp) on main 2364892547: they merge cleanly, the full build passes, guest_poll and guest_kernel_fcntl pass 3 of 3, the socket/poll/fcntl subset 52/52 and public_headers pass.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
…r limit Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… be allocated Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
757c084 to
ba9200a
Compare
|
@oneandonlydean thanks, both points are fixed in
Tests: |
|
Checked the |
What
Guest
pollwith a hugenfds(for example0xffffffff) allocated a host vector of that many descriptors and crashed the emulator. FreeBSD 11.4kern_pollchecks, after the timeout,nfds > maxfilesperproc && nfds > FD_SETSIZEand returnsEINVALbefore it reads the array.pollnow does the same, keeping the order: bad timeoutEINVAL, nfds limitEINVAL, thenEFAULTfor a null or unreadable array or an unwritable result (both already onmainsince #12462).kern.maxfilesperprocis not modelled (the sysctl is still unanswered), so the guestRLIMIT_NOFILEhard limit stands in for it; it is read only whennfdsis above 1024, so the common path is unchanged. 8192 on Windows, the host hard limit elsewhere.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release,
-DBUILD_TESTING=ON, currentmain.guest_poll:0xffffffffdescriptors with a valid, a null array givesEINVAL; at the limit with a null array givesEFAULT, limit + 1 givesEINVALeven with a0x10array. The check on the limit boundary runs when the hard limit is between 1024 and 100000 (it is on Windows). Onmainthe test crashes (0xc0000409) three runs out of three; with this change it passes three runs out of three.vulkan_validation_gate_reportsandcheck_compile_test_windows_gcc_response_text_mode_is_not_reinterpreted, Python tooling tests that fail here because the Microsoft Storepython.execannot be read (OSError: Invalid argument); they fail alone three runs out of three and have nothing to do withpoll.pr_overlap_encoding,agc_host_import_cut_lifetimeandagc_driver_depth_plane_partial_storepass alone.python tools/check_conventions.py --base upstream/main: passes.RLIMIT_NOFILEhard limit and so lower thepolllimit, whichmaxfilesperprocwould not follow; on a Linux host with an extremenr_opena count just below the limit can still fail to allocate.Overlaps
tools/pr_overlap.pycould not compareUdp.cppwith #5021, #7088, #8605, #9713, #10645, #12682, #12688, #12700 and #12965 because they conflict withmainthemselves; I read their diffs and none touchespoll_nid_postfix. #11223 and #11247 change whatpollreports for sockets, not argument checks.Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code