8000 Fix handling of file capabilities. by copybara-service[bot] · Pull Request #11704 · google/gvisor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix handling of file capabilities. #11704

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

Merged
merged 1 commit into from
May 22, 2025
Merged

Conversation

copybara-service[bot]
Copy link

Fix handling of file capabilities.

All the following changes are compatible with what Linux does.

  • Do not attempt to apply file capabilities when it is not present.
  • If the rootID specified in v3 file capability struct does not own the
    current userns, then file capabilities are not applied.
  • While applying file capabilities, EPERM is only returned if
    VFS_CAP_FLAGS_EFFECTIVE is set.
  • Re-raise capabilities of root user as per capabilities(7). Compare
    security/commoncap.c:handle_privileged_root().

@copybara-service copybara-service bot added the exported Issue was exported automatically label May 9, 2025
@avagin avagin requested a review from Copilot May 20, 2025 21:53
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes the handling of file capabilities by changing how file capability data is retrieved, parsed, and applied across various components, while ensuring compatibility with Linux behavior. Key changes include:

  • Refactoring test cases and variable usage in the iptables and e2e tests to use a unified runtime variable and combinatorial test loops.
  • Updating capability extraction functions and replacing deprecated bits-based operations with new auth-based capability set methods.
  • Introducing a new function to handle privileged root users and updating related build file dependencies.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/iptables/nftables_test.sh Updated test script to use the environment variable RUNTIME instead of a positional runtime argument.
test/e2e/exec_test.go Refactored TestFileCap with nested loops for combinatorial testing and added new tests for non-zero root ID and effective flag handling.
runsc/specutils/specutils.go Replaced AllCapabilitiesUint64 with AllCapabilitiesSet and removed the bits dependency.
runsc/container/container_test.go Updated capability mask conversion for CAP_NET_RAW using the new auth API.
pkg/sentry/loader/loader.go Improved error handling for file capability retrieval by checking for EOPNOTSUPP.
pkg/sentry/kernel/kernel.go Modified file capability application logic to integrate with new helper functions.
pkg/sentry/kernel/auth/capability_set*.go Added Add and Clear methods on CapabilitySet; updated CapsFromVfsCaps to return an extra boolean and handle EPERM correctly.
pkg/sentry/kernel/auth/BUILD Adjusted visibility and dependency updates in the authentication package build.
Makefile Revised the test invocation command for nftables tests.

# The image passed to docker run uses iptables-nft by default, so the above
# rules can't be simply scraped and passed to gVisor. We test that those rules
# are correctly translated to iptables-legacy rules.
net_name="nftables-test-net-$(shuf -i 0-99999999 -n 1)"
docker network create "$net_name"
trap "docker network rm \"$net_name\"" EXIT
got=$(docker run --network="$net_name" --rm --runtime "$runtime" --privileged gvisor.dev/images/iptables iptables-legacy -t nat -S)
got=$(docker run --network="$net_name" --rm --runtime "$RUNTIME" --privileged gvisor.dev/images/iptables iptables-legacy -t nat -S)
Copy link
Preview
Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a comment explaining the change from using a positional 'runtime' argument to the environment variable 'RUNTIME' for clarity in the test setup.

Copilot uses AI. Check for mistakes.

for _, success := range []bool{true, false} {
for _, useTmpfs := range []bool{true, false} {
for _, rootUser := range []bool{true, false} {
tcName := "success"
Copy link
Preview
Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding brief inline comments to clarify how the test case names are constructed from the nested boolean loops to improve readability.

Copilot uses AI. Check for mistakes.

(CapabilitySet(capData.Inheritable()) & creds.InheritableCaps)
// by applying the file capability that is specified by capData. It also
// returns a boolean indicating whether the file capability is applied.
func CapsFromVfsCaps(vfsCaps linux.VfsNsCapData, creds *Credentials) (*Credentials, bool, error) {
Copy link
Preview
Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

Update the function comment to explicitly document the meaning of the returned boolean, indicating whether the file capabilities were applied.

Copilot uses AI. Check for mistakes.

@copybara-service copybara-service bot force-pushed the test/cl756179837 branch 2 times, most recently from 45b428f to 5e5f515 Compare May 21, 2025 23:28
All the following changes are compatible with what Linux does.
- Do not attempt to apply file capabilities when it is not present.
- If the rootID specified in v3 file capability struct does not own the
  current userns, then file capabilities are not applied.
- While applying file capabilities, EPERM is only returned if
  VFS_CAP_FLAGS_EFFECTIVE is set.
- Re-raise capabilities of root user as per capabilities(7). Compare
  security/commoncap.c:handle_privileged_root().

PiperOrigin-RevId: 761725759
@copybara-service copybara-service bot merged commit a178e09 into master May 22, 2025
@copybara-service copybara-service bot deleted the test/cl756179837 branch May 22, 2025 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exported Issue was exported automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0