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

Commit

Permalink
dev: Revert "Don't ignore container mounts based on their path"
Browse files Browse the repository at this point in the history
This reverts commit 08909b2.

We should not be passing any bind-mounts from /dev, /sys and /proc.
Mounting these from the host inside the container does not make
sense as these files are relevant to the host OS.

Fixes #219

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Apr 19, 2018
1 parent 1c7a02e commit 10c596a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (c *Container) createContainersDirs() error {
func (c *Container) mountSharedDirMounts(hostSharedDir, guestSharedDir string) ([]Mount, error) {
var sharedDirMounts []Mount
for idx, m := range c.mounts {
if m.Type != "bind" {
if isSystemMount(m.Destination) || m.Type != "bind" {
continue
}

Expand Down
12 changes: 12 additions & 0 deletions virtcontainers/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ import (

var rootfsDir = "rootfs"

var systemMountPrefixes = []string{"/proc", "/dev", "/sys"}

func isSystemMount(m string) bool {
for _, p := range systemMountPrefixes {
if m == p || strings.HasPrefix(m, p+"/") {
return true
}
}

return false
}

func major(dev uint64) int {
return int((dev >> 8) & 0xfff)
}
Expand Down
24 changes: 24 additions & 0 deletions virtcontainers/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ import (
"testing"
)

func TestIsSystemMount(t *testing.T) {
tests := []struct {
mnt string
expected bool
}{
{"/sys", true},
{"/sys/", true},
{"/sys//", true},
{"/sys/fs", true},
{"/sys/fs/", true},
{"/sys/fs/cgroup", true},
{"/sysfoo", false},
{"/home", false},
{"/dev/block/", true},
}

for _, test := range tests {
result := isSystemMount(test.mnt)
if result != test.expected {
t.Fatalf("Expected result for path %s : %v, got %v", test.mnt, test.expected, result)
}
}
}

func TestMajorMinorNumber(t *testing.T) {
devices := []string{"/dev/zero", "/dev/net/tun"}

Expand Down

0 comments on commit 10c596a

Please sign in to comment.