mirror of
https://github.com/docker/cli.git
synced 2026-11-06 13:10:41 -04:00
Merge pull request #7492 from thaJeztah/bump_capability
vendor: github.com/moby/sys/capability v0.5.0
This commit is contained in:
+1
-1
@@ -38,7 +38,7 @@ require (
|
||||
github.com/moby/patternmatcher v0.6.1
|
||||
github.com/moby/swarmkit/v2 v2.1.3
|
||||
github.com/moby/sys/atomicwriter v0.1.0
|
||||
github.com/moby/sys/capability v0.4.0
|
||||
github.com/moby/sys/capability v0.5.0
|
||||
github.com/moby/sys/sequential v0.7.0
|
||||
github.com/moby/sys/signal v0.7.1
|
||||
github.com/moby/sys/symlink v0.3.0
|
||||
|
||||
+2
-2
@@ -98,8 +98,8 @@ github.com/moby/swarmkit/v2 v2.1.3 h1:UcwtwkIRjr75qSgUWCTIuzKUzAXlidxsiqVMnyxSF1
|
||||
github.com/moby/swarmkit/v2 v2.1.3/go.mod h1:KhkxT93Hm4wHoNUPJ4JRD384pS7OODFGzJWoDRj9bLE=
|
||||
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
|
||||
github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=
|
||||
github.com/moby/sys/capability v0.4.0 h1:4D4mI6KlNtWMCM1Z/K0i7RV1FkX+DBDHKVJpCndZoHk=
|
||||
github.com/moby/sys/capability v0.4.0/go.mod h1:4g9IK291rVkms3LKCDOoYlnV8xKwoDTpIrNEE35Wq0I=
|
||||
github.com/moby/sys/capability v0.5.0 h1:Bm4oD9xGCtZguPnaoQy1/jvKTSwZHMvM0FrnxNYtGYU=
|
||||
github.com/moby/sys/capability v0.5.0/go.mod h1:i+0cXvNSriGrL3C6sxnmlmGL5HVU0OdxocizXdC8A+g=
|
||||
github.com/moby/sys/mount v0.3.5 h1:eS3fsZTjHaBihwjp4/+5Z3jxqLXYsbwxqpVSfFv3M00=
|
||||
github.com/moby/sys/mount v0.3.5/go.mod h1:WUQDO+/uCiCIkIztx8SrwIDVn2dtMFRBebRhpDFT71M=
|
||||
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
|
||||
|
||||
+16
@@ -5,6 +5,21 @@ from https://github.com/syndtr/gocapability/commit/42c35b4376354fd5.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.5.0] - 2026-10-23
|
||||
|
||||
### Breaking changes
|
||||
* Go 1.24 or later is now required. (#264)
|
||||
|
||||
### Fixed
|
||||
* [LastCap] no longer reads `/proc/sys/kernel/cap_last_cap`, querying the
|
||||
kernel via `prctl(PR_CAPBSET_READ)` instead. This makes the package work
|
||||
when `/proc` is not mounted, and fixes a possible panic or infinite loop
|
||||
when `/proc/sys/kernel/cap_last_cap` contains a bogus value (for example,
|
||||
if something is mounted over `/proc`). (#265, #269)
|
||||
|
||||
### Changed
|
||||
* Minor code cleanups. (#187)
|
||||
|
||||
## [0.4.0] - 2024-11-11
|
||||
|
||||
### Added
|
||||
@@ -104,6 +119,7 @@ This is an initial release since the fork.
|
||||
[SetAmbient]: https://pkg.go.dev/github.com/moby/sys/capability#SetAmbient
|
||||
|
||||
<!-- Minor releases. -->
|
||||
[0.5.0]: https://github.com/moby/sys/releases/tag/capability%2Fv0.5.0
|
||||
[0.4.0]: https://github.com/moby/sys/releases/tag/capability%2Fv0.4.0
|
||||
[0.3.0]: https://github.com/moby/sys/releases/tag/capability%2Fv0.3.0
|
||||
[0.2.0]: https://github.com/moby/sys/releases/tag/capability%2Fv0.2.0
|
||||
|
||||
+65
-17
@@ -13,7 +13,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
@@ -25,27 +24,76 @@ const (
|
||||
linuxCapVer3 = 0x20080522
|
||||
)
|
||||
|
||||
// capValid reports whether the running kernel supports capability c.
|
||||
func capValid(c Cap) (bool, error) {
|
||||
err := prctl(syscall.PR_CAPBSET_READ, uintptr(c), 0)
|
||||
if errors.Is(err, syscall.EINVAL) {
|
||||
return false, nil
|
||||
}
|
||||
return err == nil, err
|
||||
}
|
||||
|
||||
// lastCap returns the highest capability supported by the running kernel.
|
||||
var lastCap = sync.OnceValues(func() (Cap, error) {
|
||||
f, err := os.Open("/proc/sys/kernel/cap_last_cap")
|
||||
last, err := findLastCap()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, fmt.Errorf("unable to get last capability: %w", err)
|
||||
}
|
||||
|
||||
buf := make([]byte, 11)
|
||||
l, err := f.Read(buf)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
buf = buf[:l]
|
||||
|
||||
last, err := strconv.Atoi(strings.TrimSpace(string(buf)))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return Cap(last), nil
|
||||
return last, nil
|
||||
})
|
||||
|
||||
func findLastCap() (Cap, error) {
|
||||
// Based on the fact Go 1.24+ supports Linux >= 3.2, and
|
||||
// - CAP_WAKE_ALARM (35) was added in 3.0;
|
||||
// - CAP_CHECKPOINT_RESTORE (40) was added in 5.9, and it is
|
||||
// the last added capability as of October 2026 (Linux 7.3);
|
||||
//
|
||||
// the last capability is at least minLastCap, and most probably
|
||||
// lastKnownCap (but newer kernels may have more).
|
||||
//
|
||||
// maxLastCap is the highest capability which can be represented
|
||||
// by the kernel capability ABI v3 (two 32-bit words per set).
|
||||
const (
|
||||
minLastCap = CAP_WAKE_ALARM
|
||||
lastKnownCap = CAP_CHECKPOINT_RESTORE
|
||||
maxLastCap = Cap(63)
|
||||
)
|
||||
|
||||
// Start from lastKnownCap, and go up if it's valid, or down if it's
|
||||
// not. For most kernels, this takes two syscalls.
|
||||
c := lastKnownCap
|
||||
ok, err := capValid(c)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if ok {
|
||||
// Go up while the next one is valid.
|
||||
for c < maxLastCap {
|
||||
ok, err := capValid(c + 1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
c++
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
// Go down until a valid one is found.
|
||||
for c > minLastCap {
|
||||
c--
|
||||
ok, err := capValid(c)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if ok {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
return 0, fmt.Errorf("PR_CAPBSET_READ returned EINVAL for %s", minLastCap)
|
||||
}
|
||||
|
||||
func capUpperMask() uint32 {
|
||||
last, err := lastCap()
|
||||
if err != nil || last < 32 {
|
||||
|
||||
+4
-3
@@ -141,16 +141,17 @@ func setVfsCap(path string, data *vfscapData) (err error) {
|
||||
return
|
||||
}
|
||||
var size uintptr
|
||||
if data.version == 1 {
|
||||
switch data.version {
|
||||
case 1:
|
||||
data.magic = vfsCapVer1
|
||||
size = vfscapDataSizeV1
|
||||
} else if data.version == 2 {
|
||||
case 2:
|
||||
data.magic = vfsCapVer2
|
||||
if data.effective[0] != 0 || data.effective[1] != 0 {
|
||||
data.magic |= vfsCapFlageffective
|
||||
}
|
||||
size = vfscapDataSizeV2
|
||||
} else {
|
||||
default:
|
||||
return syscall.EINVAL
|
||||
}
|
||||
_, _, e1 := syscall.RawSyscall6(syscall.SYS_SETXATTR, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_vfsXattrName)), uintptr(unsafe.Pointer(data)), size, 0, 0)
|
||||
|
||||
Vendored
+2
-2
@@ -215,8 +215,8 @@ github.com/moby/swarmkit/v2/protobuf/plugin
|
||||
# github.com/moby/sys/atomicwriter v0.1.0
|
||||
## explicit; go 1.18
|
||||
github.com/moby/sys/atomicwriter
|
||||
# github.com/moby/sys/capability v0.4.0
|
||||
## explicit; go 1.21
|
||||
# github.com/moby/sys/capability v0.5.0
|
||||
## explicit; go 1.24
|
||||
github.com/moby/sys/capability
|
||||
# github.com/moby/sys/sequential v0.7.0
|
||||
## explicit; go 1.24.0
|
||||
|
||||
Reference in New Issue
Block a user