From 9c1242ecba40df95e43b42956411f0382ebbb2e7 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Wed, 6 Jan 2016 14:48:40 +0800 Subject: [PATCH] Add white list for bind mount chec Fixes: #400 It would be useful to use fuse to isolate proc info. Signed-off-by: Qiang Huang --- libcontainer/rootfs_linux.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index 5a2fad88..89ce38e8 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -299,6 +299,24 @@ func checkMountDestination(rootfs, dest string) error { invalidDestinations := []string{ "/proc", } + // White list, it should be sub directories of invalid destinations + validDestinations := []string{ + // These entries can be bind mounted by files emulated by fuse, + // so commands like top, free displays stats in container. + "/proc/cpuinfo", + "/proc/diskstats", + "/proc/meminfo", + "/proc/stats", + } + for _, valid := range validDestinations { + path, err := filepath.Rel(filepath.Join(rootfs, valid), dest) + if err != nil { + return err + } + if path == "." { + return nil + } + } for _, invalid := range invalidDestinations { path, err := filepath.Rel(filepath.Join(rootfs, invalid), dest) if err != nil {