Skip to content

Resolve filesystem operations in container mount namespaces - #830

Open
recrack wants to merge 1 commit into
apple:mainfrom
recrack:fix/filesystem-operation-mount-namespace
Open

Resolve filesystem operations in container mount namespaces#830
recrack wants to merge 1 commit into
apple:mainfrom
recrack:fix/filesystem-operation-mount-namespace

Conversation

@recrack

@recrack recrack commented Aug 4, 2026

Copy link
Copy Markdown

Summary

Resolve filesystem operations relative to a workload container's init process so operations such as FITRIM target the container's mount namespace instead of vminitd's namespace.

  • Add an optional container identifier to FilesystemOperationRequest
  • Validate canonical container-absolute paths before issuing the RPC
  • Pin the init process /proc/<pid> directory when the process starts
  • Resolve the process root through the pinned descriptor to avoid PID reuse races
  • Open operation targets with openat2(RESOLVE_IN_ROOT | RESOLVE_NO_MAGICLINKS)
  • Add host and Linux guest tests for path containment, process lifetime, and mount namespace selection

Motivation

vminitd currently resolves filesystem-operation paths in its own mount namespace. A workload's root filesystem can be addressed there, but mounts created in the workload container's mount namespace, including named volumes, cannot. This prevents operations such as filesystem trim from reaching those filesystems.

Passing only a numeric PID or concatenating /proc/<pid>/root with a guest-controlled path would introduce traversal, procfs magic-link, and PID-reuse risks. This change instead carries the workload identity through the RPC, looks up the managed init process, and resolves the target through a process-root descriptor captured at process start.

Closes #829.

Related to apple/container#1763 and apple/container#1949.

Testing

  • make fmt
  • make update-licenses
  • hawkeye check
  • git diff --check
  • /usr/bin/swift test --filter LinuxContainerTests/filesystemOperation
    • 3 tests passed, including 7 rejected path cases
  • /usr/bin/swift test --filter LinuxContainerTests/podFilesystemOperationTargetsContainerMountNamespace
    • passed
  • make linux-test
    • 596 tests across 81 suites passed
  • Linux VminitCoreTests
    • 5 tests passed; privileged test skipped by default
  • Privileged mount-namespace test in an isolated Apple Container with CAP_SYS_ADMIN
    • passed
  • make linux-build LIBC=all
    • glibc and musl builds passed
  • make containerization && make init-image
    • passed; host binaries were signed and vminit:latest was created
  • End-to-end local apple/container clean exercise with this vminit image

Security considerations

  • Rejects relative, non-canonical, traversal, repeated-separator, trailing-separator, and NUL-containing paths
  • Uses RESOLVE_IN_ROOT to scope resolution to the captured container root
  • Uses RESOLVE_NO_MAGICLINKS to prevent procfs magic-link escapes while preserving normal container symlinks
  • Captures /proc/<pid> before process execution is exposed and clears it when the process exits
  • Does not re-resolve a stale numeric PID after process exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filesystem operations cannot target workload mount namespaces

1 participant