Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capability: can't raise ambient and drop bounding caps for other process #171

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions capability/capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// Package capability provides utilities for manipulating POSIX capabilities.
package capability

import "errors"

type Capabilities interface {
// Get check whether a capability present in the given
// capabilities set. The 'which' value should be one of EFFECTIVE,
Expand Down Expand Up @@ -61,6 +63,11 @@ type Capabilities interface {
Apply(kind CapType) error
}

var (
errBoundingNotMine = errors.New("not support drop bounding cap of other process")
errAmbientNotMine = errors.New("not support modify ambient cap of other process")
Comment on lines +67 to +68
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errBoundingNotMine = errors.New("not support drop bounding cap of other process")
errAmbientNotMine = errors.New("not support modify ambient cap of other process")
errBoundingNotMine = errors.New("unable to modify bounding capabilities of another process")
errAmbientNotMine = errors.New("unable to modify ambient capabilities of another process")

)

// NewPid initializes a new [Capabilities] object for given pid when
// it is nonzero, or for the current process if pid is 0.
//
Expand Down
6 changes: 6 additions & 0 deletions capability/capability_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ func (c *capsV3) Apply(kind CapType) (err error) {
}
if kind&BOUNDS == BOUNDS {
var data [2]capData
if c.hdr.pid != 0 {
return errBoundingNotMine
}
err = capget(&c.hdr, &data[0])
if err != nil {
return
Expand Down Expand Up @@ -364,6 +367,9 @@ func (c *capsV3) Apply(kind CapType) (err error) {
}

if kind&AMBS == AMBS {
if c.hdr.pid != 0 {
return errAmbientNotMine
}
err = prctl(pr_CAP_AMBIENT, pr_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0)
if err != nil && err != syscall.EINVAL { //nolint:errorlint // Errors from syscall are bare.
// Ignore EINVAL as not supported on kernels before 4.3
Expand Down