summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/vfs/resolving_path.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-03-25 22:03:34 +0000
committergVisor bot <gvisor-bot@google.com>2020-03-25 22:03:34 +0000
commit0a1754d8a16af9db032c0c367ac4599daf8e2475 (patch)
treee236c9524481b6fadfed24fa304829916605a7b6 /pkg/sentry/vfs/resolving_path.go
parent91403113dded391bec07350f77e404096c490e0d (diff)
parente541ebec2fdb5b29209cb3fc8235b77edcaebb6a (diff)
Merge release-20200219.0-228-ge541ebe (automated)
Diffstat (limited to 'pkg/sentry/vfs/resolving_path.go')
-rwxr-xr-xpkg/sentry/vfs/resolving_path.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/pkg/sentry/vfs/resolving_path.go b/pkg/sentry/vfs/resolving_path.go
index eb4ebb511..8f31495da 100755
--- a/pkg/sentry/vfs/resolving_path.go
+++ b/pkg/sentry/vfs/resolving_path.go
@@ -329,10 +329,22 @@ func (rp *ResolvingPath) ResolveComponent(d *Dentry) (*Dentry, error) {
// component in pcs represents a symbolic link, the symbolic link should be
// followed.
//
+// If path is terminated with '/', the '/' is considered the last element and
+// any symlink before that is followed:
+// - For most non-creating walks, the last path component is handled by
+// fs/namei.c:lookup_last(), which sets LOOKUP_FOLLOW if the first byte
+// after the path component is non-NULL (which is only possible if it's '/')
+// and the path component is of type LAST_NORM.
+//
+// - For open/openat/openat2 without O_CREAT, the last path component is
+// handled by fs/namei.c:do_last(), which does the same, though without the
+// LAST_NORM check.
+//
// Preconditions: !rp.Done().
func (rp *ResolvingPath) ShouldFollowSymlink() bool {
- // Non-final symlinks are always followed.
- return rp.flags&rpflagsFollowFinalSymlink != 0 || !rp.Final()
+ // Non-final symlinks are always followed. Paths terminated with '/' are also
+ // always followed.
+ return rp.flags&rpflagsFollowFinalSymlink != 0 || !rp.Final() || rp.MustBeDir()
}
// HandleSymlink is called when the current path component is a symbolic link