Directfs is a filesystem access mode in runsc that provides gVisor's application kernel (the Sentry) with secure, direct access to the container filesystem.
How it works
Historically, gVisor used a "gofer" (a trusted filesystem proxy) to handle all filesystem operations via RPCs. This added significant overhead.
With Directfs, the gofer still exists but acts as a setup process rather than a proxy for every operation:
- The gofer enters a new mount namespace and sets up appropriate bind mounts to create the container filesystem.
- The gofer uses
pivot_root(2) to enter that directory. - The sandbox (Sentry) enters its own user and mount namespaces and
pivot_root(2)s into an empty directory to prevent path traversal escapes. - Instead of making RPCs, the gofer sends file descriptors (FDs) for all mount points to the sandbox using
SCM_RIGHTS messages. - The sandbox then performs filesystem operations directly using file-descriptor-relative syscalls (e.g.,
fstatat(2), openat(2), mkdirat(2)).
Security Model
Directfs relies on Linux filesystem isolation primitives (mount namespaces, pivot_root, and detached bind mounts) rather than just syscall filtering. The sandbox is restricted to the FDs provided by the gofer and cannot walk backwards (using ..) or follow malicious symlinks to escape the container filesystem.