Repository navigation
capability: don't use /proc/sys/kernel/cap_last_cap - #269
Merged
Merged
Conversation
kolyshkin
force-pushed
the
capability-lastcap-prctl
branch
from
October 21, 2026 03:16
8e852e8 to
ad25fc0
Compare
AkihiroSuda
reviewed
Oct 21, 2026
There was a problem hiding this comment.
🟢 Approval recommended
The bounded probing and updated assertions are consistent with the supported kernel baseline, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Removes capability detection’s dependency on /proc, allowing capability handling in root filesystems without it and preventing unsafe bounds from bogus file contents.
Changes:
- Uses bounded
PR_CAPBSET_READprobing to detect the highest supported capability. - Updates tests to compare against
/procwhen available and verify the supported-list length.
| File | Description |
|---|---|
| capability/capability_test.go | Updates capability detection and list-length assertions. |
| capability/capability_linux.go | Replaces /proc reads with bounded kernel capability probing. |
Review effort: Balanced
The value of /proc/sys/kernel/cap_last_cap is used as the upper bound in a few loops, and as an index into [2]uint32 capability sets, so a bogus value (e.g. if something is mounted over /proc) can lead to a panic or an infinite loop. In addition, /proc may not be mounted. Instead, ask the kernel directly using prctl(PR_CAPBSET_READ), which returns EINVAL for a capability the kernel does not know about. Start from the last known capability (CAP_CHECKPOINT_RESTORE), which is the last one since Linux 5.9, and go up or down from it until the validity changes. For most kernels, this takes two syscalls. The upper limit is 63, which is the highest capability that can be represented by the kernel capability ABI v3. The lower limit is CAP_WAKE_ALARM, which is always supported, given the minimum kernel version required by Go. Since LastCap no longer reads /proc/sys/kernel/cap_last_cap, change TestLastCap to check that the two values agree, rather than checking that LastCap is within a fixed range. Similarly, change TestListSupported to check the exact list length based on LastCap. Thanks to Anthropic and Ada Logics who found and validated this. Fixes: moby#265 Reported-by: Adam Korczynski <[email protected]> Signed-off-by: Kir Kolyshkin <[email protected]>
kolyshkin
force-pushed
the
capability-lastcap-prctl
branch
from
October 21, 2026 05:26
ad25fc0 to
7c18ebb
Compare
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The value of /proc/sys/kernel/cap_last_cap is used as the upper bound
in a few loops, and as an index into [2]uint32 capability sets, so a
bogus value (e.g. if something is mounted over /proc) can lead to a
panic or an infinite loop. In addition, /proc may not be mounted.
Instead, ask the kernel directly using prctl(PR_CAPBSET_READ), which
returns EINVAL for a capability the kernel does not know about.
Start from the last known capability (CAP_CHECKPOINT_RESTORE), which is
the last one since Linux 5.9, and go up or down from it until the
validity changes. For most kernels, this takes two syscalls. The upper
limit is 63, which is the highest capability that can be represented
by the kernel capability ABI v3. The lower limit is CAP_WAKE_ALARM,
which is always supported, given the minimum kernel version required
by Go.
Since LastCap no longer reads /proc/sys/kernel/cap_last_cap, change
TestLastCap to check that the two values agree, rather than checking
that LastCap is within a fixed range. Similarly, change
TestListSupported to check the exact list length based on LastCap.
Thanks to Anthropic and Ada Logics who found and validated this.
Fixes: #265
Reported-by: Adam Korczynski [email protected]