Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
vc: do not follow symlink when umounting contanier host path
Browse files Browse the repository at this point in the history
So that if a guest changes it, we do not end up
propergating the error.

Fixes: #2474
Signed-off-by: Peng Tao <[email protected]>
(cherry picked from commit 5bf3231)
  • Loading branch information
bergwolf authored and amshinde committed Jun 4, 2020
1 parent 3d45e54 commit bac553d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ func (c *Container) unmountHostMounts() error {
span, _ := c.trace("unmount")
span.SetTag("host-path", m.HostPath)

if err := syscall.Unmount(m.HostPath, syscall.MNT_DETACH); err != nil {
if err := syscall.Unmount(m.HostPath, syscall.MNT_DETACH|UmountNoFollow); err != nil {
c.Logger().WithFields(logrus.Fields{
"host-path": m.HostPath,
"error": err,
Expand Down
5 changes: 4 additions & 1 deletion virtcontainers/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
// IPC is used.
const DefaultShmSize = 65536 * 1024

// Sadly golang/sys doesn't have UmountNoFollow although it's there since Linux 2.6.34
const UmountNoFollow = 0x8

var rootfsDir = "rootfs"

var systemMountPrefixes = []string{"/proc", "/sys"}
Expand Down Expand Up @@ -333,7 +336,7 @@ func bindUnmountContainerRootfs(ctx context.Context, sharedDir, sandboxID, cID s
defer span.Finish()

rootfsDest := filepath.Join(sharedDir, sandboxID, cID, rootfsDir)
err := syscall.Unmount(rootfsDest, syscall.MNT_DETACH)
err := syscall.Unmount(rootfsDest, syscall.MNT_DETACH|UmountNoFollow)
if err == syscall.ENOENT {
logrus.Warnf("%s: %s", err, rootfsDest)
return nil
Expand Down

0 comments on commit bac553d

Please sign in to comment.