feat(libkernel): allow lowering rlim_cur for RLIMIT_NOFILE in setrlimit #5902
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5902"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T15:08:35Z.
What
Allows lowering
rlim_cur(or settingrlim_cur <= rlim_max) insetrlimit(RLIMIT_NOFILE):Process.cpp,setrlimit_nid_postfixpreviously threwchanging the limit of resource X is not supportedifrequested.rlim_cur != current.rlim_cur.sys_setrlimit(kern_resource.c), unprivileged processes can freely lower the current soft limit below the hard limit without privilege.resource == guestRlimitNofile, ifrequested.rlim_max <= current.rlim_maxandrequested.rlim_cur <= requested.rlim_max, the call records the updated limit pair inguestOpenFileLimitand returns 0.getrlimit_nid_postfixreports the recorded limits on subsequent queries. Raisingrlim_maxor modifying other unsupported resource limits continues to throw.GuestGetrlimit.cppto verify round-trip reading back the lowered limit pair, restoring original limits, and verifying that attempting to raiserlim_maxabove the current hard limit throwsstd::runtime_error.docs/dev/debt/libkernel.md.Target context: Java 25 LAN / DNS (PPSA99869, #5501). During HotSpot VM initialization (
os::init_2in OpenJDKos_bsd.cppL2130), the runtime queriesgetrlimit(RLIMIT_NOFILE)and invokessetrlimit(RLIMIT_NOFILE)withrlim_cur = MIN(0x100000, rlim_max). On Linux hosts whererlim_maxis large (e.g. 1,048,576), requesting a lower soft limit previously threw.Tested
GuestGetrlimit.cpptest cases pass: lowering soft limit succeeds, reading back withgetrlimitconfirms the lowered value, restoring limits succeeds, and raising hard limit throws.python tools/check_conventions.py --base origin/mainpasses with zero errors and zero warnings.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)Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T17:23:17Z.
Review: COMMENTED
Lowering the soft limit is allowed without privilege in FreeBSD 11's
kern_proc_setrlimit, so accepting the call is right. The value is dropped, though: the new branch returns 0 without storingrequested. A title that setsrlim_curand then reads it back withgetrlimit(RLIMIT_NOFILE)gets the old soft limit. FreeBSD stores the new limits and returns them fromgetrlimit.setpriorityin #5545 ran into the same thing, and its fix was to keep one guest value: the setter stores, the getter returns it, and the host is left alone. The same works here: keep a guestRLIMIT_NOFILEpair, initialized from the host valuesgetrlimitreports now, then update it on a successfulsetrlimitand return it fromgetrlimit. Whether the guest's descriptor allocation should also enforce the lower soft limit is a separate question for the debt entry. Recording and reporting it is what makes the call exact.The test could then check the round trip: lower
rlim_cur, read it back, and expect the lowered value.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T17:37:42Z.
Thanks for the review @CnRJay! Updated in commit
8f46895d5:guestOpenFileLimit(GuestResourceLimit) is kept inProcess.cppunder a mutex, lazily initialized from the host descriptors on first read, and updated on successfulsetrlimit(RLIMIT_NOFILE)calls.getrlimit(RLIMIT_NOFILE)now returns the recorded limits, ensuring round-trip consistency.GuestGetrlimit.cppnow tests the full round trip (lowersrlim_cur, reads back viagetrlimitand verifies the lowered value, then restores the original limits and verifies restoration).docs/dev/debt/libkernel.mdto note that descriptor allocation enforcement of the lowered soft limit is not implemented.origin/mainwith all convention checks passing green.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T19:11:47Z.
Thanks, that's what I meant. The limit is stored,
getrlimitreturns it, and the test checks the round trip and that raising the hard limit still throws. Nothing more from me.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-15T05:32:49Z.
@adriadam10 Just following up: @CnRJay has reviewed and approved the stored limit implementation and round-trip tests. All CI checks are passing green on latest main; ready for merge when you have a moment!
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:11:22Z.
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.
main)docs/dev/debt/libkernel.mdL160-161Some 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.
core/libs/prx/libkernel/System/src/Process.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/tests/GuestGetrlimit.cppcore/libs/prx/libkernel/System/src/Process.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/System/src/Process.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/System/src/Process.cppImported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-15T13:33:33Z.
@oneandonlydean @adriadam10 Rebased clean on latest origin/main (
8dc92ae29). @CnRJay has approved the stored limit implementation and round-trip tests; all CI checks are passing green. Ready for merge squash whenever convenient, thank you!Imported from boykopovar/AnyPS5. Originally posted by isnisk on 2026-10-15T16:26:54Z.
Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (
43818719a) merged ontomain489466d3f(clean merge).guest_getrlimitandguest_setrlimitpass, 3 rounds; no compiler warnings.main'sProcess.cpp, the new test kept):guest_getrlimitaborts 3 of 3 withwhat(): setrlimit: changing the limit of resource 8 is not supported, so the new round-trip case covers the change.check_conventions.py --base origin/mainpasses.Not checked: macOS, the title.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-15T18:20:56Z.
A small correction, so the maintainers aren't misled: I left a comment review, not an approval. I said my point (store the limit and return it from
getrlimit) was addressed. Approval and merging are up to @adriadam10 and @oneandonlydean.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-16T15:05:25Z.
@CnRJay @oneandonlydean Cleanly rebased on latest main (
e0e3ced1e) with all CI checks green. Ready for merge whenever you have a moment!Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T18:36:45Z.
Checked build and tests for libkernel (175/175 pass) and that
guest_getrlimitfails without theProcess.cppchange. The stored soft/hard limit round-trips throughgetrlimit, raisingrlim_maxstill throws, and the TechnicalDebt line is updated. Merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-16T18:45:20Z.
@adriadam10 Thank you for running the verification tests, checking the soft/hard limit round-trips, and reviewing!