Skip to content

Commit 15ff093

Browse files
committed
If container will run as non root user, drop permitted, effective caps early
As soon as the initial executable in the container is executed as a non root user, permitted and effective capabilities are dropped. Drop them earlier than this, so that they are dropped before executing the file. The main effect of this is that if `CAP_DAC_OVERRIDE` is set (the default) the user will not be able to execute files they do not have permission to execute, which previously they could. The old behaviour was somewhat surprising and the new one is definitely correct, but it is not in any meaningful way exploitable, and I do not think it is necessary to backport this fix. It is unlikely to have any negative effects as almost all executables have world execute permission anyway. Use the bounding set not the effective set as the canonical set of capabilities, as effective will now vary. Signed-off-by: Justin Cormack <[email protected]>
1 parent 60e2dc2 commit 15ff093

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

daemon/oci_linux.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ func setCapabilities(s *specs.Spec, c *container.Container) error {
255255
if c.HostConfig.Privileged {
256256
caplist = caps.GetAllCapabilities()
257257
} else {
258-
caplist, err = caps.TweakCapabilities(s.Process.Capabilities.Effective, c.HostConfig.CapAdd, c.HostConfig.CapDrop)
258+
caplist, err = caps.TweakCapabilities(s.Process.Capabilities.Bounding, c.HostConfig.CapAdd, c.HostConfig.CapDrop)
259259
if err != nil {
260260
return err
261261
}
@@ -264,6 +264,12 @@ func setCapabilities(s *specs.Spec, c *container.Container) error {
264264
s.Process.Capabilities.Bounding = caplist
265265
s.Process.Capabilities.Permitted = caplist
266266
s.Process.Capabilities.Inheritable = caplist
267+
// setUser has already been executed here
268+
// if non root drop capabilities in the way execve does
269+
if s.Process.User.UID != 0 {
270+
s.Process.Capabilities.Effective = []string{}
271+
s.Process.Capabilities.Permitted = []string{}
272+
}
267273
return nil
268274
}
269275

profiles/seccomp/seccomp.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Loop:
105105
}
106106
if len(call.Excludes.Caps) > 0 {
107107
for _, c := range call.Excludes.Caps {
108-
if inSlice(rs.Process.Capabilities.Effective, c) {
108+
if inSlice(rs.Process.Capabilities.Bounding, c) {
109109
continue Loop
110110
}
111111
}
@@ -117,7 +117,7 @@ Loop:
117117
}
118118
if len(call.Includes.Caps) > 0 {
119119
for _, c := range call.Includes.Caps {
120-
if !inSlice(rs.Process.Capabilities.Effective, c) {
120+
if !inSlice(rs.Process.Capabilities.Bounding, c) {
121121
continue Loop
122122
}
123123
}

0 commit comments

Comments
 (0)