summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/limits/limits.go
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2019-04-10 12:35:43 -0700
committerShentubot <shentubot@google.com>2019-04-10 12:36:45 -0700
commitf7aff0aaa4320505933df838cf5b551b69d5e513 (patch)
treef773a8942f4f025d370ee0d8c0e711944f168f4c /pkg/sentry/limits/limits.go
parent0a0619216ec9ca96c181dd69d9bf31e7762090cb (diff)
Allow threads with CAP_SYS_RESOURCE to raise hard rlimits.
PiperOrigin-RevId: 242919489 Change-Id: Ie3267b3bcd8a54b54bc16a6556369a19e843376f
Diffstat (limited to 'pkg/sentry/limits/limits.go')
-rw-r--r--pkg/sentry/limits/limits.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/pkg/sentry/limits/limits.go b/pkg/sentry/limits/limits.go
index eeca01876..b0571739f 100644
--- a/pkg/sentry/limits/limits.go
+++ b/pkg/sentry/limits/limits.go
@@ -113,13 +113,17 @@ func (l *LimitSet) SetUnchecked(t LimitType, v Limit) {
}
// Set assigns value v to resource of LimitType t and returns the old value.
-func (l *LimitSet) Set(t LimitType, v Limit) (Limit, error) {
+// privileged should be true only when either the caller has CAP_SYS_RESOURCE
+// or when creating limits for a new kernel.
+func (l *LimitSet) Set(t LimitType, v Limit, privileged bool) (Limit, error) {
l.mu.Lock()
defer l.mu.Unlock()
+
// If a limit is already set, make sure the new limit doesn't
// exceed the previous max limit.
if _, ok := l.data[t]; ok {
- if l.data[t].Max < v.Max {
+ // Unprivileged users can only lower their hard limits.
+ if l.data[t].Max < v.Max && !privileged {
return Limit{}, syscall.EPERM
}
if v.Cur > v.Max {