libc: make setrlimit/getrlimit consistent and stop aborting#1435
Open
gburd wants to merge 2 commits into
Open
Conversation
Two problems with the resource-limit functions: 1. getrlimit() called abort() on any resource it did not special-case (RLIMIT_LOCKS, RLIMIT_SIGPENDING, RLIMIT_RTPRIO, RLIMIT_RTTIME). A program querying one of those crashed the whole unikernel, the same class of landmine as the libaio stubs. 2. setrlimit() was a no-op that returned success, so a later getrlimit() reported the old (usually infinite) value rather than what the application just set, an inconsistency some programs depend on. Replace the switch with a process-wide stored table of RLIMIT_NLIMITS entries, initialized once with the previous defaults (stack size from the default pthread attr, RLIMIT_NOFILE 10240, RLIMIT_NICE 0, everything else infinite). getrlimit() reads the table, setrlimit() writes it, both guarded by a mutex. Out-of-range resources and rlim_cur > rlim_max return EINVAL instead of crashing or being silently accepted. The limits remain advisory (OSv is a single address space and does not enforce most of them), but set and get are now consistent. Wire setrlimit as syscall SYS_setrlimit (only getrlimit and prlimit64 were in the table) with a tracepoint. Add tests/tst-rlimit.cc covering querying every resource without aborting, the EINVAL paths, set/get round-trips, and prlimit. Passes on OSv under KVM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes two problems with the resource-limit functions:
getrlimit()calledabort()on any resource it did not special-case(
RLIMIT_LOCKS,RLIMIT_SIGPENDING,RLIMIT_RTPRIO,RLIMIT_RTTIME). Aprogram querying one of those crashed the whole unikernel, the same class of
hazard as the old libaio stubs.
setrlimit()was a no-op that returned success, so a latergetrlimit()reported the old (usually infinite) value rather than what the application
just set, an inconsistency some programs depend on.
How
Replace the
getrlimit()switch with a process-wide stored table ofRLIMIT_NLIMITSentries, initialized once with the previous defaults (stacksize from the default pthread attr,
RLIMIT_NOFILE10240,RLIMIT_NICE0,everything else infinite).
getrlimit()reads the table,setrlimit()writesit, both guarded by a mutex. Out-of-range resources and
rlim_cur > rlim_maxreturn
EINVALinstead of crashing or being silently accepted.The limits remain advisory (OSv is a single address space and does not enforce
most of them), but set and get are now consistent.
Wire
setrlimitas syscallSYS_setrlimit(onlygetrlimitandprlimit64were in the table) with a tracepoint.
Testing
tests/tst-rlimit.cccovers querying every resource without aborting, theEINVAL paths, set/get round-trips, and
prlimit. Passes on OSv under KVM.(Recreated from #1415, which GitHub auto-closed when its branch was rebased onto current master. Same change, rebased and verified on master 3aba46c.)