diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 38dfab88a6..32e3abde9c 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -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 } diff --git a/virtcontainers/mount.go b/virtcontainers/mount.go index da512779ad..e4a7dfb275 100644 --- a/virtcontainers/mount.go +++ b/virtcontainers/mount.go @@ -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) } diff --git a/virtcontainers/mount_test.go b/virtcontainers/mount_test.go index d907b11252..4795932f53 100644 --- a/virtcontainers/mount_test.go +++ b/virtcontainers/mount_test.go @@ -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"}