Skip to content

Commit

Permalink
validate: Check that the given namespace path is a symlink
Browse files Browse the repository at this point in the history
When checking if the provided networking namespace is the host
one or not, we should first check if it's a symbolic link or not
as in some cases we can use persistent networking namespace under
e.g. /var/run/netns/.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Samuel Ortiz committed Dec 10, 2016
1 parent 34f23cb commit f19aa2d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libcontainer/configs/validate/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
return nil
}

func isSymbolicLink(path string) (bool, error) {
fi, err := os.Lstat(path)
if err != nil {
return false, err
}

return fi.Mode()&os.ModeSymlink == os.ModeSymlink, nil
}

// checkHostNs checks whether network sysctl is used in host namespace.
func checkHostNs(sysctlConfig string, path string) error {
var currentProcessNetns = "/proc/self/ns/net"
Expand All @@ -156,6 +165,19 @@ func checkHostNs(sysctlConfig string, path string) error {
if err != nil {
return fmt.Errorf("read soft link %q error", currentProcessNetns)
}

// First check if the provided path is a symbolic link
symLink, err := isSymbolicLink(path)
if err != nil {
return fmt.Errorf("could not check that %q is a symlink: %v", path, err)
}

if symLink == false {
// The provided namespace is not a symbolic link,
// it is not the host namespace.
return nil
}

// readlink on the path provided in the struct
destOfContainer, err := os.Readlink(path)
if err != nil {
Expand Down

0 comments on commit f19aa2d

Please sign in to comment.