Skip to content

Commit 7be88ec

Browse files
ekzhanggvisor-bot
authored andcommitted
vfs: Follow symlinks in MkdirAllAt
See #11910 for details — this potentially fixes a divergence between gVisor and runc behavior where having the `cwd` of the OCI container spec set to a symlink to a folder causes gVisor to exit with this error: ``` running container: starting container: starting root container: starting sandbox: failed to create process working directory "/cwd-folder-name-here": not a directory ``` Fixes #11910 FUTURE_COPYBARA_INTEGRATE_REVIEW=#11911 from ekzhang:patch-1 3f7bca1 PiperOrigin-RevId: 783024019
1 parent 7323f1d commit 7be88ec

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pkg/sentry/vfs/vfs.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,16 @@ func (vfs *VirtualFilesystem) MkdirAllAt(ctx context.Context, currentPath string
878878
Start: root,
879879
Path: fspath.Parse(currentPath),
880880
}
881+
882+
// For the StatAt() operation, we follow final symlinks so that we don't
883+
// produce errors when the final component is a symlink to a directory.
884+
//
885+
// However, keep the old pop unchanged when passing to MkdirAt() below
886+
// because MkdirAt() must not follow the final symlink. This is enforced
887+
// by preconditions of FilesystemImpl.MkdirAt().
888+
pop.FollowFinalSymlink = true
881889
stat, err := vfs.StatAt(ctx, creds, pop, &StatOptions{Mask: linux.STATX_TYPE})
890+
pop.FollowFinalSymlink = false
882891
switch {
883892
case err == nil:
884893
if mustBeDir && (stat.Mask&linux.STATX_TYPE == 0 || stat.Mode&linux.FileTypeMask != linux.ModeDirectory) {

0 commit comments

Comments
 (0)