File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
libcontainer/configs/validate Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,15 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
148148 return nil
149149}
150150
151+ func isSymbolicLink (path string ) (bool , error ) {
152+ fi , err := os .Lstat (path )
153+ if err != nil {
154+ return false , err
155+ }
156+
157+ return fi .Mode ()& os .ModeSymlink == os .ModeSymlink , nil
158+ }
159+
151160// checkHostNs checks whether network sysctl is used in host namespace.
152161func checkHostNs (sysctlConfig string , path string ) error {
153162 var currentProcessNetns = "/proc/self/ns/net"
@@ -156,6 +165,19 @@ func checkHostNs(sysctlConfig string, path string) error {
156165 if err != nil {
157166 return fmt .Errorf ("read soft link %q error" , currentProcessNetns )
158167 }
168+
169+ // First check if the provided path is a symbolic link
170+ symLink , err := isSymbolicLink (path )
171+ if err != nil {
172+ return fmt .Errorf ("could not check that %q is a symlink: %v" , path , err )
173+ }
174+
175+ if symLink == false {
176+ // The provided namespace is not a symbolic link,
177+ // it is not the host namespace.
178+ return nil
179+ }
180+
159181 // readlink on the path provided in the struct
160182 destOfContainer , err := os .Readlink (path )
161183 if err != nil {
You can’t perform that action at this time.
0 commit comments