Skip to content

Commit e7abf30

Browse files
authored
Merge pull request #1150 from WeiZhang555/forbid-duplicated-namespace
Detect and forbid duplicated namespace in spec
2 parents 4599e70 + a0f7977 commit e7abf30

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

libcontainer/specconv/spec_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
187187
if !exists {
188188
return nil, fmt.Errorf("namespace %q does not exist", ns)
189189
}
190+
if config.Namespaces.Contains(t) {
191+
return nil, fmt.Errorf("malformed spec file: duplicated ns %q", ns)
192+
}
190193
config.Namespaces.Add(t, ns.Path)
191194
}
192195
if config.Namespaces.Contains(configs.NEWNET) {

libcontainer/specconv/spec_linux_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,27 @@ func TestLinuxCgroupsPathNotSpecified(t *testing.T) {
3838
t.Errorf("Wrong cgroupsPath, expected it to be empty string, got '%s'", cgroup.Path)
3939
}
4040
}
41+
42+
func TestDupNamespaces(t *testing.T) {
43+
spec := &specs.Spec{
44+
Linux: &specs.Linux{
45+
Namespaces: []specs.Namespace{
46+
{
47+
Type: "pid",
48+
},
49+
{
50+
Type: "pid",
51+
Path: "/proc/1/ns/pid",
52+
},
53+
},
54+
},
55+
}
56+
57+
_, err := CreateLibcontainerConfig(&CreateOpts{
58+
Spec: spec,
59+
})
60+
61+
if err == nil {
62+
t.Errorf("Duplicated namespaces should be forbidden")
63+
}
64+
}

0 commit comments

Comments
 (0)