Skip to content

Commit

Permalink
libcontainer: Use gocapability's NewPid2
Browse files Browse the repository at this point in the history
For newContainerCapList, we don't care what the current values are.
Using NewPid2 saves us a few syscalls at no cost.

For bootstrapData, this avoids crashing when there is no
container-side /proc.  Previously you'd get:

   container_linux.go:... starting container process caused "open
     /proc/self/status: no such file or directory"

The IsNotExist check is because we do need to load the effective set.
But capsV3's Load() does that first with the capget() call.  After the
capget call it hits /proc for bounding and ambient capabilities.  We
don't need those, so the not-exist error isn't a problem.  This is a
fairly tight binding to the current gocapability implementation, but
we vendor gocapability, so I'm not too worried about it.  If it
becomes an issue we can follow up with a LoadType(which CapType) so we
can explicitly ask to only load the effective set.

Signed-off-by: W. Trevor King <wking@tremily.us>
  • Loading branch information
wking committed Feb 23, 2018
1 parent d1257c5 commit 42fa333
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libcontainer/capabilities_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func newContainerCapList(capConfig *configs.Capabilities) (*containerCapabilitie
}
ambient = append(ambient, v)
}
pid, err := capability.NewPid(0)
pid, err := capability.NewPid2(0)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1804,10 +1804,14 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na
// The following only applies if we are root.
if !c.config.Rootless {
// check if we have CAP_SETGID to setgroup properly
pid, err := capability.NewPid(0)
pid, err := capability.NewPid2(0)
if err != nil {
return nil, err
}
err = pid.Load()
if err != nil && !os.IsNotExist(err) {
return nil, err
}
if !pid.Get(capability.EFFECTIVE, capability.CAP_SETGID) {
r.AddData(&Boolmsg{
Type: SetgroupAttr,
Expand Down

0 comments on commit 42fa333

Please sign in to comment.