From ee91874121596af76ab03d694c280cb5aac84521 Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Tue, 27 Sep 2016 22:03:04 +0100 Subject: [PATCH] Add support for ambient capabilities Ambient capabilities were added in Linux 4.3 and provide a way to pass on capabilities to unprivileged processes easily. Signed-off-by: Justin Cormack --- capability/capability.go | 20 +++++++------- capability/capability_linux.go | 50 +++++++++++++++++++++++++++++++--- capability/enum.go | 4 +++ capability/syscall_linux.go | 9 ++++++ 4 files changed, 69 insertions(+), 14 deletions(-) diff --git a/capability/capability.go b/capability/capability.go index c13f4e5..c07c557 100644 --- a/capability/capability.go +++ b/capability/capability.go @@ -10,42 +10,42 @@ package capability type Capabilities interface { // Get check whether a capability present in the given // capabilities set. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Get(which CapType, what Cap) bool // Empty check whether all capability bits of the given capabilities // set are zero. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Empty(which CapType) bool // Full check whether all capability bits of the given capabilities // set are one. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Full(which CapType) bool // Set sets capabilities of the given capabilities sets. The // 'which' value should be one or combination (OR'ed) of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Set(which CapType, caps ...Cap) // Unset unsets capabilities of the given capabilities sets. The // 'which' value should be one or combination (OR'ed) of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE, BOUNDING or AMBIENT. Unset(which CapType, caps ...Cap) // Fill sets all bits of the given capabilities kind to one. The - // 'kind' value should be one or combination (OR'ed) of CAPS or - // BOUNDS. + // 'kind' value should be one or combination (OR'ed) of CAPS, + // BOUNDS or AMBS. Fill(kind CapType) // Clear sets all bits of the given capabilities kind to zero. The - // 'kind' value should be one or combination (OR'ed) of CAPS or - // BOUNDS. + // 'kind' value should be one or combination (OR'ed) of CAPS, + // BOUNDS or AMBS. Clear(kind CapType) // String return current capabilities state of the given capabilities // set as string. The 'which' value should be one of EFFECTIVE, - // PERMITTED, INHERITABLE or BOUNDING. + // PERMITTED, INHERITABLE BOUNDING or AMBIENT StringCap(which CapType) string // String return current capabilities state as string. diff --git a/capability/capability_linux.go b/capability/capability_linux.go index 3dfcd39..6d2135a 100644 --- a/capability/capability_linux.go +++ b/capability/capability_linux.go @@ -235,9 +235,10 @@ func (c *capsV1) Apply(kind CapType) error { } type capsV3 struct { - hdr capHeader - data [2]capData - bounds [2]uint32 + hdr capHeader + data [2]capData + bounds [2]uint32 + ambient [2]uint32 } func (c *capsV3) Get(which CapType, what Cap) bool { @@ -256,6 +257,8 @@ func (c *capsV3) Get(which CapType, what Cap) bool { return (1<